Class: Taler::Order
- Inherits:
-
Object
- Object
- Taler::Order
- Defined in:
- lib/taler/order.rb
Overview
Order representation with convenient access to the merchant API.
Instance Method Summary collapse
-
#create(amount:, summary:, fulfillment_url: nil, fulfillment_message: nil) ⇒ String
Create a new order record ready to take a payment.
-
#fetch(key) ⇒ String, ...
Access order status fields.
-
#initialize(backend_url:, password:, id: nil) ⇒ Order
constructor
Connect an Order to the Taler merchant backend.
- #inspect ⇒ String
-
#refund(refund:, reason:) ⇒ Hash
Issue a refund request for this order.
-
#reload ⇒ Hash
Query the latest order information from the backend.
-
#status_url ⇒ String
The page where the customer can pay or accept a refund, depending on the state of the order.
- #to_s ⇒ String
Constructor Details
#initialize(backend_url:, password:, id: nil) ⇒ Order
Connect an Order to the Taler merchant backend.
16 17 18 19 |
# File 'lib/taler/order.rb', line 16 def initialize(backend_url:, password:, id: nil) @client = Client.new(backend_url, password) @id = id end |
Instance Method Details
#create(amount:, summary:, fulfillment_url: nil, fulfillment_message: nil) ⇒ String
Create a new order record ready to take a payment.
30 31 32 33 34 35 |
# File 'lib/taler/order.rb', line 30 def create(amount:, summary:, fulfillment_url: nil, fulfillment_message: nil) response = @client.create_order( amount:, summary:, fulfillment_url:, fulfillment_message: ) @id = response.fetch("order_id") end |
#fetch(key) ⇒ String, ...
Access order status fields.
It queries the backend if it hasn't done that already. Call #reload beforehand to get the latest status from the backend.
60 61 62 63 |
# File 'lib/taler/order.rb', line 60 def fetch(key) reload unless @status @status.fetch(key) end |
#inspect ⇒ String
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/taler/order.rb', line 86 def inspect status = @status.to_h.slice(*%w[ order_status deposit_total wired refunded refund_pending refund_amount ]) "#<#{self.class.name} #{status_url} #{status.inspect}>" end |
#refund(refund:, reason:) ⇒ Hash
Issue a refund request for this order.
81 82 83 |
# File 'lib/taler/order.rb', line 81 def refund(refund:, reason:) @client.refund_order(@id, refund:, reason:) end |
#reload ⇒ Hash
Query the latest order information from the backend.
If you called #fetch in the past and are expecting updates from user interaction, you want to call this.
71 72 73 |
# File 'lib/taler/order.rb', line 71 def reload @status = @client.fetch_order(@id) end |
#status_url ⇒ String
The page where the customer can pay or accept a refund, depending on the state of the order.
The merchant backend opens the Taler plugin or app if it can. Otherwise it shows a QR code to scan in the app and provides installation instructions.
45 46 47 |
# File 'lib/taler/order.rb', line 45 def status_url @client.order_status_url(@id) end |
#to_s ⇒ String
99 100 101 102 |
# File 'lib/taler/order.rb', line 99 def to_s status = @status.to_h.slice("order_status", "refunded") "#<#{self.class.name} #{status_url} #{status.inspect}>" end |