Skip to content

Commit 2b52734

Browse files
authored
Merge pull request #347 from EasyPost/new_partner_white_label_billing
feat: adds referral customer billing functions
2 parents 38f73b3 + e5653b1 commit 2b52734

21 files changed

+590
-12
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
## Next Release
44

55
- Adds `WebhookCustomHeader` model, allowing `custom_headers` to be passed when creating/updating a webhook
6+
- Adds the following functions to assist ReferralCustomers add credit cards and bank accounts:
7+
- `betaReferralCustomer.createCreditCardClientSecret`
8+
- `betaReferralCustomer.createBankAccountClientSecret`
9+
- `referralCustomer.addCreditCardFromStripe`
10+
- `referralCustomer.addBankAccountFromStripe`
611
- Adds `tracking_codes` param to tracker index endpoint
712
- Fixes error parsing
813
- Allows for alternative format of `errors` field (previously we deserialized the `errors` field into a list of `Error` objects; however, sometimes the errors are simply a list of strings. This change make the `errors` field a list of `Object` allowing for either the new `FieldError` object or a list of strings. Users will need to check for the type of error returned and handle appropriately)

examples

Submodule examples updated 47 files
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.easypost.model;
2+
3+
import lombok.Getter;
4+
5+
@Getter
6+
public final class ClientSecret {
7+
private String clientSecret;
8+
}

src/main/java/com/easypost/model/PaymentMethodObject.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ String getEndpoint() {
4848
private String name;
4949
// bank_account
5050
private boolean verified;
51+
// both
52+
private boolean requiresMandateCollection;
5153

5254
/**
5355
* Get the type of this PaymentMethodObject object.

src/main/java/com/easypost/service/BetaReferralCustomerService.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.easypost.http.Requestor;
77
import com.easypost.http.Requestor.RequestMethod;
88
import com.easypost.model.BetaPaymentRefund;
9+
import com.easypost.model.ClientSecret;
910
import com.easypost.model.PaymentMethod;
1011
import com.easypost.model.PaymentMethodObject;
1112

@@ -92,4 +93,44 @@ public BetaPaymentRefund refundByPaymentLog(String paymentLogId) throws EasyPost
9293
return Requestor.request(RequestMethod.POST, endpoint, params,
9394
BetaPaymentRefund.class, client, "beta");
9495
}
96+
97+
/**
98+
* Creates a client secret to use with Stripe when adding a credit card.
99+
*
100+
* @return ClientSecret containing the client secret.
101+
* @throws EasyPostException When the request fails.
102+
*/
103+
public ClientSecret createCreditCardClientSecret() throws EasyPostException {
104+
String endpoint = "setup_intents";
105+
106+
return Requestor.request(RequestMethod.POST, endpoint, null, ClientSecret.class, client, "beta");
107+
}
108+
109+
/**
110+
* Creates a client secret to use with Stripe when adding a bank account.
111+
*
112+
* @return ClientSecret containing the client secret.
113+
* @throws EasyPostException When the request fails.
114+
*/
115+
public ClientSecret createBankAccountClientSecret() throws EasyPostException {
116+
return createBankAccountClientSecret(null);
117+
}
118+
119+
/**
120+
* Creates a client secret to use with Stripe when adding a bank account.
121+
*
122+
* @param returnUrl Optional return URL for the bank account setup.
123+
* @return ClientSecret containing the client secret.
124+
* @throws EasyPostException When the request fails.
125+
*/
126+
public ClientSecret createBankAccountClientSecret(String returnUrl) throws EasyPostException {
127+
HashMap<String, Object> params = new HashMap<>();
128+
if (returnUrl != null) {
129+
params.put("return_url", returnUrl);
130+
}
131+
132+
String endpoint = "financial_connections_sessions";
133+
134+
return Requestor.request(RequestMethod.POST, endpoint, params, ClientSecret.class, client, "beta");
135+
}
95136
}

src/main/java/com/easypost/service/ReferralCustomerService.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,59 @@ public PaymentMethodObject addCreditCardToUser(final String referralApiKey, fina
166166
return createEasypostCreditCard(referralApiKey, stripeToken, priority.toString().toLowerCase());
167167
}
168168

169+
/**
170+
* Add a credit card to EasyPost for a ReferralCustomer with a payment method ID from Stripe.
171+
* This function requires the ReferralCustomer User's API key.
172+
*
173+
* @param referralApiKey API key of the referral user.
174+
* @param paymentMethodId Payment method ID from Stripe.
175+
* @param priority Priority of the credit card (e.g., "primary" or "secondary").
176+
* @return PaymentMethodObject object.
177+
* @throws EasyPostException when the request fails.
178+
*/
179+
public PaymentMethodObject addCreditCardFromStripe(final String referralApiKey, final String paymentMethodId,
180+
final PaymentMethod.Priority priority) throws EasyPostException {
181+
Map<String, Object> params = new HashMap<>();
182+
Map<String, Object> creditCardParams = new HashMap<>();
183+
creditCardParams.put("payment_method_id", paymentMethodId);
184+
creditCardParams.put("priority", priority.toString().toLowerCase());
185+
params.put("credit_card", creditCardParams);
186+
187+
EasyPostClient referralClient = new EasyPostClient(referralApiKey);
188+
189+
String endpoint = "credit_cards";
190+
191+
return Requestor.request(RequestMethod.POST, endpoint, params, PaymentMethodObject.class, referralClient);
192+
}
193+
194+
/**
195+
* Add a bank account to EasyPost for a ReferralCustomer.
196+
* This function requires the ReferralCustomer User's API key.
197+
*
198+
* @param referralApiKey API key of the referral user.
199+
* @param financialConnectionsId Financial connections ID from Stripe.
200+
* @param mandateData Mandate data for the bank account.
201+
* @param priority Priority of the bank account (e.g., "primary" or "secondary").
202+
* @return PaymentMethodObject object.
203+
* @throws EasyPostException when the request fails.
204+
*/
205+
public PaymentMethodObject addBankAccountFromStripe(final String referralApiKey,
206+
final String financialConnectionsId,
207+
final Map<String, Object> mandateData,
208+
final PaymentMethod.Priority priority)
209+
throws EasyPostException {
210+
Map<String, Object> params = new HashMap<>();
211+
params.put("financial_connections_id", financialConnectionsId);
212+
params.put("mandate_data", mandateData);
213+
params.put("priority", priority.toString().toLowerCase());
214+
215+
EasyPostClient referralClient = new EasyPostClient(referralApiKey);
216+
217+
String endpoint = "bank_accounts";
218+
219+
return Requestor.request(RequestMethod.POST, endpoint, params, PaymentMethodObject.class, referralClient);
220+
}
221+
169222
/**
170223
* Retrieve EasyPost Stripe API key.
171224
*

src/test/cassettes/beta_referral_customer/create_bank_account_client_secret.json

Lines changed: 94 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/test/cassettes/beta_referral_customer/create_credit_card_client_secret.json

Lines changed: 91 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)