class EasyPost::Services::ReferralCustomer

Constants

MODEL_CLASS

The User object can be used to manage your own account and to create child accounts.

Public Instance Methods

add_credit_card(referral_api_key, number, expiration_month, expiration_year, cvc, priority = 'primary') click to toggle source

Add credit card to a referral customer. This function requires the ReferralCustomer Customer’s API key.

# 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
all(params = {}) click to toggle source

Retrieve a list of referral customers. This function requires the Partner User’s API key.

# 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 = {}) click to toggle source

Create a referral customer. This function requires the Partner User’s API key.

# 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) click to toggle source

Get the next page of referral customers.

# 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) click to toggle source

Update a referral customer. This function requires the Partner User’s API key.

# 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