smartpay 0.2.13 → 0.2.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +13 -13
- data/lib/generators/smartpay/templates/initializer.rb +0 -2
- data/lib/smartpay/api.rb +13 -13
- data/lib/smartpay/client.rb +45 -44
- data/lib/smartpay/configuration.rb +48 -30
- data/lib/smartpay/requests/checkout_session.rb +209 -194
- data/lib/smartpay/responses/checkout_session.rb +40 -35
- data/lib/smartpay/version.rb +1 -1
- data/lib/smartpay.rb +25 -25
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d28befc09bec0649be0542e440f1acbcde630f38984e375986809f94a9bedec
|
4
|
+
data.tar.gz: 7888dac202c056b57e476039d731a3b297833eacde05b98631300d0de1258270
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c7fe94acaa28d87d3568c3e5fedc49fb61ae7ab85b401fbbbf985bda50664620c5afa8a194d6f7cb2d503fe8f7298bb782cdd7cd067a8a106e1b48d928578a0
|
7
|
+
data.tar.gz: cb754e4460b339788a8cec5e688b08725dfb684156651539cf005b4b8dbe6950d5ffb22f852c0ec6035496a40d8194d80d81b6cbc44c6b10ddc2cb3a2874817f
|
data/.rubocop.yml
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
AllCops:
|
2
|
-
TargetRubyVersion: 2.
|
3
|
-
|
4
|
-
Style/StringLiterals:
|
5
|
-
Enabled: true
|
6
|
-
EnforcedStyle: double_quotes
|
7
|
-
|
8
|
-
Style/StringLiteralsInInterpolation:
|
9
|
-
Enabled: true
|
10
|
-
EnforcedStyle: double_quotes
|
11
|
-
|
12
|
-
Layout/LineLength:
|
13
|
-
Max: 120
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.5
|
3
|
+
|
4
|
+
Style/StringLiterals:
|
5
|
+
Enabled: true
|
6
|
+
EnforcedStyle: double_quotes
|
7
|
+
|
8
|
+
Style/StringLiteralsInInterpolation:
|
9
|
+
Enabled: true
|
10
|
+
EnforcedStyle: double_quotes
|
11
|
+
|
12
|
+
Layout/LineLength:
|
13
|
+
Max: 120
|
data/lib/smartpay/api.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Smartpay
|
4
|
-
class Api
|
5
|
-
class << self
|
6
|
-
def create_checkout_session(payload)
|
7
|
-
Responses::CheckoutSession.new(
|
8
|
-
Client.post(
|
9
|
-
)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Smartpay
|
4
|
+
class Api
|
5
|
+
class << self
|
6
|
+
def create_checkout_session(payload)
|
7
|
+
Responses::CheckoutSession.new(
|
8
|
+
Client.post("/checkout-sessions", Requests::CheckoutSession.new(payload).as_hash)
|
9
|
+
)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/smartpay/client.rb
CHANGED
@@ -1,44 +1,45 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require
|
4
|
-
|
5
|
-
module Smartpay
|
6
|
-
class Client
|
7
|
-
class << self
|
8
|
-
def post(path, payload = {})
|
9
|
-
request_payload = default_payload.merge(payload)
|
10
|
-
response = RestClient::Request.execute(method: :post, url: api_url(path), headers: headers, timeout: timeout,
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
'
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rest-client"
|
4
|
+
|
5
|
+
module Smartpay
|
6
|
+
class Client
|
7
|
+
class << self
|
8
|
+
def post(path, payload = {})
|
9
|
+
request_payload = default_payload.merge(payload)
|
10
|
+
response = RestClient::Request.execute(method: :post, url: api_url(path), headers: headers, timeout: timeout,
|
11
|
+
payload: request_payload.to_json)
|
12
|
+
JSON.parse(response.body, symbolize_names: true)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def api_url(path)
|
18
|
+
"#{Smartpay.configuration.api_url}#{path}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def timeout
|
22
|
+
Smartpay.configuration.post_timeout
|
23
|
+
end
|
24
|
+
|
25
|
+
def headers
|
26
|
+
{
|
27
|
+
accept: :json,
|
28
|
+
content_type: :json,
|
29
|
+
Authorization: "Basic #{secret_key}"
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def secret_key
|
34
|
+
Smartpay.configuration.secret_key
|
35
|
+
end
|
36
|
+
|
37
|
+
def default_payload
|
38
|
+
{
|
39
|
+
'dev-lang': :ruby,
|
40
|
+
'sdk-version': Smartpay::VERSION
|
41
|
+
}.freeze
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -1,30 +1,48 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Smartpay
|
4
|
-
class Configuration
|
5
|
-
attr_accessor :public_key, :secret_key
|
6
|
-
attr_writer :post_timeout, :api_url, :checkout_url
|
7
|
-
|
8
|
-
DEFAULT_TIMEOUT_SETTING = 30
|
9
|
-
DEFAULT_API_URL =
|
10
|
-
DEFAULT_CHECKOUT_URL =
|
11
|
-
|
12
|
-
def initialize
|
13
|
-
@post_timeout = DEFAULT_TIMEOUT_SETTING
|
14
|
-
@api_url =
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
@
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
def
|
27
|
-
@
|
28
|
-
end
|
29
|
-
|
30
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Smartpay
|
4
|
+
class Configuration
|
5
|
+
attr_accessor :public_key, :secret_key
|
6
|
+
attr_writer :post_timeout, :api_url, :checkout_url
|
7
|
+
|
8
|
+
DEFAULT_TIMEOUT_SETTING = 30
|
9
|
+
DEFAULT_API_URL = "https://api.smartpay.co/v1"
|
10
|
+
DEFAULT_CHECKOUT_URL = "https://checkout.smartpay.co"
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@post_timeout = DEFAULT_TIMEOUT_SETTING
|
14
|
+
@api_url = if in_development_mode?
|
15
|
+
ENV["SMARTPAY_API_PREFIX"].downcase || DEFAULT_API_URL
|
16
|
+
else
|
17
|
+
DEFAULT_API_URL
|
18
|
+
end
|
19
|
+
@checkout_url = if in_development_mode? && ENV["SMARTPAY_CHECKOUT_URL"].is_a?(String)
|
20
|
+
ENV["SMARTPAY_CHECKOUT_URL"].downcase || DEFAULT_CHECKOUT_URL
|
21
|
+
else
|
22
|
+
DEFAULT_CHECKOUT_URL
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def post_timeout
|
27
|
+
@post_timeout || DEFAULT_TIMEOUT_SETTING
|
28
|
+
end
|
29
|
+
|
30
|
+
def api_url
|
31
|
+
if in_development_mode?
|
32
|
+
@api_url || ENV["SMARTPAY_API_PREFIX"].downcase || DEFAULT_API_URL
|
33
|
+
else
|
34
|
+
@api_url || DEFAULT_API_URL
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def checkout_url
|
39
|
+
@checkout_url || DEFAULT_CHECKOUT_URL
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def in_development_mode?
|
45
|
+
ENV["SMARTPAY_API_PREFIX"].downcase.include?("api.smartpay") if ENV["SMARTPAY_API_PREFIX"].is_a?(String)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -1,194 +1,209 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Smartpay
|
4
|
-
module Requests
|
5
|
-
class CheckoutSession
|
6
|
-
attr_accessor :payload
|
7
|
-
|
8
|
-
REQUIREMENT_KEY_NAME = [:successURL, :cancelURL, :customerInfo, :orderData].freeze
|
9
|
-
CAN_FALLBACK_KEYS = [:customerInfo, :orderData].freeze
|
10
|
-
|
11
|
-
def initialize(raw_payload)
|
12
|
-
@payload = raw_payload.transform_keys(&:to_sym)
|
13
|
-
end
|
14
|
-
|
15
|
-
def as_hash
|
16
|
-
check_requirement!
|
17
|
-
normalize_payload
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def check_requirement!
|
23
|
-
REQUIREMENT_KEY_NAME.each do |key_name|
|
24
|
-
next if CAN_FALLBACK_KEYS.include?(key_name)
|
25
|
-
raise Errors::InvalidRequestPayloadError, key_name unless payload.include?(key_name)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def normalize_payload
|
30
|
-
currency = get_currency
|
31
|
-
total_amount = get_total_amount
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
total_amount
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Smartpay
|
4
|
+
module Requests
|
5
|
+
class CheckoutSession
|
6
|
+
attr_accessor :payload
|
7
|
+
|
8
|
+
REQUIREMENT_KEY_NAME = [:successURL, :cancelURL, :customerInfo, :orderData].freeze
|
9
|
+
CAN_FALLBACK_KEYS = [:customerInfo, :orderData].freeze
|
10
|
+
|
11
|
+
def initialize(raw_payload)
|
12
|
+
@payload = raw_payload.transform_keys(&:to_sym)
|
13
|
+
end
|
14
|
+
|
15
|
+
def as_hash
|
16
|
+
check_requirement!
|
17
|
+
normalize_payload
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def check_requirement!
|
23
|
+
REQUIREMENT_KEY_NAME.each do |key_name|
|
24
|
+
next if CAN_FALLBACK_KEYS.include?(key_name)
|
25
|
+
raise Errors::InvalidRequestPayloadError, key_name unless payload.include?(key_name)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def normalize_payload
|
30
|
+
currency = get_currency
|
31
|
+
total_amount = get_total_amount
|
32
|
+
shippingInfo = payload.dig(:shippingInfo) || normalize_shipping(payload.dig(:shipping))
|
33
|
+
shippingInfo[:feeCurrency] = currency if shippingInfo && shippingInfo[:feeCurrency].nil? && !(shippingInfo[:feeAmount].nil?)
|
34
|
+
|
35
|
+
{
|
36
|
+
customerInfo: normalize_customer_info(payload.dig(:customerInfo) || payload.dig(:customer) || {}),
|
37
|
+
orderData: normalize_order_data(payload.dig(:orderData) || {
|
38
|
+
amount: total_amount,
|
39
|
+
currency: currency,
|
40
|
+
captureMethod: payload.dig(:captureMethod),
|
41
|
+
confirmationMethod: payload.dig(:confirmationMethod),
|
42
|
+
coupons: payload.dig(:coupons),
|
43
|
+
shippingInfo: shippingInfo,
|
44
|
+
lineItemData: payload.dig(:orderData, :lineItemData) || payload.dig(:items),
|
45
|
+
description: payload.dig(:orderDescription),
|
46
|
+
metadata: payload.dig(:orderMetadata),
|
47
|
+
reference: payload.dig(:reference),
|
48
|
+
}),
|
49
|
+
successUrl: payload.dig(:successURL),
|
50
|
+
cancelUrl: payload.dig(:cancelURL),
|
51
|
+
test: payload.dig(:test) || false
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
def normalize_customer_info(info)
|
56
|
+
return if info.nil?
|
57
|
+
customer = info.transform_keys(&:to_sym)
|
58
|
+
{
|
59
|
+
accountAge: customer.dig(:accountAge),
|
60
|
+
emailAddress: customer.dig(:emailAddress) || customer.dig(:email),
|
61
|
+
firstName: customer.dig(:firstName),
|
62
|
+
lastName: customer.dig(:lastName),
|
63
|
+
firstNameKana: customer.dig(:firstNameKana),
|
64
|
+
lastNameKana: customer.dig(:lastNameKana),
|
65
|
+
address: customer.dig(:address),
|
66
|
+
phoneNumber: customer.dig(:phoneNumber) || customer.dig(:phone),
|
67
|
+
dateOfBirth: customer.dig(:dateOfBirth),
|
68
|
+
legalGender: customer.dig(:legalGender) || customer.dig(:gender),
|
69
|
+
reference: customer.dig(:reference)
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
def normalize_shipping(shipping)
|
74
|
+
return if shipping.nil?
|
75
|
+
shipping= shipping.transform_keys(&:to_sym)
|
76
|
+
{
|
77
|
+
address: shipping.dig(:address) || {
|
78
|
+
line1: shipping.dig(:line1),
|
79
|
+
line2: shipping.dig(:line2),
|
80
|
+
line3: shipping.dig(:line3),
|
81
|
+
line4: shipping.dig(:line4),
|
82
|
+
line5: shipping.dig(:line5),
|
83
|
+
subLocality: shipping.dig(:subLocality),
|
84
|
+
locality: shipping.dig(:locality),
|
85
|
+
administrativeArea: shipping.dig(:administrativeArea),
|
86
|
+
postalCode: shipping.dig(:postalCode),
|
87
|
+
country: shipping.dig(:country),
|
88
|
+
},
|
89
|
+
addressType: shipping.dig(:addressType),
|
90
|
+
feeAmount: shipping.dig(:feeAmount),
|
91
|
+
feeCurrency: shipping.dig(:feeCurrency),
|
92
|
+
}
|
93
|
+
end
|
94
|
+
|
95
|
+
def normalize_order_data(order)
|
96
|
+
return if order.nil?
|
97
|
+
order = order.transform_keys(&:to_sym)
|
98
|
+
{
|
99
|
+
amount: order.dig(:amount),
|
100
|
+
currency: order.dig(:currency),
|
101
|
+
captureMethod: order.dig(:captureMethod),
|
102
|
+
confirmationMethod: order.dig(:confirmationMethod),
|
103
|
+
coupons: order.dig(:coupons),
|
104
|
+
shippingInfo: order.dig(:shippingInfo),
|
105
|
+
lineItemData: normalize_line_items(order.dig(:lineItemData) || order.dig(:items)),
|
106
|
+
metadata: order.dig(:metadata) || {},
|
107
|
+
reference: order.dig(:reference)
|
108
|
+
}
|
109
|
+
end
|
110
|
+
|
111
|
+
def normalize_line_items(data)
|
112
|
+
return [] if data.nil?
|
113
|
+
|
114
|
+
data.map do |item|
|
115
|
+
line_item = item.transform_keys(&:to_sym)
|
116
|
+
{
|
117
|
+
price: line_item.dig(:price),
|
118
|
+
priceData: normalize_price_data(line_item.dig(:priceData) || {
|
119
|
+
productData: {
|
120
|
+
name: line_item.dig(:name),
|
121
|
+
brand: line_item.dig(:brand),
|
122
|
+
categories: line_item.dig(:categories),
|
123
|
+
gtin: line_item.dig(:gtin),
|
124
|
+
images: line_item.dig(:images),
|
125
|
+
reference: line_item.dig(:reference),
|
126
|
+
url: line_item.dig(:url),
|
127
|
+
description: line_item.dig(:productDescription),
|
128
|
+
metadata: line_item.dig(:productMetadata)
|
129
|
+
},
|
130
|
+
amount: line_item.dig(:amount),
|
131
|
+
currency: line_item.dig(:currency),
|
132
|
+
label: line_item.dig(:label),
|
133
|
+
description: line_item.dig(:priceDescription),
|
134
|
+
metadata: line_item.dig(:priceMetadata)
|
135
|
+
}),
|
136
|
+
quantity: line_item.dig(:quantity),
|
137
|
+
description: line_item.dig(:description),
|
138
|
+
metadata: line_item.dig(:metadata)
|
139
|
+
}
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def normalize_price_data(data)
|
144
|
+
return if data.nil?
|
145
|
+
data = data.transform_keys(&:to_sym)
|
146
|
+
{
|
147
|
+
productData: normalize_product_data(data.dig(:productData) || {}),
|
148
|
+
amount: data.dig(:amount),
|
149
|
+
currency: data.dig(:currency),
|
150
|
+
metadata: data.dig(:metadata)
|
151
|
+
}
|
152
|
+
end
|
153
|
+
|
154
|
+
def normalize_product_data(product)
|
155
|
+
return if product.nil?
|
156
|
+
product = product.transform_keys(&:to_sym)
|
157
|
+
{
|
158
|
+
name: product.dig(:name),
|
159
|
+
brand: product.dig(:brand),
|
160
|
+
categories: product.dig(:categories),
|
161
|
+
description: product.dig(:description),
|
162
|
+
gtin: product.dig(:gtin),
|
163
|
+
images: product.dig(:images),
|
164
|
+
reference: product.dig(:reference),
|
165
|
+
url: product.dig(:url),
|
166
|
+
metadata: product.dig(:metadata)
|
167
|
+
}
|
168
|
+
end
|
169
|
+
|
170
|
+
def get_currency
|
171
|
+
currency = payload.dig(:orderData, :currency) || payload.dig(:orderData, 'currency')
|
172
|
+
if currency.nil?
|
173
|
+
items = get_items
|
174
|
+
if !items.nil? && items.count > 0
|
175
|
+
currency = items.first.dig(:currency) || items.first.dig('currency')
|
176
|
+
end
|
177
|
+
end
|
178
|
+
currency
|
179
|
+
end
|
180
|
+
|
181
|
+
def get_total_amount
|
182
|
+
total_amount = payload.dig(:orderData, :amount) || payload.dig(:orderData, 'amount')
|
183
|
+
|
184
|
+
if total_amount.nil?
|
185
|
+
items = get_items
|
186
|
+
|
187
|
+
if !items.nil? && items.count > 0
|
188
|
+
total_amount = items.inject(0) { |sum, item| sum + (item[:amount] || item['amount'] || 0) }
|
189
|
+
end
|
190
|
+
|
191
|
+
shipping_fee = payload.dig(:orderData, :shippingInfo, :feeAmount) ||
|
192
|
+
payload.dig(:orderData, :shippingInfo, 'feeAmount') ||
|
193
|
+
payload.dig(:shipping, :feeAmount) ||
|
194
|
+
payload.dig(:shipping, 'feeAmount') ||
|
195
|
+
0
|
196
|
+
total_amount = shipping_fee + (total_amount || 0)
|
197
|
+
end
|
198
|
+
|
199
|
+
total_amount
|
200
|
+
end
|
201
|
+
|
202
|
+
def get_items
|
203
|
+
@items ||= payload.dig(:orderData, :lineItemData, :priceData) ||
|
204
|
+
payload.dig(:orderData, 'lineItemData', 'priceData') ||
|
205
|
+
payload.dig(:items)
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
@@ -1,35 +1,40 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Smartpay
|
4
|
-
module Responses
|
5
|
-
class CheckoutSession
|
6
|
-
attr_reader :response
|
7
|
-
|
8
|
-
def initialize(response)
|
9
|
-
@response = response
|
10
|
-
end
|
11
|
-
|
12
|
-
def redirect_url
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Smartpay
|
4
|
+
module Responses
|
5
|
+
class CheckoutSession
|
6
|
+
attr_reader :response
|
7
|
+
|
8
|
+
def initialize(response)
|
9
|
+
@response = response
|
10
|
+
end
|
11
|
+
|
12
|
+
def redirect_url(options = {})
|
13
|
+
url = "#{checkout_url}/login"
|
14
|
+
promotion_code = options[:promotion_code] || response[:metadata][:__promotion_code__] || nil
|
15
|
+
qs = "session-id=#{URI.encode_www_form_component(response[:id])}&public-key=#{URI.encode_www_form_component(public_key)}"
|
16
|
+
qs = "#{qs}&promotion-code=#{URI.encode_www_form_component(promotion_code)}" if promotion_code
|
17
|
+
|
18
|
+
"#{url}?#{qs}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def as_hash
|
22
|
+
@response
|
23
|
+
end
|
24
|
+
|
25
|
+
def as_json
|
26
|
+
@response.to_json
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def checkout_url
|
32
|
+
Smartpay.configuration.checkout_url
|
33
|
+
end
|
34
|
+
|
35
|
+
def public_key
|
36
|
+
Smartpay.configuration.public_key
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/smartpay/version.rb
CHANGED
data/lib/smartpay.rb
CHANGED
@@ -1,25 +1,25 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require
|
4
|
-
|
5
|
-
require_relative "smartpay/version"
|
6
|
-
require_relative
|
7
|
-
require_relative
|
8
|
-
require_relative
|
9
|
-
require_relative
|
10
|
-
require_relative
|
11
|
-
require_relative
|
12
|
-
|
13
|
-
module Smartpay
|
14
|
-
class << self
|
15
|
-
attr_accessor :configuration
|
16
|
-
|
17
|
-
def configuration
|
18
|
-
@configuration ||= Smartpay::Configuration.new
|
19
|
-
end
|
20
|
-
|
21
|
-
def configure
|
22
|
-
yield(configuration)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "json"
|
4
|
+
|
5
|
+
require_relative "smartpay/version"
|
6
|
+
require_relative "smartpay/configuration"
|
7
|
+
require_relative "smartpay/client"
|
8
|
+
require_relative "smartpay/api"
|
9
|
+
require_relative "smartpay/errors/invalid_request_payload_error"
|
10
|
+
require_relative "smartpay/requests/checkout_session"
|
11
|
+
require_relative "smartpay/responses/checkout_session"
|
12
|
+
|
13
|
+
module Smartpay
|
14
|
+
class << self
|
15
|
+
attr_accessor :configuration
|
16
|
+
|
17
|
+
def configuration
|
18
|
+
@configuration ||= Smartpay::Configuration.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def configure
|
22
|
+
yield(configuration)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smartpay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Smartpay
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|