Class: EasyPost::Services::ReferralCustomer
- Defined in:
- lib/easypost/services/referral_customer.rb
Constant Summary collapse
Instance Method Summary collapse
-
#add_bank_account_from_stripe(referral_api_key, financial_connections_id, mandate_data, priority = 'primary') ⇒ Object
Add a bank account to EasyPost for a ReferralCustomer.
-
#add_credit_card(referral_api_key, number, expiration_month, expiration_year, cvc, priority = 'primary') ⇒ Object
Add a credit card to EasyPost for a ReferralCustomer without needing a Stripe account.
-
#add_credit_card_from_stripe(referral_api_key, payment_method_id, priority = 'primary') ⇒ Object
Add a credit card to EasyPost for a ReferralCustomer with a payment method ID from Stripe.
-
#all(params = {}) ⇒ Object
Retrieve a list of referral customers.
-
#create(params = {}) ⇒ Object
Create a referral customer.
-
#get_next_page(collection, page_size = nil) ⇒ Object
Get the next page of referral customers.
-
#update_email(user_id, email) ⇒ Object
Update a referral customer.
Methods inherited from Service
Constructor Details
This class inherits a constructor from EasyPost::Services::Service
Instance Method Details
#add_bank_account_from_stripe(referral_api_key, financial_connections_id, mandate_data, priority = 'primary') ⇒ Object
Add a bank account to EasyPost for a ReferralCustomer. This function requires the ReferralCustomer User’s API key.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/easypost/services/referral_customer.rb', line 81 def add_bank_account_from_stripe(referral_api_key, financial_connections_id, mandate_data, priority = 'primary') params = { financial_connections_id: financial_connections_id, mandate_data: mandate_data, priority: priority, } referral_client = EasyPost::Client.new(api_key: referral_api_key) response = referral_client.make_request( :post, 'bank_accounts', params, ) EasyPost::InternalUtilities::Json.convert_json_to_object(response) end |
#add_credit_card(referral_api_key, number, expiration_month, expiration_year, cvc, priority = 'primary') ⇒ Object
Add a credit card to EasyPost for a ReferralCustomer without needing a Stripe account. This function requires the ReferralCustomer User’s API key.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/easypost/services/referral_customer.rb', line 44 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_credit_card_from_stripe(referral_api_key, payment_method_id, priority = 'primary') ⇒ Object
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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/easypost/services/referral_customer.rb', line 63 def add_credit_card_from_stripe(referral_api_key, payment_method_id, priority = 'primary') params = { credit_card: { payment_method_id: payment_method_id, priority: priority, }, } referral_client = EasyPost::Client.new(api_key: referral_api_key) response = referral_client.make_request( :post, 'credit_cards', params, ) EasyPost::InternalUtilities::Json.convert_json_to_object(response) end |
#all(params = {}) ⇒ Object
Retrieve a list of referral customers. This function requires the Partner User’s API key.
27 28 29 30 31 |
# File 'lib/easypost/services/referral_customer.rb', line 27 def all(params = {}) filters = { key: 'referral_customers' } get_all_helper('referral_customers', MODEL_CLASS, params, filters) end |
#create(params = {}) ⇒ Object
Create a referral customer. This function requires the Partner User’s API key.
7 8 9 10 11 |
# File 'lib/easypost/services/referral_customer.rb', line 7 def create(params = {}) response = @client.make_request(:post, 'referral_customers', { user: params }) EasyPost::InternalUtilities::Json.convert_json_to_object(response, MODEL_CLASS) end |
#get_next_page(collection, page_size = nil) ⇒ Object
Get the next page of referral customers.
34 35 36 37 38 39 40 41 |
# File 'lib/easypost/services/referral_customer.rb', line 34 def get_next_page(collection, page_size = nil) raise EasyPost::Errors::EndOfPaginationError.new unless more_pages?(collection) params = { before_id: collection.referral_customers.last.id } params[:page_size] = page_size unless page_size.nil? all(params) end |
#update_email(user_id, email) ⇒ Object
Update a referral customer. This function requires the Partner User’s API key.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/easypost/services/referral_customer.rb', line 14 def update_email(user_id, email) wrapped_params = { user: { email: email, }, } @client.make_request(:put, "referral_customers/#{user_id}", wrapped_params) # return true if API succeeds, else an error is throw if it fails. true end |