Class: Taler::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/taler/client.rb

Overview

Access the GNU Taler merchant backend API.

See: https://docs.taler.net/core/api-merchant.html

Instance Method Summary collapse

Constructor Details

#initialize(backend_url, password) ⇒ Client

Returns a new instance of Client.

Parameters:

  • backend_url (String)

    e.g. "https://backend.demo.taler.net/instances/sandbox"

  • password (String)


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"}.

Parameters:

  • amount (String)

    e.g. "KUDOS:200"

  • summary (String)

    A description of the order displayed to the user.

  • fulfillment_url (String) (defaults to: nil)

    The user is redirected to this URL after payment. The order status page also links here.

  • fulfillment_message (String) (defaults to: nil)

    Text to display to the user after payment.

Returns:

  • (Hash)

    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] = fulfillment_message unless fulfillment_message.nil?
  payload = {order:, create_token: false}
  request(url, payload:)
end

#fetch_order(order_id) ⇒ Hash

Returns The order status returned by the backend.

Parameters:

  • order_id (String)

Returns:

  • (Hash)

    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

Parameters:

  • order_id (String)

Returns:

  • (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.

Parameters:

  • order_id (String)
  • refund (String)

    The amount with currency.

  • reason (String)

    Why are you refunding?

Returns:

  • (Hash)

    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_tokenString

Obtain an access token to authenticate all other API calls.

Returns:

  • (String)


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