Class: EasyPost::Referral
- Inherits:
-
Resource
- Object
- EasyPostObject
- Resource
- EasyPost::Referral
- Defined in:
- lib/easypost/referral.rb
Overview
Referral objects are User objects created from a Partner user.
Instance Attribute Summary
Attributes inherited from EasyPostObject
#api_key, #name, #parent, #unsaved_values
Class Method Summary collapse
-
.add_credit_card(referral_api_key, number, expiration_month, expiration_year, cvc, priority = 'primary') ⇒ Object
Add credit card to a referral user.
-
.all(params = {}, api_key = nil) ⇒ Object
Retrieve a list of referral users.
-
.create(params = {}, api_key = nil) ⇒ Object
Create a referral user.
-
.update_email(email, user_id, api_key = nil) ⇒ Object
Update a referral user.
Methods inherited from Resource
class_name, #delete, each, #refresh, retrieve, #save, url, #url
Methods inherited from EasyPostObject
#[], #[]=, #as_json, construct_from, #deconstruct_keys, #each, #id, #id=, #initialize, #inspect, #keys, #refresh_from, #to_hash, #to_json, #to_s, #values
Constructor Details
This class inherits a constructor from EasyPost::EasyPostObject
Class Method Details
.add_credit_card(referral_api_key, number, expiration_month, expiration_year, cvc, priority = 'primary') ⇒ Object
Add credit card to a referral user. This function requires the Referral User’s API key.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/easypost/referral.rb', line 31 def self.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::Error.new('Could not send card details to Stripe, please try again later.') end response = create_easypost_credit_card(referral_api_key, stripe_credit_card_token, priority) EasyPost::Util.convert_to_easypost_object(response, referral_api_key) end |
.all(params = {}, api_key = nil) ⇒ Object
Retrieve a list of referral users. This function requires the Partner User’s API key.
25 26 27 28 |
# File 'lib/easypost/referral.rb', line 25 def self.all(params = {}, api_key = nil) response = EasyPost.make_request(:get, '/v2/referral_customers', api_key, params) EasyPost::Util.convert_to_easypost_object(response, api_key) end |
.create(params = {}, api_key = nil) ⇒ Object
Create a referral user. This function requires the Partner User’s API key.
6 7 8 9 |
# File 'lib/easypost/referral.rb', line 6 def self.create(params = {}, api_key = nil) response = EasyPost.make_request(:post, '/v2/referral_customers', api_key, { user: params }) EasyPost::Util.convert_to_easypost_object(response, api_key) end |
.update_email(email, user_id, api_key = nil) ⇒ Object
Update a referral user. This function requires the Partner User’s API key.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/easypost/referral.rb', line 12 def self.update_email(email, user_id, api_key = nil) wrapped_params = { user: { email: email, }, } EasyPost.make_request(:put, "/v2/referral_customers/#{user_id}", api_key, wrapped_params) # return true if API succeeds, else an error is throw if it fails. true end |