class EasyPost::Services::Billing

Public Instance Methods

delete_payment_method(priority) click to toggle source

Delete a payment method.

# File lib/easypost/services/billing.rb, line 20
def delete_payment_method(priority)
  payment_info = get_payment_method_info(priority.downcase)
  endpoint = payment_info[0]
  payment_id = payment_info[1]

  @client.make_request(:delete, "#{endpoint}/#{payment_id}")

  # Return true if succeeds, an error will be thrown if it fails
  true
end
fund_wallet(amount, priority = 'primary') click to toggle source

Fund your EasyPost wallet by charging your primary or secondary card on file.

# File lib/easypost/services/billing.rb, line 7
def fund_wallet(amount, priority = 'primary')
  payment_info = get_payment_method_info(priority.downcase)
  endpoint = payment_info[0]
  payment_id = payment_info[1]

  wrapped_params = { amount: amount }
  @client.make_request(:post, "#{endpoint}/#{payment_id}/charges", wrapped_params)

  # Return true if succeeds, an error will be thrown if it fails
  true
end
retrieve_payment_methods() click to toggle source

Retrieve all payment methods.

# File lib/easypost/services/billing.rb, line 32
def retrieve_payment_methods
  response = @client.make_request(:get, '/payment_methods')
  payment_methods = EasyPost::InternalUtilities::Json.convert_json_to_object(response)

  if payment_methods['id'].nil?
    raise EasyPost::Errors::InvalidObjectError.new(EasyPost::Constants::NO_PAYMENT_METHODS)
  end

  payment_methods
end