taler 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2264b54990f6df1015504ea8e2d51e9e0f3f9e8fb0d2e6948e32b900e4c899dd
4
- data.tar.gz: ae655bb16c4a6d5e9aab5c5da7051d19895232388c2709b3d51e67f040137b0e
3
+ metadata.gz: dc1ef9028362bec363c1c645759524173618697fc1a0ce52cfb87539c5ecc2b1
4
+ data.tar.gz: 50654905eb23b1f07571cbe96bb30d223320ea65f82779e2a3a7990bf5af4bfe
5
5
  SHA512:
6
- metadata.gz: '0718fc34e186d2a5af60bad022efa7362eddcc4844b579aa417f43565b5004a0ddbfa1de83148540d6555dcd52f87bb7a09cfdf60d1b1dc90cba70ae0a35c50e'
7
- data.tar.gz: 3f5b4abddbd440dd5df338aa0269b91360e3ed8cb8a91dd0e23a002b5d2b95b83cb80ec0cdba3beb3eae87dab31949a0037e6c8d98dff1d8a42def2fd180afec
6
+ metadata.gz: c4ada42f23bfc80478b5bff58d03b166c221bfc7d054153f8f079a6b4869eb319a0d6051826a05df53b6053dcf0e3b08cc133524a9a2e5085ece452ad1fdfa8b
7
+ data.tar.gz: '0029a33dfd7313028d146748039acd2d38683cb5b25b6ec8916e3097e79c129a9281381423bac354c888c74336a63a2b33ced5697fee1c83bd383da301bdc510'
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.0] - 2026-02-24
4
+
5
+ - Update docs and rbs file.
6
+ - Custom methods `Taler::Order#to_s` and `#inspect`.
7
+ - Replaced deprecated password auth with access token.
8
+
3
9
  ## [0.2.0] - 2026-02-02
4
10
 
5
11
  - Add `Taler::Order` as an easier interface.
data/README.md CHANGED
@@ -13,6 +13,8 @@ bundle add taler
13
13
  ## Usage
14
14
 
