Skip to content

Commit e65653d

Browse files
authored
Merge pull request #322 from EasyPost/new_partner_white_label_billing
feat: new partner white label billing
2 parents 09eabd6 + c8526bc commit e65653d

22 files changed

Lines changed: 386 additions & 8 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`)

easypost.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ Gem::Specification.new do |spec|
2929
spec.add_development_dependency 'ostruct', '~> 0.6'
3030
spec.add_development_dependency 'rdoc', '~> 6.12'
3131
spec.add_development_dependency 'rspec', '~> 3.13'
32-
spec.add_development_dependency 'rubocop', '= 1.73'
33-
spec.add_development_dependency 'rubocop-rspec', '2.31' # can't upgrade to 3.0, requires easycop config changes
32+
spec.add_development_dependency 'rubocop', '= 1.72' # TODO: v1.73 no longer packages certain plugins and will require changes
33+
spec.add_development_dependency 'rubocop-rspec', '= 2.31' # can't upgrade to 3.0, requires easycop config changes
3434
spec.add_development_dependency 'simplecov', '~> 0.22'
3535
spec.add_development_dependency 'simplecov-lcov', '~> 0.8'
3636
spec.add_development_dependency 'typhoeus', '~> 1.4'

examples

Submodule examples updated 40 files

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/billing_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
},
1616
)
1717
allow(client).to receive(:make_request).with(:post, '/credit_cards/pm_123/charges', { amount: '2000' })
18-
credit_card = client.billing.fund_wallet('2000', 'primary')
18+
credit_card = client.billing.fund_wallet('2000', Fixture.billing['priority'])
1919

2020
expect(credit_card).to eq(true)
2121
end
@@ -32,7 +32,7 @@
3232
)
3333
allow(client).to receive(:make_request).with(:delete, '/credit_cards/pm_123')
3434

35-
deleted_credit_card = client.billing.delete_payment_method('primary')
35+
deleted_credit_card = client.billing.delete_payment_method(Fixture.billing['priority'])
3636

3737
expect(deleted_credit_card).to eq(true)
3838
end
@@ -55,7 +55,7 @@
5555
# will pass if get_payment_method_info returns ['credit_cards', 'pm_123'], fail otherwise
5656
allow(client).to receive(:make_request).with(:delete, '/credit_cards/pm_123')
5757

58-
deleted_credit_card = client.billing.delete_payment_method('primary')
58+
deleted_credit_card = client.billing.delete_payment_method(Fixture.billing['priority'])
5959

6060
expect(deleted_credit_card).to eq(true)
6161
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.

0 commit comments

Comments
 (0)