Class: SolidusPaybright::ApiClient
- Inherits:
-
Object
- Object
- SolidusPaybright::ApiClient
- Defined in:
- lib/solidus_paybright/api_client.rb
Instance Method Summary collapse
-
#initialize(api_key, api_token, base_url) ⇒ ApiClient
constructor
A new instance of ApiClient.
-
#refund!(paybright_order_id, amount) ⇒ Boolean
Refund some amount of refunds on an Paybright order.
-
#void!(paybright_order_id) ⇒ Boolean
This cancels an authorized order.
Constructor Details
#initialize(api_key, api_token, base_url) ⇒ ApiClient
Returns a new instance of ApiClient.
11 12 13 14 15 |
# File 'lib/solidus_paybright/api_client.rb', line 11 def initialize(api_key, api_token, base_url) @api_key = api_key @api_token = api_token @base_url = base_url end |
Instance Method Details
#refund!(paybright_order_id, amount) ⇒ Boolean
Refund some amount of refunds on an Paybright order. Once a loan is fully refunded it cannot be reinstated.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/solidus_paybright/api_client.rb', line 45 def refund!(paybright_order_id, amount) uri = "#{@base_url}/orders/#{paybright_order_id}/refund/" body = "{\"amount\": #{amount}}" nonce = SecureRandom.hex response = Typhoeus.post( uri, body: body, headers: { "Authorization" => auth_header_for(nonce, body, uri), "Content-Type" => "application/json" } ) handle_response(response) end |
#void!(paybright_order_id) ⇒ Boolean
This cancels an authorized order. For example, when a user decides to cancel their order before it’s fulfilled. Once a loan is voided, it is permanently canceled and cannot be reauthorized.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/solidus_paybright/api_client.rb', line 23 def void!(paybright_order_id) uri = "#{@base_url}/orders/#{paybright_order_id}/void/" body = "" nonce = SecureRandom.hex response = Typhoeus.post( uri, body: body, headers: { "Authorization" => auth_header_for(nonce, body, uri) } ) handle_response(response) end |