Class: EasyPost::Services::Billing

Inherits:
Service
  • Object
show all
Defined in:
lib/easypost/services/billing.rb

Instance Method Summary collapse

Methods inherited from Service

#initialize

Constructor Details

This class inherits a constructor from EasyPost::Services::Service

Instance Method Details

#delete_payment_method(priority) ⇒ Object

Delete a payment method.



20
21
22
23
24
25
26
27
28
29
# 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') ⇒ Object

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



7
8
9
10
11
12
13
14
15
16
17
# 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_methodsObject

Retrieve all payment methods.



32
33
34
35
36
37
38
39
40
41
# 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