Class: SolidusPaybright::ApiClient

Inherits:
Object
  • Object
show all
Defined in:
lib/solidus_paybright/api_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_key, api_token, base_url) ⇒ ApiClient

Returns a new instance of ApiClient.

Parameters:

  • api_key (String)

    The account Api key

  • api_token (String)

    The account secret Api token

  • base_url (String)

    The API base endpoint



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.

Parameters:

  • paybright_order_id (String)

    The Paybright order reference

  • amount (String)

    The amount to refund

Returns:

  • (Boolean)

    The successfulness of the refund operation



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.

Parameters:

  • paybright_order_id (String)

    The Paybright order reference

Returns:

  • (Boolean)

    The successfulness of the void operation



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