15
15
  ```rb
16
+ require "taler"
17
+
16
18
  backend_url = "https://backend.demo.taler.net/instances/sandbox"
17
19
  backend_password = "sandbox"
18
20
 
@@ -47,11 +49,13 @@ After checking out the repo, run `bin/setup` to install dependencies.
47
49
  Then, run `rake` to run the tests.
48
50
  You can also run `bin/console` for an interactive prompt.
49
51
 
50
- To install this gem onto your local machine, run `bundle exec rake install`.
51
- To release a new version, update the version number in `version.rb`,
52
- and then run `bundle exec rake release`, which will create a git tag for the
53
- version, push git commits and the created tag, and push the `.gem` file
54
- to [rubygems.org](https://rubygems.org).
52
+ ## Release
53
+
54
+ - Update the version number in `lib/taler/version.rb`.
55
+ - Update the `CHANGELOG.md` file.
56
+ - Run `bundle update`.
57
+ - Commit.
58
+ - Run `bundle exec rake release` to build, tag and push the gem.
55
59
 
56
60
  ## Contributing
57
61
 
data/lib/taler/client.rb CHANGED
@@ -8,18 +8,31 @@ module Taler
8
8
  #
9
9
  # See: https://docs.taler.net/core/api-merchant.html
10
10
  class Client
11
+ # @param backend_url [String] e.g. `"https://backend.demo.taler.net/instances/sandbox"`
12
+ # @param password [String]
11
13
  def initialize(backend_url, password)
12
14
  @backend_url = backend_url
13
15
  @password = password
14
16
  end
15
17
 
18
+ # Obtain an access token to authenticate all other API calls.
19
+ #
20
+ # @return [String]
16
21
  def request_token
17
22
  url = "#{@backend_url}/private/token"
18
23
  payload = {scope: "write"}
19
- result = request(url, payload:)
24
+ result = request(url, token: auth_token, payload:)
20
25
  result.fetch("token")
21
26
  end
22
27
 
28
+ # @param amount [String] e.g. "KUDOS:200"
29
+ # @param summary [String] A description of the order displayed to the user.
30
+ # @param fulfillment_url [String] The user is redirected to this URL after
31
+ # payment. The order status page also links here.
32
+ # @param fulfillment_message [String] Text to display to the user after
33
+ # payment.
34
+ # @return [Hash] The resonse from the backend, usually just containing an
35
+ # order id, e.g. `{order_id: "xxxxx"}`
23
36
  def create_order(amount:, summary:, fulfillment_url: nil, fulfillment_message: nil)
24
37
  url = "#{@backend_url}/private/orders"
25
38
  order = {
@@ -32,15 +45,24 @@ module Taler
32
45
  request(url, payload:)
33
46
  end
34
47
 
48
+ # @param order_id [String]
49
+ # @return [String]
35
50
  def order_status_url(order_id)
36
51
  "#{@backend_url}/orders/#{order_id}"
37
52
  end
38
53
 
54
+ # @param order_id [String]
55
+ # @return [Hash] The order status returned by the backend.
39
56
  def fetch_order(order_id)
40
57
  url = "#{@backend_url}/private/orders/#{order_id}"
41
58
  request(url)
42
59
  end
43
60
 
61
+ # @param order_id [String]
62
+ # @param refund [String] The amount with currency.
63
+ # @param reason [String] Why are you refunding?
64
+ #
65
+ # @return [Hash] Response from the merchant backend.
44
66
  def refund_order(order_id, refund:, reason:)
45
67
  url = "#{@backend_url}/private/orders/#{order_id}/refund"
46
68
  payload = {refund:, reason:}
@@ -49,21 +71,21 @@ module Taler
49
71
 
50
72
  private
51
73
 
74
+ # @return [String]
52
75
  def auth_token
53
76
  "secret-token:#{@password}"
54
77
  end
55
78
 
56
- def get(url, token = auth_token)
57
- headers = {
58
- "Authorization" => "Bearer #{token}",
59
- "Accept" => "application/json",
60
- "User-Agent" => "Taler Ruby"
61
- }
62
- response = Net::HTTP.get(URI(url), headers)
63
- JSON.parse(response)
79
+ # @return [String]
80
+ def access_token
81
+ @access_token ||= request_token
64
82
  end
65
83
 
66
- def request(url, token: auth_token, payload: nil)
84
+ # @param url [String]
85
+ # @param token [String]
86
+ # @param payload [Hash]
87
+ # @return [String]
88
+ def request(url, token: access_token, payload: nil)
67
89
  uri = URI(url)
68
90
  headers = {
69
91
  "Authorization" => "Bearer #{token}",
data/lib/taler/order.rb CHANGED
@@ -8,6 +8,11 @@ module Taler
8
8
  # @param backend_url [String] e.g. `"https://backend.demo.taler.net/instances/sandbox"`
9
9
  # @param password [String] e.g. `"sandbox"`
10
10
  # @param id [String] The order id of an existing order.
11
+ # @example Connect to the official demo backend
12
+ # Taler::Order.new(
13
+ # backend_url: "https://backend.demo.taler.net/instances/sandbox",
14
+ # password: "sandbox"
15
+ # )
11
16
  def initialize(backend_url:, password:, id: nil)
12
17
  @client = Client.new(backend_url, password)
13
18
  @id = id
@@ -15,6 +20,12 @@ module Taler
15
20
 
16
21
  # Create a new order record ready to take a payment.
17
22
  #
23
+ # @param amount [String] e.g. "KUDOS:200"
24
+ # @param summary [String] A description of the order displayed to the user.
25
+ # @param fulfillment_url [String] The user is redirected to this URL after
26
+ # payment. The order status page also links here.
27
+ # @param fulfillment_message [String] Text to display to the user after
28
+ # payment.
18
29
  # @return [String] The id of the new order.
19
30
  def create(amount:, summary:, fulfillment_url: nil, fulfillment_message: nil)
20
31
  response = @client.create_order(
@@ -29,6 +40,8 @@ module Taler
29
40
  # The merchant backend opens the Taler plugin or app if it can.
30
41
  # Otherwise it shows a QR code to scan in the app and provides
31
42
  # installation instructions.
43
+ #
44
+ # @return [String]
32
45
  def status_url
33
46
  @client.order_status_url(@id)
34
47
  end
@@ -36,12 +49,14 @@ module Taler
36
49
  # Access order status fields.
37
50
  #
38
51
  # It queries the backend if it hasn't done that already.
39
- # Call `#reload` beforehand to get the latest status from the backend.
52
+ # Call {#reload} beforehand to get the latest status from the backend.
40
53
  #
41
54
  # @param key [String] A field in the order status response of the backend,
42
55
  # e.g. `order_status`.
43
- # @return [String,TrueClass,FalseClass] The value of the field.
56
+ # @return [String,true,false] The value of the field.
44
57
  # Any simple type supported by JSON.
58
+ # @example
59
+ # fetch("order_status") #=> "unpaid"
45
60
  def fetch(key)
46
61
  reload unless @status
47
62
  @status.fetch(key)
@@ -49,8 +64,10 @@ module Taler
49
64
 
50
65
  # Query the latest order information from the backend.
51
66
  #
52
- # If you called `#fetch` in the past and are expecting updates from
67
+ # If you called {#fetch} in the past and are expecting updates from
53
68
  # user interaction, you want to call this.
