Skip to content
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

## Next Release

- Removes the deprecated, unusable `add_credit_card` function
- Stripe has disabled the ability to pass plain credit card details over the wire and now requires using [Stripe.js/Elements/Checkout](https://support.stripe.com/questions/card-tokenization-restrictions-using-publishable-keys). Follow the [Decentralized (EasyPost-Manage Billing) Guide](https://docs.easypost.com/guides/get-started-with-forge/easypost-managed-billing-guide#referralcustomer-billing-management) for more details on the new flow to use.
- Makes `referral_customer.retrieve_easypost_stripe_api_key` public to help facilitate adding credit cards using Stripe.js

## v7.7.0 (2026-06-25)

- Adds `params` to `request_pin` ensuring users can pass `easypost_details` to the call
Expand Down
71 changes: 0 additions & 71 deletions lib/easypost/services/referral_customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,6 @@ def get_next_page(collection, page_size = nil)
all(params)
end

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

begin
stripe_credit_card_token = create_stripe_token(
number,
expiration_month,
expiration_year,
cvc,
easypost_stripe_api_key,
)
rescue StandardError
raise EasyPost::Errors::ExternalApiError.new(EasyPost::Constants::STRIPE_CARD_CREATE_FAILED)
end

create_easypost_credit_card(referral_api_key, stripe_credit_card_token, priority)
end

# 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.
def add_credit_card_from_stripe(referral_api_key, payment_method_id, priority = 'primary')
params = {
Expand Down Expand Up @@ -94,61 +75,9 @@ def add_bank_account_from_stripe(referral_api_key, financial_connections_id, man
EasyPost::InternalUtilities::Json.convert_json_to_object(response)
end

private

# Retrieve EasyPost's Stripe public API key.
def retrieve_easypost_stripe_api_key
response = @client.make_request(:get, 'partners/stripe_public_key', nil, 'beta')
response['public_key']
end

# Get credit card token from Stripe.
def create_stripe_token(number, expiration_month, expiration_year,
cvc, easypost_stripe_token)
headers = {
# This Stripe endpoint only accepts URL form encoded bodies.
Authorization: "Bearer #{easypost_stripe_token}",
'Content-type': 'application/x-www-form-urlencoded',
}

credit_card_hash = {
card: {
number: number,
exp_month: expiration_month,
exp_year: expiration_year,
cvc: cvc,
},
}

form_encoded_params = EasyPost::InternalUtilities.form_encode_params(credit_card_hash)

uri = URI.parse('https://api.stripe.com/v1/tokens')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri, headers)
query = URI.encode_www_form(form_encoded_params)

response = http.request(request, query)
response_json = JSON.parse(response.body)
response_json['id']
end

# Submit Stripe credit card token to EasyPost.
def create_easypost_credit_card(referral_api_key, stripe_object_id, priority = 'primary')
wrapped_params = {
credit_card: {
stripe_object_id: stripe_object_id,
priority: priority,
},
}
referral_client = EasyPost::Client.new(api_key: referral_api_key)
response = referral_client.make_request(
:post,
'credit_cards',
wrapped_params,
'beta',
)

EasyPost::InternalUtilities::Json.convert_json_to_object(response)
end
end

This file was deleted.

Loading
Loading