Skip to content

Commit 19a26d5

Browse files
committed
feat: new billing functions for referral customers
1 parent acfee75 commit 19a26d5

File tree

12 files changed

+1086
-301
lines changed

12 files changed

+1086
-301
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
- Drop support for Node 12, 13, 14, and 15
66
- Adds `webhook_secret` and `custom_headers` properties to Typescript definitions of a Webhook
7+
- Adds the following functions to assist ReferralCustomers add credit cards and bank accounts:
8+
- `betaReferralCustomer.createCreditCardClientSecret`
9+
- `betaReferralCustomer.createBankAccountClientSecret`
10+
- `referralCustomer.addCreditCardFromStripe`
11+
- `referralCustomer.addBankAccountFromStripe`
12+
- Properly returns the response body of the following functions: `addPaymentMethod`, `refundByAmount`, `refundByPaymentLog`
713
- `findMatchingMockRequest` mocking function made private
814
- Removes undocumented and unmaintained `repl`
915
- Bumps dependencies

examples

Submodule examples updated 47 files

package-lock.json

+297-294
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/services/beta_referral_customer_service.js

+31-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default (easypostClient) =>
1010
* @returns {Object} - A JSON object representing the payment method.
1111
*/
1212
static async addPaymentMethod(stripeCustomerId, paymentMethodReference, priority = 'primary') {
13-
const wrappedParams = {
13+
const params = {
1414
payment_method: {
1515
stripe_customer_id: stripeCustomerId,
1616
payment_method_reference: paymentMethodReference,
@@ -20,9 +20,9 @@ export default (easypostClient) =>
2020

2121
const url = 'beta/referral_customers/payment_method';
2222

23-
const response = await easypostClient._post(url, wrappedParams);
23+
const response = await easypostClient._post(url, params);
2424

25-
return response;
25+
return response.body;
2626
}
2727

2828
/**
@@ -39,7 +39,7 @@ export default (easypostClient) =>
3939

4040
const response = await easypostClient._post(url, params);
4141

42-
return response;
42+
return response.body;
4343
}
4444

4545
/**
@@ -56,6 +56,32 @@ export default (easypostClient) =>
5656

5757
const response = await easypostClient._post(url, params);
5858

59-
return response;
59+
return response.body;
60+
}
61+
62+
/**
63+
* Creates a client secret to use with Stripe when adding a credit card.
64+
* @returns {object} - A JSON object representing the client secret.
65+
*/
66+
static async createCreditCardClientSecret() {
67+
const url = 'beta/setup_intents';
68+
69+
const response = await easypostClient._post(url, null);
70+
71+
return response.body;
72+
}
73+
74+
/**
75+
* Creates a client secret to use with Stripe when adding a credit card.
76+
* @returns {object} - A JSON object representing the client secret.
77+
*/
78+
static async createBankAccountClientSecret(returnUrl) {
79+
const params = returnUrl ? { return_url: returnUrl } : null;
80+
81+
const url = 'beta/financial_connections_sessions';
82+
83+
const response = await easypostClient._post(url, params);
84+
85+
return response.body;
6086
}
6187
};

src/services/referral_customer_service.js

+46-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export default (easypostClient) =>
121121
}
122122

123123
/**
124-
* Add a credit card to a {@link User referral customer's} account.
124+
* Add a credit card to EasyPost for a ReferralCustomer without needing a Stripe account. This function requires the ReferralCustomer User's API key.
125125
* See {@link https://www.easypost.com/docs/api/node#create-credit-card EasyPost API Documentation} for more information.
126126
* @param {string} referralApiKey - The referral customer's production API key.
127127
* @param {string} number - The credit card number.
@@ -159,6 +159,51 @@ export default (easypostClient) =>
159159
return paymentMethod;
160160
}
161161

162+
/**
163+
* Add a credit card to EasyPost for a ReferralCustomer with a payment method ID from Stripe.
164+
* This function requires the ReferralCustomer User's API key.
165+
* @returns {object} - A JSON object representing the credit card.
166+
*/
167+
static async addCreditCardFromStripe(referralApiKey, paymentMethodId, priority = 'primary') {
168+
const _client = _getReferralClient(easypostClient, referralApiKey);
169+
const params = {
170+
credit_card: {
171+
payment_method_id: paymentMethodId,
172+
priority: priority,
173+
},
174+
};
175+
const url = 'credit_cards';
176+
177+
const response = await _client._post(url, params);
178+
179+
return this._convertToEasyPostObject(response.body, params);
180+
}
181+
182+
/**
183+
* Add a bank account to EasyPost for a ReferralCustomer.
184+
* This function requires the ReferralCustomer User's API key.
185+
* @returns {object} - A JSON object representing the bank account.
186+
*/
187+
static async addBankAccountFromStripe(
188+
referralApiKey,
189+
financialConnectionsId,
190+
mandateData,
191+
priority = 'primary',
192+
) {
193+
const _client = _getReferralClient(easypostClient, referralApiKey);
194+
const params = {
195+
financial_connections_id: financialConnectionsId,
196+
mandate_data: mandateData,
197+
priority: priority,
198+
};
199+
200+
const url = 'bank_accounts';
201+
202+
const response = await _client._post(url, params);
203+
204+
return this._convertToEasyPostObject(response.body, params);
205+
}
206+
162207
/**
163208
* Retrieve all {@link User referral customers} associated with the current authenticated user.
164209
* See {@link https://www.easypost.com/docs/api/node#retrieve-a-list-of-referral-customers EasyPost API Documentation} for more information.

test/cassettes/BetaReferralCustomerService_312890993/returns-a-client-secret-for-bank-accounts_845792627/recording.har

+167
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)