69
+ #
70
+ # @return [Hash] The order status returned by the backend.
54
71
  def reload
55
72
  @status = @client.fetch_order(@id)
56
73
  end
@@ -64,5 +81,24 @@ module Taler
64
81
  def refund(refund:, reason:)
65
82
  @client.refund_order(@id, refund:, reason:)
66
83
  end
84
+
85
+ # @return [String]
86
+ def inspect
87
+ status = @status.to_h.slice(*%w[
88
+ order_status
89
+ deposit_total
90
+ wired
91
+ refunded
92
+ refund_pending
93
+ refund_amount
94
+ ])
95
+ "#<#{self.class.name} #{status_url} #{status.inspect}>"
96
+ end
97
+
98
+ # @return [String]
99
+ def to_s
100
+ status = @status.to_h.slice("order_status", "refunded")
101
+ "#<#{self.class.name} #{status_url} #{status.inspect}>"
102
+ end
67
103
  end
68
104
  end
data/lib/taler/version.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Taler
4
- VERSION = "0.2.0"
4
+ # @return [String]
5
+ VERSION = "0.3.0"
5
6
  end
data/lib/taler.rb CHANGED
@@ -4,6 +4,8 @@ require_relative "taler/client"
4
4
  require_relative "taler/order"
5
5
  require_relative "taler/version"
6
6
 
7
+ # GNU Taler payment system interface
7
8
  module Taler
9
+ # Base error class for errors raised in this module
8
10
  class Error < StandardError; end
9
11
  end
data/sig/taler.rbs CHANGED
@@ -1,4 +1,148 @@
1
+ # GNU Taler payment system interface
1
2
  module Taler
2
3
  VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
- end
4
+
5
+ # Base error class for errors raised in this module
6
+ class Error < StandardError
7
+ end
8
+
9
+ # Order representation with convenient access to the merchant API.
10
+ class Order
11
+ # Connect an Order to the Taler merchant backend.
12
+ #
13
+ # _@param_ `backend_url` — e.g. `"https://backend.demo.taler.net/instances/sandbox"`
14
+ #
15
+ # _@param_ `password` — e.g. `"sandbox"`
16
+ #
17
+ # _@param_ `id` — The order id of an existing order.
18
+ #
19
+ # Connect to the official demo backend
20
+ # ```ruby
21
+ # Taler::Order.new(
22
+ # backend_url: "https://backend.demo.taler.net/instances/sandbox",
23
+ # password: "sandbox"
24
+ # )
25
+ # ```
26
+ def initialize: (backend_url: String, password: String, ?id: String?) -> void
27
+
28
+ # Create a new order record ready to take a payment.
29
+ #
30
+ # _@param_ `amount` — e.g. "KUDOS:200"
31
+ #
32
+ # _@param_ `summary` — A description of the order displayed to the user.
33
+ #
34
+ # _@param_ `fulfillment_url` — The user is redirected to this URL after payment. The order status page also links here.
35
+ #
36
+ # _@param_ `fulfillment_message` — Text to display to the user after payment.
37
+ #
38
+ # _@return_ — The id of the new order.
39
+ def create: (
40
+ amount: String,
41
+ summary: String,
42
+ ?fulfillment_url: String?,
43
+ ?fulfillment_message: String?
44
+ ) -> String
45
+
46
+ # The page where the customer can pay or accept a refund,
47
+ # depending on the state of the order.
48
+ #
49
+ # The merchant backend opens the Taler plugin or app if it can.
50
+ # Otherwise it shows a QR code to scan in the app and provides
51
+ # installation instructions.
52
+ def status_url: () -> String
53
+
54
+ # Access order status fields.
55
+ #
56
+ # It queries the backend if it hasn't done that already.
57
+ # Call {#reload} beforehand to get the latest status from the backend.
58
+ #
59
+ # _@param_ `key` — A field in the order status response of the backend, e.g. `order_status`.
60
+ #
61
+ # _@return_ — The value of the field.
62
+ # Any simple type supported by JSON.
63
+ #
64
+ # ```ruby
65
+ # fetch("order_status") #=> "unpaid"
66
+ # ```
67
+ def fetch: (String key) -> (String | bool)
68
+
69
+ # Query the latest order information from the backend.
70
+ #
71
+ # If you called {#fetch} in the past and are expecting updates from
72
+ # user interaction, you want to call this.
73
+ #
74
+ # _@return_ — The order status returned by the backend.
75
+ def reload: () -> ::Hash[untyped, untyped]
76
+
77
+ # Issue a refund request for this order.
78
+ #
79
+ # _@param_ `refund` — The amount with currency.
80
+ #
81
+ # _@param_ `reason` — Why are you refunding?
82
+ #
83
+ # _@return_ — Response from the merchant backend.
84
+ def refund: (refund: String, reason: String) -> ::Hash[untyped, untyped]
85
+
86
+ def inspect: () -> String
87
+
88
+ def to_s: () -> String
89
+ end
90
+
91
+ # Access the GNU Taler merchant backend API.
92
+ #
93
+ # See: https://docs.taler.net/core/api-merchant.html
94
+ class Client
95
+ # _@param_ `backend_url` — e.g. `"https://backend.demo.taler.net/instances/sandbox"`
96
+ #
97
+ # _@param_ `password`
98
+ def initialize: (String backend_url, String password) -> void
99
+
100
+ # Obtain an access token to authenticate all other API calls.
101
+ def request_token: () -> String
102
+
103
+ # _@param_ `amount` — e.g. "KUDOS:200"
104
+ #
105
+ # _@param_ `summary` — A description of the order displayed to the user.
106
+ #
107
+ # _@param_ `fulfillment_url` — The user is redirected to this URL after payment. The order status page also links here.
108
+ #
109
+ # _@param_ `fulfillment_message` — Text to display to the user after payment.
110
+ #
111
+ # _@return_ — The resonse from the backend, usually just containing an
112
+ # order id, e.g. `{order_id: "xxxxx"}`
113
+ def create_order: (
114
+ amount: String,
115
+ summary: String,
116
+ ?fulfillment_url: String?,
117
+ ?fulfillment_message: String?
118
+ ) -> ::Hash[untyped, untyped]
119
+
120
+ # _@param_ `order_id`
121
+ def order_status_url: (String order_id) -> String
122
+
123
+ # _@param_ `order_id`
124
+ #
125
+ # _@return_ — The order status returned by the backend.
126
+ def fetch_order: (String order_id) -> ::Hash[untyped, untyped]
127
+
128
+ # _@param_ `order_id`
129
+ #
130
+ # _@param_ `refund` — The amount with currency.
131
+ #
132
+ # _@param_ `reason` — Why are you refunding?
133
+ #
134
+ # _@return_ — Response from the merchant backend.
135
+ def refund_order: (String order_id, refund: String, reason: String) -> ::Hash[untyped, untyped]
136
+
137
+ def auth_token: () -> String
138
+
139
+ def access_token: () -> String
140
+
141
+ # _@param_ `url`
142
+ #
143
+ # _@param_ `token`
144
+ #
145
+ # _@param_ `payload`
146
+ def request: (String url, ?token: String, ?payload: ::Hash[untyped, untyped]?) -> String
147
+ end
148
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maikel Linke
@@ -37,6 +37,20 @@ dependencies:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
39
  version: '0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: guard-rspec
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
40
54
  - !ruby/object:Gem::Dependency
41
55
  name: rspec
42
56
  requirement: !ruby/object:Gem::Requirement
@@ -121,6 +135,20 @@ dependencies:
121
135
  - - ">="
122
136
  - !ruby/object:Gem::Version
123
137
  version: '0'
138
+ - !ruby/object:Gem::Dependency
139
+ name: sord
140
+ requirement: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ type: :development
146
+ prerelease: false
147
+ version_requirements: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
124
152
  description: Create and refund orders through the Taler merchant backend API.
125
153
  email:
126
154
  - maikel@email.org.au
@@ -139,7 +167,6 @@ files:
139
167
  - lib/taler/client.rb
140
168
  - lib/taler/order.rb
141
169
  - lib/taler/version.rb
142
- - sig/client.rbs
143
170
  - sig/taler.rbs
144
171
  homepage: https://github.com/openfoodfoundation/taler-ruby
145
172
  licenses:
@@ -154,7 +181,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
154
181
  requirements:
155
182
  - - ">="
156
183
  - !ruby/object:Gem::Version
157
- version: 3.4.0
184
+ version: 3.3.0
158
185
  required_rubygems_version: !ruby/object:Gem::Requirement
159
186
  requirements:
160
187
  - - ">="
data/sig/client.rbs DELETED
@@ -1,23 +0,0 @@
1
- module Taler
2
- class Client
3
- @backend_url: untyped
4
-
5
- @password: untyped
6
-
7
- def initialize: (untyped backend_url, untyped password) -> void
8
-
9
- def request_token: () -> untyped
10
-
11
- def create_order: (untyped amount, untyped summary, untyped fulfillment_url) -> untyped
12
-
13
- def fetch_order: (untyped order_id) -> untyped
14
-
15
- private
16
-
17
- def auth_token: () -> ::String
18
-
19
- def get: (untyped url, ?untyped token) -> untyped
20
-
21
- def request: (untyped url, ?token: untyped, ?payload: untyped?) -> untyped
22
- end
23
- end