Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adds referral customer billing functions #347

Merged
merged 1 commit into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
## Next Release

- Adds `WebhookCustomHeader` model, allowing `custom_headers` to be passed when creating/updating a webhook
- Adds the following functions to assist ReferralCustomers add credit cards and bank accounts:
- `betaReferralCustomer.createCreditCardClientSecret`
- `betaReferralCustomer.createBankAccountClientSecret`
- `referralCustomer.addCreditCardFromStripe`
- `referralCustomer.addBankAccountFromStripe`
- Adds `tracking_codes` param to tracker index endpoint
- Fixes error parsing
- 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)
Expand Down
2 changes: 1 addition & 1 deletion examples
Submodule examples updated 47 files
+0 −5 .babelrc
+29 −25 Gemfile.lock
+11 −9 README.md
+3 −3 examples.gemspec
+10 −0 official/fixtures/client-library-fixtures.json
+2,036 −1,408 package-lock.json
+0 −2 package.json
+10 −9 style_guides/ruby/.rubocop.yml
+2 −2 style_guides/ruby/easycop.yml
+2 −0 tools/docs/responses/.gitignore
+62 −0 tools/docs/responses/Makefile
+19 −0 tools/docs/responses/README.md
+0 −0 tools/docs/responses/builder/__init__.py
+164 −0 tools/docs/responses/builder/snippets.py
+45 −0 tools/docs/responses/setup.py
+0 −0 tools/docs/responses/tests/__init__.py
+256 −0 tools/docs/responses/tests/conftest.py
+68 −0 tools/docs/responses/tests/test_address.py
+69 −0 tools/docs/responses/tests/test_api_keys.py
+100 −0 tools/docs/responses/tests/test_batch.py
+69 −0 tools/docs/responses/tests/test_billing.py
+11 −0 tools/docs/responses/tests/test_brand.py
+48 −0 tools/docs/responses/tests/test_carrier_account.py
+10 −0 tools/docs/responses/tests/test_carrier_types.py
+18 −0 tools/docs/responses/tests/test_customs_info.py
+18 −0 tools/docs/responses/tests/test_customs_item.py
+54 −0 tools/docs/responses/tests/test_end_shipper.py
+112 −0 tools/docs/responses/tests/test_event.py
+15 −0 tools/docs/responses/tests/test_form.py
+25 −0 tools/docs/responses/tests/test_insurance.py
+11 −0 tools/docs/responses/tests/test_options.py
+48 −0 tools/docs/responses/tests/test_order.py
+18 −0 tools/docs/responses/tests/test_parcel.py
+43 −0 tools/docs/responses/tests/test_pickup.py
+20 −0 tools/docs/responses/tests/test_rate.py
+84 −0 tools/docs/responses/tests/test_referral_customer.py
+31 −0 tools/docs/responses/tests/test_refund.py
+34 −0 tools/docs/responses/tests/test_report.py
+11 −0 tools/docs/responses/tests/test_returns.py
+27 −0 tools/docs/responses/tests/test_scan_form.py
+61 −0 tools/docs/responses/tests/test_shipment.py
+18 −0 tools/docs/responses/tests/test_shipping_insurance.py
+11 −0 tools/docs/responses/tests/test_smartrate.py
+12 −0 tools/docs/responses/tests/test_tax_identifiers.py
+18 −0 tools/docs/responses/tests/test_tracker.py
+37 −0 tools/docs/responses/tests/test_user.py
+50 −0 tools/docs/responses/tests/test_webhook.py
8 changes: 8 additions & 0 deletions src/main/java/com/easypost/model/ClientSecret.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.easypost.model;

import lombok.Getter;

