Skip to content

Commit e810527

Browse files
committed
feat: adds new credit card and bank account functions for referral customers
1 parent 09eabd6 commit e810527

18 files changed

Lines changed: 374 additions & 2 deletions

File tree

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 Ruby 3.4 support
6+
- Adds the following functions to assist ReferralCustomers add credit cards and bank accounts:
7+
- `beta_referral_customer.create_credit_card_client_secret`
8+
- `beta_referral_customer.create_bank_account_client_secret`
9+
- `referral_customer.add_credit_card_from_stripe`
10+
- `referral_customer.add_bank_account_from_stripe`
611
- Fixes error parsing
712
- Allows for alternative format of `errors` field
813
- Corrects available properties of an `EasyPostError` and `ApiError` (`code` and `field` removed from `EasyPostError`, `message` unfurled and explicitly added to `ApiError`)

lib/easypost/services/beta_referral_customer.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,19 @@ def refund_by_payment_log(payment_log_id)
4141

4242
EasyPost::InternalUtilities::Json.convert_json_to_object(response)
4343
end
44+
45+
# Creates a client secret to use with Stripe when adding a credit card.
46+
def create_credit_card_client_secret()
47+
response = @client.make_request(:post, 'setup_intents', nil, 'beta')
48+
49+
EasyPost::InternalUtilities::Json.convert_json_to_object(response)
50+
end
51+
52+
# Creates a client secret to use with Stripe when adding a bank account.
53+
def create_bank_account_client_secret(return_url = nil)
54+
params = return_url ? { return_url: return_url } : nil
55+
response = @client.make_request(:post, 'financial_connections_sessions', params, 'beta')
56+
57+
EasyPost::InternalUtilities::Json.convert_json_to_object(response)
58+
end
4459
end

lib/easypost/services/referral_customer.rb

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def get_next_page(collection, page_size = nil)
4040
all(params)
4141
end
4242

43-
# Add credit card to a referral customer. This function requires the ReferralCustomer Customer's API key.
43+
# Add a credit card to EasyPost for a ReferralCustomer without needing a Stripe account. This function requires the ReferralCustomer User's API key.
4444
def add_credit_card(referral_api_key, number, expiration_month, expiration_year, cvc, priority = 'primary')
4545
easypost_stripe_api_key = retrieve_easypost_stripe_api_key
4646

@@ -59,6 +59,41 @@ def add_credit_card(referral_api_key, number, expiration_month, expiration_year,
5959
create_easypost_credit_card(referral_api_key, stripe_credit_card_token, priority)
6060
end
6161

62+
# 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.
63+
def add_credit_card_from_stripe(referral_api_key, payment_method_id, priority = 'primary')
64+
params = {
65+
credit_card: {
66+
payment_method_id: payment_method_id,
67+
priority: priority,
68+
},
69+
}
70+
referral_client = EasyPost::Client.new(api_key: referral_api_key)
71+
response = referral_client.make_request(
72+
:post,
73+
'credit_cards',
74+
params,
75+
)
76+
77+
EasyPost::InternalUtilities::Json.convert_json_to_object(response)
78+
end
79+
80+
# Add a bank account to EasyPost for a ReferralCustomer. This function requires the ReferralCustomer User's API key.
81+
def add_bank_account_from_stripe(referral_api_key, financial_connections_id, mandate_data, priority = 'primary')
82+
params = {
83+
financial_connections_id: financial_connections_id,
84+
mandate_data: mandate_data,
85+
priority: priority,
86+
}
87+
referral_client = EasyPost::Client.new(api_key: referral_api_key)
88+
response = referral_client.make_request(
89+
:post,
90+
'bank_accounts',
91+
params,
92+
)
93+
94+
EasyPost::InternalUtilities::Json.convert_json_to_object(response)
95+
end
96+
6297
private
6398

6499
# Retrieve EasyPost's Stripe public API key.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,20 @@
3939
)
4040
end
4141
end
42+
43+
describe '.create_credit_card_client_secret' do
44+
it 'returns a client secret for credit cards' do
45+
response = client.beta_referral_customer.create_credit_card_client_secret()
46+
47+
expect(response.client_secret).to match('seti_')
48+
end
49+
end
50+
51+
describe '.create_bank_account_client_secret' do
52+
it 'returns a client secret for bank accounts' do
53+
response = client.beta_referral_customer.create_bank_account_client_secret()
54+
55+
expect(response.client_secret).to match('fcsess_client_secret_')
56+
end
57+
end
4258
end

spec/cassettes/beta_referral/EasyPost_Services_BetaReferralCustomer_add_payment_method_adds_a_Stripe_card_or_bank_account_to_a_referral_customer_account.yml renamed to spec/cassettes/beta_referral_customer/EasyPost_Services_BetaReferralCustomer_add_payment_method_adds_a_Stripe_card_or_bank_account_to_a_referral_customer_account.yml

File renamed without changes.

spec/cassettes/beta_referral_customer/EasyPost_Services_BetaReferralCustomer_create_bank_account_client_secret_returns_a_client_secret_for_bank_accounts.yml

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

spec/cassettes/beta_referral_customer/EasyPost_Services_BetaReferralCustomer_create_credit_card_client_secret_returns_a_client_secret_for_credit_cards.yml

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

spec/cassettes/beta_referral/EasyPost_Services_BetaReferralCustomer_refund_by_amount_refunds_a_referral_user_by_a_specific_amount.yml renamed to spec/cassettes/beta_referral_customer/EasyPost_Services_BetaReferralCustomer_refund_by_amount_refunds_a_referral_user_by_a_specific_amount.yml

File renamed without changes.

spec/cassettes/beta_referral/EasyPost_Services_BetaReferralCustomer_refund_by_payment_log_refunds_a_referral_user_by_a_specific_payment_log_entry.yml renamed to spec/cassettes/beta_referral_customer/EasyPost_Services_BetaReferralCustomer_refund_by_payment_log_refunds_a_referral_user_by_a_specific_payment_log_entry.yml

File renamed without changes.

spec/cassettes/referral_customer/EasyPost_Services_ReferralCustomer_add_bank_account_from_stripe_raises_an_error_when_adding_a_bank_account_from_Stripe_fails.yml

Lines changed: 67 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)