Class: Taler::Client
- Inherits:
-
Object
- Object
- Taler::Client
- Defined in:
- lib/taler/client.rb
Overview
Access the GNU Taler merchant backend API.
Instance Method Summary collapse
-
#create_order(amount:, summary:, fulfillment_url: nil, fulfillment_message: nil) ⇒ Hash
The resonse from the backend, usually just containing an order id, e.g.
-
#fetch_order(order_id) ⇒ Hash
The order status returned by the backend.
-
#initialize(backend_url, password) ⇒ Client
constructor
A new instance of Client.
- #order_status_url(order_id) ⇒ String
-
#refund_order(order_id, refund:, reason:) ⇒ Hash
Response from the merchant backend.
-
#request_token ⇒ String
Obtain an access token to authenticate all other API calls.
Constructor Details
#initialize(backend_url, password) ⇒ Client
Returns a new instance of Client.
13 14 15 16 |
# File 'lib/taler/client.rb', line 13 def initialize(backend_url, password) @backend_url = backend_url @password = password end |
Instance Method Details
#create_order(amount:, summary:, fulfillment_url: nil, fulfillment_message: nil) ⇒ Hash
Returns The resonse from the backend, usually just containing an
order id, e.g. {order_id: "xxxxx"}.
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/taler/client.rb', line 36 def create_order(amount:, summary:, fulfillment_url: nil, fulfillment_message: nil) url = "#{@backend_url}/private/orders" order = { amount: amount, summary: summary } order[:fulfillment_url] = fulfillment_url unless fulfillment_url.nil? order[:fulfillment_message] = unless .nil? payload = {order:, create_token: false} request(url, payload:) end |
#fetch_order(order_id) ⇒ Hash
Returns The order status returned by the backend.
56 57 58 59 |
# File 'lib/taler/client.rb', line 56 def fetch_order(order_id) url = "#{@backend_url}/private/orders/#{order_id}" request(url) end |
#order_status_url(order_id) ⇒ String
50 51 52 |
# File 'lib/taler/client.rb', line 50 def order_status_url(order_id) "#{@backend_url}/orders/#{order_id}" end |
#refund_order(order_id, refund:, reason:) ⇒ Hash
Returns Response from the merchant backend.
66 67 68 69 70 |
# File 'lib/taler/client.rb', line 66 def refund_order(order_id, refund:, reason:) url = "#{@backend_url}/private/orders/#{order_id}/refund" payload = {refund:, reason:} request(url, payload:) end |
#request_token ⇒ String
Obtain an access token to authenticate all other API calls.
21 22 23 24 25 26 |
# File 'lib/taler/client.rb', line 21 def request_token url = "#{@backend_url}/private/token" payload = {scope: "write"} result = request(url, token: auth_token, payload:) result.fetch("token") end |