@Getter
public final class ClientSecret {
private String clientSecret;
}
2 changes: 2 additions & 0 deletions src/main/java/com/easypost/model/PaymentMethodObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ String getEndpoint() {
private String name;
// bank_account
private boolean verified;
// both
private boolean requiresMandateCollection;

/**
* Get the type of this PaymentMethodObject object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.easypost.http.Requestor;
import com.easypost.http.Requestor.RequestMethod;
import com.easypost.model.BetaPaymentRefund;
import com.easypost.model.ClientSecret;
import com.easypost.model.PaymentMethod;
import com.easypost.model.PaymentMethodObject;

Expand Down Expand Up @@ -92,4 +93,44 @@ public BetaPaymentRefund refundByPaymentLog(String paymentLogId) throws EasyPost
return Requestor.request(RequestMethod.POST, endpoint, params,
BetaPaymentRefund.class, client, "beta");
}

/**
* Creates a client secret to use with Stripe when adding a credit card.
*
* @return ClientSecret containing the client secret.
* @throws EasyPostException When the request fails.
*/
public ClientSecret createCreditCardClientSecret() throws EasyPostException {
String endpoint = "setup_intents";

return Requestor.request(RequestMethod.POST, endpoint, null, ClientSecret.class, client, "beta");
}

/**
* Creates a client secret to use with Stripe when adding a bank account.
*
* @return ClientSecret containing the client secret.
* @throws EasyPostException When the request fails.
*/
public ClientSecret createBankAccountClientSecret() throws EasyPostException {
return createBankAccountClientSecret(null);
}

/**
* Creates a client secret to use with Stripe when adding a bank account.
*
* @param returnUrl Optional return URL for the bank account setup.
* @return ClientSecret containing the client secret.
* @throws EasyPostException When the request fails.
*/
public ClientSecret createBankAccountClientSecret(String returnUrl) throws EasyPostException {
HashMap<String, Object> params = new HashMap<>();
if (returnUrl != null) {
params.put("return_url", returnUrl);
}

String endpoint = "financial_connections_sessions";

return Requestor.request(RequestMethod.POST, endpoint, params, ClientSecret.class, client, "beta");
}
}
53 changes: 53 additions & 0 deletions src/main/java/com/easypost/service/ReferralCustomerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,59 @@ public PaymentMethodObject addCreditCardToUser(final String referralApiKey, fina
return createEasypostCreditCard(referralApiKey, stripeToken, priority.toString().toLowerCase());
}

/**
* Add a credit card to EasyPost for a ReferralCustomer with a payment method ID from Stripe.
* This function requires the ReferralCustomer User's API key.
*
* @param referralApiKey API key of the referral user.
* @param paymentMethodId Payment method ID from Stripe.
* @param priority Priority of the credit card (e.g., "primary" or "secondary").
* @return PaymentMethodObject object.
* @throws EasyPostException when the request fails.
*/
public PaymentMethodObject addCreditCardFromStripe(final String referralApiKey, final String paymentMethodId,
final PaymentMethod.Priority priority) throws EasyPostException {
Map<String, Object> params = new HashMap<>();
Map<String, Object> creditCardParams = new HashMap<>();
creditCardParams.put("payment_method_id", paymentMethodId);
creditCardParams.put("priority", priority.toString().toLowerCase());
params.put("credit_card", creditCardParams);

EasyPostClient referralClient = new EasyPostClient(referralApiKey);

String endpoint = "credit_cards";

return Requestor.request(RequestMethod.POST, endpoint, params, PaymentMethodObject.class, referralClient);
}

/**
* Add a bank account to EasyPost for a ReferralCustomer.
* This function requires the ReferralCustomer User's API key.
*
* @param referralApiKey API key of the referral user.
* @param financialConnectionsId Financial connections ID from Stripe.
* @param mandateData Mandate data for the bank account.
* @param priority Priority of the bank account (e.g., "primary" or "secondary").
* @return PaymentMethodObject object.
* @throws EasyPostException when the request fails.
*/
public PaymentMethodObject addBankAccountFromStripe(final String referralApiKey,
final String financialConnectionsId,
final Map<String, Object> mandateData,
final PaymentMethod.Priority priority)
throws EasyPostException {
Map<String, Object> params = new HashMap<>();
params.put("financial_connections_id", financialConnectionsId);
params.put("mandate_data", mandateData);
params.put("priority", priority.toString().toLowerCase());

EasyPostClient referralClient = new EasyPostClient(referralApiKey);

String endpoint = "bank_accounts";

return Requestor.request(RequestMethod.POST, endpoint, params, PaymentMethodObject.class, referralClient);
}

/**
* Retrieve EasyPost Stripe API key.
*
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading