tamara 0.1.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 +7 -0
- data/.rubocop.yml +114 -0
- data/.rubocop_todo.yml +21 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +22 -0
- data/Gemfile.lock +227 -0
- data/Guardfile +42 -0
- data/LICENSE.txt +21 -0
- data/README.md +290 -0
- data/Rakefile +19 -0
- data/lib/generators/tamara/install_generator.rb +15 -0
- data/lib/generators/tamara/templates/tamara.rb +8 -0
- data/lib/tamara/api/api_token.rb +14 -0
- data/lib/tamara/api/application_service.rb +48 -0
- data/lib/tamara/api/orders/authorize.rb +26 -0
- data/lib/tamara/api/orders/cancel.rb +38 -0
- data/lib/tamara/api/orders/create.rb +71 -0
- data/lib/tamara/api/orders/details/merchant_order.rb +28 -0
- data/lib/tamara/api/orders/details/tamara_order.rb +28 -0
- data/lib/tamara/api/orders.rb +56 -0
- data/lib/tamara/api/payment_options/check.rb +34 -0
- data/lib/tamara/api/payment_options.rb +13 -0
- data/lib/tamara/api/payment_types.rb +23 -0
- data/lib/tamara/api/payments/capture.rb +40 -0
- data/lib/tamara/api/payments.rb +16 -0
- data/lib/tamara/api/request.rb +49 -0
- data/lib/tamara/api/signature.rb +25 -0
- data/lib/tamara/api/webhooks.rb +28 -0
- data/lib/tamara/configuration.rb +5 -0
- data/lib/tamara/errors.rb +67 -0
- data/lib/tamara/hmac.rb +20 -0
- data/lib/tamara/json_schemas/address.rb +23 -0
- data/lib/tamara/json_schemas/amount.rb +19 -0
- data/lib/tamara/json_schemas/checkout_optional_keys.rb +11 -0
- data/lib/tamara/json_schemas/consumer.rb +21 -0
- data/lib/tamara/json_schemas/discount.rb +17 -0
- data/lib/tamara/json_schemas/item.rb +41 -0
- data/lib/tamara/json_schemas/merchant_url.rb +19 -0
- data/lib/tamara/json_schemas/orders/cancel.rb +30 -0
- data/lib/tamara/json_schemas/orders/create.rb +61 -0
- data/lib/tamara/json_schemas/payment_options/check.rb +25 -0
- data/lib/tamara/json_schemas/payment_types.rb +21 -0
- data/lib/tamara/json_schemas/payments/capture.rb +38 -0
- data/lib/tamara/json_schemas/risk_assessment.rb +65 -0
- data/lib/tamara/json_schemas/types/boolean.rb +15 -0
- data/lib/tamara/json_schemas/types/date.rb +17 -0
- data/lib/tamara/json_schemas/types/enum.rb +15 -0
- data/lib/tamara/json_schemas/types/float.rb +16 -0
- data/lib/tamara/json_schemas/types/integer.rb +17 -0
- data/lib/tamara/json_schemas/types/string.rb +21 -0
- data/lib/tamara/json_schemas/types/url.rb +15 -0
- data/lib/tamara/json_schemas/types/uuid.rb +19 -0
- data/lib/tamara/json_schemas/validator.rb +66 -0
- data/lib/tamara/json_schemas/webhook.rb +33 -0
- data/lib/tamara/json_schemas/webhook_event.rb +37 -0
- data/lib/tamara/version.rb +3 -0
- data/lib/tamara.rb +101 -0
- data/sig/tamara.rbs +4 -0
- metadata +181 -0
data/README.md
ADDED
@@ -0,0 +1,290 @@
|
|
1
|
+
# Tamara
|
2
|
+
|
3
|
+
Ruby gem for [Tamara](https://tamara.co/en-SA)
|
4
|
+
|
5
|
+
For reference on the internals & specifics of Tamara, please head to their [official documentation](https://docs.tamara.co/docs/)
|
6
|
+
|
7
|
+
# Table of Contents
|
8
|
+
1. [Installation](#installation)
|
9
|
+
1. [Configuration](#configuration)
|
10
|
+
1. [APIs](#apis)
|
11
|
+
1. [List Available Payment Types](#list-available-payment-types)
|
12
|
+
1. [Check Payment Options Availability](#check-payment-options-availability)
|
13
|
+
1. [Orders](#online-checkout)
|
14
|
+
1. [Create](#create)
|
15
|
+
1. [Authorize](#authorize)
|
16
|
+
1. [Cancel](#cancel)
|
17
|
+
1. [Order Details](#order-details)
|
18
|
+
1. [Get Order Details by Tamara's order_id](#get-order-details-by-tamaras-order_id)
|
19
|
+
1. [Get Order Details by Merchant's order_reference_id](#get-order-details-by-merchants-order_reference_id)
|
20
|
+
1. [Payments](#payments)
|
21
|
+
1. [Capture](#capture)
|
22
|
+
1. [Webhooks](#webhooks)
|
23
|
+
1. [Register Webhook](#register-webhook)
|
24
|
+
1. [Errors](#errors)
|
25
|
+
1. [Contributing](#contributing)
|
26
|
+
1. [License](#license)
|
27
|
+
|
28
|
+
|
29
|
+
## Installation
|
30
|
+
|
31
|
+
Install the gem and add to the application's Gemfile by executing:
|
32
|
+
|
33
|
+
$ bundle add tamara
|
34
|
+
|
35
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
36
|
+
|
37
|
+
$ gem install tamara
|
38
|
+
|
39
|
+
Next, you need to run the generator:
|
40
|
+
|
41
|
+
$ rails generate tamara:install
|
42
|
+
|
43
|
+
## Configuration
|
44
|
+
|
45
|
+
Configure the gem with your configuration
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
Tamara.configure do |config|
|
49
|
+
config.api_token = "api_token"
|
50
|
+
config.notification_token = "notification_token"
|
51
|
+
config.public_key = "public_key"
|
52
|
+
config.checkout_optional_keys = {}
|
53
|
+
end
|
54
|
+
```
|
55
|
+
|
56
|
+
For `api_token`, you can set its value in 3 ways
|
57
|
+
- Global across whole application (through initializer and configuration)
|
58
|
+
```ruby
|
59
|
+
Tamara.configure do |config|
|
60
|
+
config.api_token = "api_token"
|
61
|
+
end
|
62
|
+
```
|
63
|
+
|
64
|
+
- Per method or block (through the application variables). All consecutive requests will use that token until it is set to a different value
|
65
|
+
```ruby
|
66
|
+
Tamara.api_token = "api_token"
|
67
|
+
```
|
68
|
+
|
69
|
+
- Per request (through opts parameter)
|
70
|
+
```ruby
|
71
|
+
Tamara::PaymentTypes.list(opts: { api_token: "api_token" })
|
72
|
+
```
|
73
|
+
|
74
|
+
## APIs
|
75
|
+
|
76
|
+
Any API call will return an object with following methods:
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
result = Tamara.doSomething
|
80
|
+
result.success?
|
81
|
+
result.failure?
|
82
|
+
result.payload
|
83
|
+
result.error
|
84
|
+
```
|
85
|
+
|
86
|
+
### [List Available Payment Types](https://docs.tamara.co/reference/paymenttypes)
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
Tamara::PaymentTypes.list(country: "SA", order_value: 1)
|
90
|
+
```
|
91
|
+
|
92
|
+
### [Check Payment Options Availability](https://docs.tamara.co/reference/checkpaymentoptionsavailability)
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
Tamara::PaymentOptions.check(country: "SA", phone_number: "544337766", order_value: { amount: 100, currency: "SAR" })
|
96
|
+
```
|
97
|
+
|
98
|
+
### Online Checkout:
|
99
|
+
|
100
|
+
#### [Create](https://docs.tamara.co/reference/createcheckoutsession)
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
Tamara::Orders.create(
|
104
|
+
order_reference_id: "abd12331-a123-1234-4567-fbde34ae",
|
105
|
+
country_code: "SA",
|
106
|
+
description: "Enter order description here",
|
107
|
+
total_amount: {
|
108
|
+
amount: 300,
|
109
|
+
currency: "SAR"
|
110
|
+
},
|
111
|
+
shipping_amount: {
|
112
|
+
amount: 10,
|
113
|
+
currency: "SAR"
|
114
|
+
},
|
115
|
+
tax_amount: {
|
116
|
+
amount: 0,
|
117
|
+
currency: "SAR"
|
118
|
+
},
|
119
|
+
consumer: {
|
120
|
+
email: "customer@email.com",
|
121
|
+
first_name: "Mona",
|
122
|
+
last_name: "Lisa",
|
123
|
+
phone_number: "566027755"
|
124
|
+
},
|
125
|
+
items: [
|
126
|
+
{
|
127
|
+
name: "Lego City 8601",
|
128
|
+
type: "Digital",
|
129
|
+
reference_id: "123",
|
130
|
+
sku: "SA-12436",
|
131
|
+
quantity: 1,
|
132
|
+
unit_price: {
|
133
|
+
amount: 490,
|
134
|
+
currency: "SAR"
|
135
|
+
},
|
136
|
+
total_amount: {
|
137
|
+
amount: 100,
|
138
|
+
currency: "SAR"
|
139
|
+
}
|
140
|
+
}
|
141
|
+
],
|
142
|
+
merchant_url: {
|
143
|
+
cancel: "http://example.com/#/cancel",
|
144
|
+
failure: "http://example.com/#/fail",
|
145
|
+
success: "http://example.com/#/success",
|
146
|
+
notification: "https://example-notification.com/payments/tamaranotifications"
|
147
|
+
},
|
148
|
+
shipping_address: {
|
149
|
+
city: "Riyadh",
|
150
|
+
country_code: "SA",
|
151
|
+
first_name: "Mona",
|
152
|
+
last_name: "Lisa",
|
153
|
+
line1: "3764 Al Urubah Rd",
|
154
|
+
line2: "string",
|
155
|
+
phone_number: "532298658",
|
156
|
+
region: "As Sulimaniyah"
|
157
|
+
}
|
158
|
+
)
|
159
|
+
```
|
160
|
+
|
161
|
+
:exclamation::exclamation::exclamation: For creating an online checkout session, some information might be optional. You can configure these through `checkout_optional_keys` in your initializer.
|
162
|
+
|
163
|
+
The below example will make `description` key optional and `sku, type` optional for `items` array.
|
164
|
+
|
165
|
+
```ruby
|
166
|
+
Tamara.configure do |config|
|
167
|
+
config.checkout_optional_keys = { description: [], items: [:sku, :type] }
|
168
|
+
end
|
169
|
+
```
|
170
|
+
|
171
|
+
:warning: This will not make `items` key optional. To do so, you need to pass an empty array `[]` to the key
|
172
|
+
|
173
|
+
```ruby
|
174
|
+
Tamara.configure do |config|
|
175
|
+
config.checkout_optional_keys = { description: [], items: [] }
|
176
|
+
end
|
177
|
+
```
|
178
|
+
|
179
|
+
#### [Authorize](https://docs.tamara.co/reference/authoriseorder)
|
180
|
+
|
181
|
+
```ruby
|
182
|
+
Tamara::Orders.authorize(order_id: "ff776045-513b-4cd7-8b4f-e60673daad84")
|
183
|
+
```
|
184
|
+
|
185
|
+
#### [Cancel](https://docs.tamara.co/reference/cancelorder)
|
186
|
+
|
187
|
+
```ruby
|
188
|
+
Tamara::Orders.cancel(
|
189
|
+
order_id: "abd12331-a123-1234-4567-fbde34ae",
|
190
|
+
total_amount: {
|
191
|
+
amount: 300,
|
192
|
+
currency: "SAR"
|
193
|
+
}
|
194
|
+
)
|
195
|
+
```
|
196
|
+
|
197
|
+
### Order Details
|
198
|
+
#### [Get Order Details by Tamara's order_id](https://docs.tamara.co/reference/getorderdetails)
|
199
|
+
|
200
|
+
```ruby
|
201
|
+
Tamara::Orders.get_by_tamara_order_id(order_id: "ff776045-513b-4cd7-8b4f-e60673daad84")
|
202
|
+
```
|
203
|
+
|
204
|
+
#### [Get Order Details by Merchant's order_reference_id](https://docs.tamara.co/reference/getorderdetailsbyrefid)
|
205
|
+
|
206
|
+
```ruby
|
207
|
+
Tamara::Orders.get_by_merchant_order_reference_id(order_id: "ff776045-513b-4cd7-8b4f-e60673daad84")
|
208
|
+
```
|
209
|
+
|
210
|
+
## Payments
|
211
|
+
#### [Capture](https://docs.tamara.co/reference/captureorder)
|
212
|
+
|
213
|
+
```ruby
|
214
|
+
Tamara::Payments.capture(
|
215
|
+
order_id: "ff776045-513b-4cd7-8b4f-e60673daad84",
|
216
|
+
total_amount: {
|
217
|
+
amount: 300,
|
218
|
+
currency: "SAR"
|
219
|
+
},
|
220
|
+
shipping_info: {
|
221
|
+
shipped_at: "2020-03-31T19:19:52.677Z",
|
222
|
+
shipping_company: "DHL",
|
223
|
+
tracking_number: "100",
|
224
|
+
tracking_url: "https://shipping.com/tracking?id=123456"
|
225
|
+
},
|
226
|
+
items: [
|
227
|
+
{
|
228
|
+
name: "Lego City 8601",
|
229
|
+
type: "Digital",
|
230
|
+
reference_id: "123",
|
231
|
+
sku: "SA-12436",
|
232
|
+
quantity: 1,
|
233
|
+
discount_amount: {
|
234
|
+
amount: 100,
|
235
|
+
currency: "SAR"
|
236
|
+
},
|
237
|
+
tax_amount: {
|
238
|
+
amount: 10,
|
239
|
+
currency: "SAR"
|
240
|
+
},
|
241
|
+
unit_price: {
|
242
|
+
amount: 490,
|
243
|
+
currency: "SAR"
|
244
|
+
},
|
245
|
+
total_amount: {
|
246
|
+
amount: 100,
|
247
|
+
currency: "SAR"
|
248
|
+
}
|
249
|
+
}
|
250
|
+
]
|
251
|
+
)
|
252
|
+
```
|
253
|
+
|
254
|
+
## Webhooks
|
255
|
+
### [Register Webhook](https://docs.tamara.co/reference/registerwebhookurl)
|
256
|
+
|
257
|
+
```ruby
|
258
|
+
Tamara::Webhooks.register(
|
259
|
+
type: "order",
|
260
|
+
events: [
|
261
|
+
"order_approved",
|
262
|
+
"order_authorised",
|
263
|
+
"order_canceled",
|
264
|
+
"order_updated",
|
265
|
+
"order_captured",
|
266
|
+
"order_refunded"
|
267
|
+
],
|
268
|
+
url: "https://www.enteryoursitehere.com/webhooks",
|
269
|
+
headers: {
|
270
|
+
authorization: "123344-1231-abcd-adfe-123456"
|
271
|
+
}
|
272
|
+
)
|
273
|
+
```
|
274
|
+
|
275
|
+
## Errors:
|
276
|
+
Errors could be one of the following:
|
277
|
+
|
278
|
+
```ruby
|
279
|
+
Tamara::AuthenticationError
|
280
|
+
Tamara::InvalidRequestError (With `param` attribute)
|
281
|
+
Tamara::APIError
|
282
|
+
```
|
283
|
+
|
284
|
+
## Contributing
|
285
|
+
|
286
|
+
Bug reports and pull requests are welcome.
|
287
|
+
|
288
|
+
## License
|
289
|
+
|
290
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
require "rake"
|
4
|
+
begin
|
5
|
+
require "bundler/setup"
|
6
|
+
Bundler::GemHelper.install_tasks
|
7
|
+
rescue LoadError
|
8
|
+
puts "although not required, bundler is recommended for running the tests"
|
9
|
+
end
|
10
|
+
|
11
|
+
task default: :spec
|
12
|
+
require "rspec/core/rake_task"
|
13
|
+
RSpec::Core::RakeTask.new(:spec)
|
14
|
+
|
15
|
+
require "rubocop/rake_task"
|
16
|
+
RuboCop::RakeTask.new do |task|
|
17
|
+
task.requires << "rubocop-performance"
|
18
|
+
task.requires << "rubocop-rspec"
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "rails/generators"
|
2
|
+
|
3
|
+
module Tamara
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
source_root File.expand_path("templates", __dir__)
|
7
|
+
|
8
|
+
desc "Creates a Tamara initializers file."
|
9
|
+
|
10
|
+
def copy_initializer
|
11
|
+
copy_file "tamara.rb", "config/initializers/tamara.rb"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Tamara
|
2
|
+
class ApiToken < ApplicationService
|
3
|
+
def self.verify(opts: {})
|
4
|
+
new(opts: opts).verify
|
5
|
+
end
|
6
|
+
|
7
|
+
def verify
|
8
|
+
result = Tamara::PaymentTypes.list(opts: @opts)
|
9
|
+
return failure(result.error) if result.failure?
|
10
|
+
|
11
|
+
success("API Token is valid")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Tamara
|
2
|
+
class ApplicationService
|
3
|
+
include Tamara::Request
|
4
|
+
|
5
|
+
Response = Struct.new(:success?, :payload, :error) do
|
6
|
+
def failure?
|
7
|
+
!success?
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(**params)
|
12
|
+
@params = params
|
13
|
+
@opts = params[:opts] || {}
|
14
|
+
end
|
15
|
+
|
16
|
+
def call
|
17
|
+
validate_params!
|
18
|
+
@response = call_api
|
19
|
+
handle_response_error
|
20
|
+
|
21
|
+
success(parsed_response)
|
22
|
+
rescue StandardError => e
|
23
|
+
failure(e)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def validate_params!
|
29
|
+
raise NotImplementedError, "Subclasses must implement validate_params!"
|
30
|
+
end
|
31
|
+
|
32
|
+
def call_api
|
33
|
+
raise NotImplementedError, "Subclasses must implement call_api"
|
34
|
+
end
|
35
|
+
|
36
|
+
def url
|
37
|
+
raise NotImplementedError, "Subclasses must implement url"
|
38
|
+
end
|
39
|
+
|
40
|
+
def success(payload = nil)
|
41
|
+
Response.new(true, payload)
|
42
|
+
end
|
43
|
+
|
44
|
+
def failure(exception)
|
45
|
+
Response.new(false, nil, exception)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Tamara
|
2
|
+
module Orders
|
3
|
+
class Authorize < ApplicationService
|
4
|
+
include Tamara::JsonSchemas::Validator
|
5
|
+
include Tamara::JsonSchemas::Types::Uuid
|
6
|
+
|
7
|
+
def self.call(order_id:, opts: {})
|
8
|
+
new(order_id: order_id, opts: opts).call
|
9
|
+
end
|
10
|
+
|
11
|
+
def call_api
|
12
|
+
::Faraday.post(url, {}.to_json, headers)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def url
|
18
|
+
"#{Tamara.orders_uri}/#{@params[:order_id]}/authorise"
|
19
|
+
end
|
20
|
+
|
21
|
+
def api_params
|
22
|
+
@api_params ||= @params[:order_id]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Tamara
|
2
|
+
module Orders
|
3
|
+
class Cancel < ApplicationService
|
4
|
+
include Tamara::JsonSchemas::Orders::Cancel
|
5
|
+
|
6
|
+
def self.call(order_id:, total_amount:, items: [], shipping_amount: nil, tax_amount: nil, discount_amount: nil, opts: {})
|
7
|
+
new(order_id: order_id,
|
8
|
+
total_amount: total_amount,
|
9
|
+
items: items,
|
10
|
+
shipping_amount: shipping_amount,
|
11
|
+
tax_amount: tax_amount,
|
12
|
+
discount_amount: discount_amount,
|
13
|
+
opts: opts).call
|
14
|
+
end
|
15
|
+
|
16
|
+
def call_api
|
17
|
+
::Faraday.post(url, api_params.to_json, headers)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def url
|
23
|
+
"#{Tamara.orders_uri}/#{@params[:order_id]}/cancel"
|
24
|
+
end
|
25
|
+
|
26
|
+
def api_params
|
27
|
+
@api_params ||= {
|
28
|
+
order_id: @params[:order_id],
|
29
|
+
total_amount: @params[:total_amount],
|
30
|
+
items: @params[:items],
|
31
|
+
shipping_amount: @params[:shipping_amount],
|
32
|
+
tax_amount: @params[:tax_amount],
|
33
|
+
discount_amount: @params[:discount_amount]
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Tamara
|
2
|
+
module Orders
|
3
|
+
class Create < ApplicationService
|
4
|
+
include Tamara::JsonSchemas::Orders::Create
|
5
|
+
|
6
|
+
# rubocop:disable Layout/LineLength
|
7
|
+
def self.call(order_reference_id:, country_code:, description:, total_amount:, shipping_amount:, tax_amount:, consumer:, items:, merchant_url:, shipping_address:, payment_type: "PAY_BY_INSTALMENTS", installments: 3, order_number: nil, discount: nil, billing_address: nil, platform: "", is_mobile: false, locale: "ar_SA", risk_assessment: nil, additional_data: nil, expires_in_minutes: 30, opts: {})
|
8
|
+
new(order_reference_id: order_reference_id,
|
9
|
+
country_code: country_code,
|
10
|
+
description: description,
|
11
|
+
total_amount: total_amount,
|
12
|
+
shipping_amount: shipping_amount,
|
13
|
+
tax_amount: tax_amount,
|
14
|
+
consumer: consumer,
|
15
|
+
items: items,
|
16
|
+
merchant_url: merchant_url,
|
17
|
+
shipping_address: shipping_address,
|
18
|
+
payment_type: payment_type,
|
19
|
+
installments: installments,
|
20
|
+
order_number: order_number,
|
21
|
+
discount: discount,
|
22
|
+
billing_address: billing_address,
|
23
|
+
platform: platform,
|
24
|
+
is_mobile: is_mobile,
|
25
|
+
locale: locale,
|
26
|
+
risk_assessment: risk_assessment,
|
27
|
+
additional_data: additional_data,
|
28
|
+
expires_in_minutes: expires_in_minutes,
|
29
|
+
opts: opts).call
|
30
|
+
end
|
31
|
+
# rubocop:enable Layout/LineLength
|
32
|
+
|
33
|
+
def call_api
|
34
|
+
::Faraday.post(url, api_params.to_json, headers)
|
35
|
+
end
|
36
|
+
|
37
|
+
def url
|
38
|
+
Tamara.checkout_uri
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
# rubocop:disable Metrics/AbcSize
|
44
|
+
def api_params
|
45
|
+
@api_params ||= {
|
46
|
+
order_reference_id: @params[:order_reference_id],
|
47
|
+
country_code: @params[:country_code],
|
48
|
+
description: @params[:description],
|
49
|
+
total_amount: @params[:total_amount],
|
50
|
+
shipping_amount: @params[:shipping_amount],
|
51
|
+
tax_amount: @params[:tax_amount],
|
52
|
+
consumer: @params[:consumer],
|
53
|
+
items: @params[:items],
|
54
|
+
merchant_url: @params[:merchant_url],
|
55
|
+
shipping_address: @params[:shipping_address],
|
56
|
+
payment_type: @params[:payment_type],
|
57
|
+
instalments: @params[:installments],
|
58
|
+
order_number: @params[:order_number],
|
59
|
+
discount: @params[:discount],
|
60
|
+
billing_address: @params[:billing_address],
|
61
|
+
platform: @params[:platform],
|
62
|
+
is_mobile: @params[:is_mobile],
|
63
|
+
locale: @params[:locale],
|
64
|
+
risk_assessment: @params[:risk_assessment],
|
65
|
+
additional_data: @params[:additional_data]
|
66
|
+
}
|
67
|
+
end
|
68
|
+
# rubocop:enable Metrics/AbcSize
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Tamara
|
2
|
+
module Orders
|
3
|
+
module Details
|
4
|
+
class MerchantOrder < ApplicationService
|
5
|
+
include Tamara::JsonSchemas::Validator
|
6
|
+
include Tamara::JsonSchemas::Types::String
|
7
|
+
|
8
|
+
def self.call(order_reference_id:, opts: {})
|
9
|
+
new(order_reference_id: order_reference_id, opts: opts).call
|
10
|
+
end
|
11
|
+
|
12
|
+
def call_api
|
13
|
+
::Faraday.get(url, {}, headers)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def url
|
19
|
+
"#{Tamara.base_uri}/merchants/orders/reference-id/#{@params[:order_reference_id]}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def api_params
|
23
|
+
@api_params ||= @params[:order_reference_id]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Tamara
|
2
|
+
module Orders
|
3
|
+
module Details
|
4
|
+
class TamaraOrder < ApplicationService
|
5
|
+
include Tamara::JsonSchemas::Validator
|
6
|
+
include Tamara::JsonSchemas::Types::Uuid
|
7
|
+
|
8
|
+
def self.call(order_id:, opts: {})
|
9
|
+
new(order_id: order_id, opts: opts).call
|
10
|
+
end
|
11
|
+
|
12
|
+
def call_api
|
13
|
+
::Faraday.get(url, {}, headers)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def url
|
19
|
+
"#{Tamara.orders_uri}/#{@params[:order_id]}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def api_params
|
23
|
+
@api_params ||= @params[:order_id]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Tamara
|
2
|
+
module Orders
|
3
|
+
def self.get_by_tamara_order_id(order_id:, opts: {})
|
4
|
+
Tamara::Orders::Details::TamaraOrder.call(order_id: order_id, opts: opts)
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.get_by_merchant_order_reference_id(order_reference_id:, opts: {})
|
8
|
+
Tamara::Orders::Details::MerchantOrder.call(order_reference_id: order_reference_id, opts: opts)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.authorize(order_id:, opts: {})
|
12
|
+
Tamara::Orders::Authorize.call(order_id: order_id, opts: opts)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.cancel(order_id:, total_amount:, items: [], shipping_amount: nil, tax_amount: nil, discount_amount: nil, opts: {})
|
16
|
+
Tamara::Orders::Cancel.call(
|
17
|
+
order_id: order_id,
|
18
|
+
total_amount: total_amount,
|
19
|
+
shipping_amount: shipping_amount,
|
20
|
+
tax_amount: tax_amount,
|
21
|
+
discount_amount: discount_amount,
|
22
|
+
items: items,
|
23
|
+
opts: opts
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
# rubocop:disable Layout/LineLength
|
28
|
+
def self.create(order_reference_id:, country_code:, description:, total_amount:, shipping_amount:, tax_amount:, consumer:, items:, merchant_url:, shipping_address:, payment_type: "PAY_BY_INSTALMENTS", installments: 3, order_number: nil, discount: nil, billing_address: nil, platform: "", is_mobile: false, locale: "ar_SA", risk_assessment: nil, additional_data: nil, expires_in_minutes: 30, opts: {})
|
29
|
+
Tamara::Orders::Create.call(
|
30
|
+
order_reference_id: order_reference_id,
|
31
|
+
country_code: country_code,
|
32
|
+
description: description,
|
33
|
+
total_amount: total_amount,
|
34
|
+
shipping_amount: shipping_amount,
|
35
|
+
tax_amount: tax_amount,
|
36
|
+
consumer: consumer,
|
37
|
+
items: items,
|
38
|
+
merchant_url: merchant_url,
|
39
|
+
shipping_address: shipping_address,
|
40
|
+
payment_type: payment_type,
|
41
|
+
installments: installments,
|
42
|
+
order_number: order_number,
|
43
|
+
discount: discount,
|
44
|
+
billing_address: billing_address,
|
45
|
+
platform: platform,
|
46
|
+
is_mobile: is_mobile,
|
47
|
+
locale: locale,
|
48
|
+
risk_assessment: risk_assessment,
|
49
|
+
additional_data: additional_data,
|
50
|
+
expires_in_minutes: expires_in_minutes,
|
51
|
+
opts: opts
|
52
|
+
)
|
53
|
+
end
|
54
|
+
# rubocop:enable Layout/LineLength
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Tamara
|
2
|
+
module PaymentOptions
|
3
|
+
class Check < ApplicationService
|
4
|
+
include Tamara::JsonSchemas::PaymentOptions::Check
|
5
|
+
|
6
|
+
def self.call(country:, phone_number:, order_value:, is_vip: false, opts: {})
|
7
|
+
new(country: country,
|
8
|
+
phone_number: phone_number,
|
9
|
+
order_value: order_value,
|
10
|
+
is_vip: is_vip,
|
11
|
+
opts: opts).call
|
12
|
+
end
|
13
|
+
|
14
|
+
def call_api
|
15
|
+
::Faraday.post(url, api_params.to_json, headers)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def url
|
21
|
+
"#{Tamara.checkout_uri}/payment-options-pre-check"
|
22
|
+
end
|
23
|
+
|
24
|
+
def api_params
|
25
|
+
@api_params ||= {
|
26
|
+
country: @params[:country],
|
27
|
+
phone_number: @params[:phone_number],
|
28
|
+
order_value: @params[:order_value],
|
29
|
+
is_vip: @params[:is_vip]
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Tamara
|
2
|
+
module PaymentOptions
|
3
|
+
def self.check(country:, phone_number:, order_value:, is_vip: false, opts: {})
|
4
|
+
Tamara::PaymentOptions::Check.call(
|
5
|
+
country: country,
|
6
|
+
phone_number: phone_number,
|
7
|
+
order_value: order_value,
|
8
|
+
is_vip: is_vip,
|
9
|
+
opts: opts
|
10
|
+
)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|