smartpay 0.2.17 → 0.2.18
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 +4 -4
- data/README.md +181 -181
- data/lib/smartpay/requests/checkout_session.rb +31 -120
- data/lib/smartpay/version.rb +1 -1
- 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: 3897098e68300e9004b822ba8f797040b02c00362428cee023ba598415bd4a54
|
4
|
+
data.tar.gz: dd42d0ad91f798d88fd765270975e9d61dde01cd3b52143c0d762bb1577f71b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05df4d994fd49a80bd58d56bd58469639aa0ad50f7688d874cce1b412e8366fe5afb82acf6082c00e40b3b0a7491bba4a7242117e65ab22e8fd326cbd0b9e65a
|
7
|
+
data.tar.gz: ed67c91a5e4f43991a362d77c2c2ac4f430265c14f3c236941c26f482a162683bdddbc10700e82344b9b923c698bbbd9126cd8c1cb7975bc1506807de2888a80
|
data/README.md
CHANGED
@@ -1,181 +1,181 @@
|
|
1
|
-
# Smartpay Ruby Library
|
2
|
-
|
3
|
-
The Smartpay Ruby library offers easy access to Smartpay API from applications written in Ruby.
|
4
|
-
|
5
|
-
## Documentation
|
6
|
-
|
7
|
-
- [Payment Flow](https://docs.smartpay.co/#payment_flow)
|
8
|
-
- [API Document](https://api-doc.smartpay.co)
|
9
|
-
|
10
|
-
## Requirements
|
11
|
-
|
12
|
-
- Ruby 2.6+
|
13
|
-
- Smartpay `API keys & secrets`. You can find your credential at the `settings > credentials` page on your [dashboard](https://dashboard.smartpay.co/settings/credentials).
|
14
|
-
|
15
|
-
## Installation
|
16
|
-
|
17
|
-
If you use system built-in Ruby, you might need to be the `sudoer` to be able to `sudo` in some of the following steps. We recommend you to use either [rbenv](https://github.com/rbenv/rbenv) or [rvm](https://rvm.io/) to have your own non-global Ruby to avoid potential permission issues.
|
18
|
-
|
19
|
-
Once you have your Ruby in place, add the latest version of Smartpay to your project's dependencies:
|
20
|
-
|
21
|
-
```sh
|
22
|
-
gem install smartpay
|
23
|
-
```
|
24
|
-
|
25
|
-
If you want to build the gem yourself from source:
|
26
|
-
|
27
|
-
```sh
|
28
|
-
gem build smartpay.gemspec
|
29
|
-
```
|
30
|
-
|
31
|
-
### Bundler
|
32
|
-
|
33
|
-
If you are installing via bundler, make sure that you use the `https` resource in your Gemfile to avoid the risk of gems being compromised:
|
34
|
-
|
35
|
-
```ruby
|
36
|
-
source 'https://rubygems.org'
|
37
|
-
|
38
|
-
gem 'smartpay'
|
39
|
-
```
|
40
|
-
|
41
|
-
## Usage
|
42
|
-
|
43
|
-
The package needs to be configured with your own API keys, you can find them on your [dashboard](https://dashboard.smartpay.co/settings/credentials).
|
44
|
-
|
45
|
-
```ruby
|
46
|
-
Smartpay.configure do |config|
|
47
|
-
config.public_key = '<YOUR_PUBLIC_KEY>' # the one starts with pk_test_
|
48
|
-
config.secret_key = '<YOUR_SECRET_KEY>' # the one starts with sk_test_
|
49
|
-
end
|
50
|
-
```
|
51
|
-
|
52
|
-
### Create Checkout session
|
53
|
-
|
54
|
-
You can find the description and requirement for request payload in [API Document](https://api-doc.smartpay.co/#8a3538b1-530c-448c-8bae-4a41cdf0b8fd).
|
55
|
-
|
56
|
-
```ruby
|
57
|
-
payloaad = {
|
58
|
-
"customerInfo": {
|
59
|
-
"emailAddress": "success@smartpay.co",
|
60
|
-
},
|
61
|
-
"orderData": {
|
62
|
-
"amount": 250,
|
63
|
-
"currency": "JPY",
|
64
|
-
"shippingInfo": {
|
65
|
-
"address": {
|
66
|
-
"line1": "line1",
|
67
|
-
"locality": "locality",
|
68
|
-
"postalCode": "123",
|
69
|
-
"country": "JP"
|
70
|
-
},
|
71
|
-
},
|
72
|
-
"lineItemData": [{
|
73
|
-
"priceData": {
|
74
|
-
"productData": {
|
75
|
-
"name": "レブロン 18 LOW",
|
76
|
-
},
|
77
|
-
"amount": 250,
|
78
|
-
"currency": "JPY",
|
79
|
-
},
|
80
|
-
"quantity": 1
|
81
|
-
}]
|
82
|
-
},
|
83
|
-
"reference": "order_ref_1234567",
|
84
|
-
"successUrl": "https://docs.smartpay.co/example-pages/checkout-successful",
|
85
|
-
"cancelUrl": "https://docs.smartpay.co/example-pages/checkout-canceled"
|
86
|
-
}
|
87
|
-
```
|
88
|
-
|
89
|
-
Create a checkout session by using `Smartpay::Api.create_checkout_session` with your request payload.
|
90
|
-
|
91
|
-
```ruby
|
92
|
-
session = Smartpay::Api.create_checkout_session(payload)
|
93
|
-
```
|
94
|
-
|
95
|
-
Then, you can redirect your customer to the session url by calling `redirect_url`:
|
96
|
-
|
97
|
-
```ruby
|
98
|
-
session.redirect_url
|
99
|
-
```
|
100
|
-
|
101
|
-
## Use with your favorite frameworks
|
102
|
-
|
103
|
-
### Ruby on Rails (RoR)
|
104
|
-
|
105
|
-
#### Install Rails
|
106
|
-
|
107
|
-
```sh
|
108
|
-
gem install rails
|
109
|
-
```
|
110
|
-
|
111
|
-
#### Create your app
|
112
|
-
|
113
|
-
```sh
|
114
|
-
rails new app-with-smartpay
|
115
|
-
```
|
116
|
-
|
117
|
-
#### Add Smartpay
|
118
|
-
|
119
|
-
```sh
|
120
|
-
cd app-with-smartpay
|
121
|
-
bundle add smartpay
|
122
|
-
```
|
123
|
-
|
124
|
-
#### Generator
|
125
|
-
|
126
|
-
```sh
|
127
|
-
bundle exec rails generate smartpay:install
|
128
|
-
```
|
129
|
-
|
130
|
-
This introduces 4 changes for a pre-built Smartpay Checkout example:
|
131
|
-
|
132
|
-
> 1. A new initializer - `config/initializers/smartpay.rb`. You will have to update the `config.public_key` and `config.secret_key` with your own credentials to make this work.
|
133
|
-
> 2. A new controller - `app/controllers/smartpays_controller.rb`. This is where you can see how a Checkout session is configured & created.
|
134
|
-
> 3. A new view - `app/views/smartpays/index.html.erb`. The minimum frontend required.
|
135
|
-
> 4. A new route in config/routes.rb.
|
136
|
-
|
137
|
-
#### Fill in your API keys
|
138
|
-
|
139
|
-
Edit the keys with your own credentials in `config/initializers/smartpay.rb`.
|
140
|
-
|
141
|
-
```ruby
|
142
|
-
...
|
143
|
-
config.public_key = '<YOUR_PUBLIC_KEY>' # the one starts with pk_test_
|
144
|
-
config.secret_key = '<YOUR_SECRET_KEY>' # the one starts with sk_test_
|
145
|
-
...
|
146
|
-
```
|
147
|
-
|
148
|
-
#### Start your server
|
149
|
-
|
150
|
-
```sh
|
151
|
-
bundle exec rails server
|
152
|
-
```
|
153
|
-
|
154
|
-
### Test with Checkout Session
|
155
|
-
|
156
|
-
Visit [http://localhost:3000/smartpays](http://localhost:3000/smartpays).
|
157
|
-
|
158
|
-
Click the `checkout` button on the page to be redirected to Smartpay's Checkout.
|
159
|
-
|
160
|
-
To try out different cases, you can use the following test credit cards for different cases:
|
161
|
-
|
162
|
-
- Payment succeeds: `4242 4242 4242 4242`
|
163
|
-
- Payment is declined: `4100 0000 0000 0019`
|
164
|
-
|
165
|
-
## Development
|
166
|
-
|
167
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
168
|
-
|
169
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
170
|
-
|
171
|
-
## Contributing
|
172
|
-
|
173
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/smartpay. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/smartpay/blob/master/CODE_OF_CONDUCT.md).
|
174
|
-
|
175
|
-
## License
|
176
|
-
|
177
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
178
|
-
|
179
|
-
## Code of Conduct
|
180
|
-
|
181
|
-
Everyone interacting in the Smartpay project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/smartpay/blob/master/CODE_OF_CONDUCT.md).
|
1
|
+
# Smartpay Ruby Library
|
2
|
+
|
3
|
+
The Smartpay Ruby library offers easy access to Smartpay API from applications written in Ruby.
|
4
|
+
|
5
|
+
## Documentation
|
6
|
+
|
7
|
+
- [Payment Flow](https://docs.smartpay.co/#payment_flow)
|
8
|
+
- [API Document](https://api-doc.smartpay.co)
|
9
|
+
|
10
|
+
## Requirements
|
11
|
+
|
12
|
+
- Ruby 2.6+
|
13
|
+
- Smartpay `API keys & secrets`. You can find your credential at the `settings > credentials` page on your [dashboard](https://dashboard.smartpay.co/settings/credentials).
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
If you use system built-in Ruby, you might need to be the `sudoer` to be able to `sudo` in some of the following steps. We recommend you to use either [rbenv](https://github.com/rbenv/rbenv) or [rvm](https://rvm.io/) to have your own non-global Ruby to avoid potential permission issues.
|
18
|
+
|
19
|
+
Once you have your Ruby in place, add the latest version of Smartpay to your project's dependencies:
|
20
|
+
|
21
|
+
```sh
|
22
|
+
gem install smartpay
|
23
|
+
```
|
24
|
+
|
25
|
+
If you want to build the gem yourself from source:
|
26
|
+
|
27
|
+
```sh
|
28
|
+
gem build smartpay.gemspec
|
29
|
+
```
|
30
|
+
|
31
|
+
### Bundler
|
32
|
+
|
33
|
+
If you are installing via bundler, make sure that you use the `https` resource in your Gemfile to avoid the risk of gems being compromised:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
source 'https://rubygems.org'
|
37
|
+
|
38
|
+
gem 'smartpay'
|
39
|
+
```
|
40
|
+
|
41
|
+
## Usage
|
42
|
+
|
43
|
+
The package needs to be configured with your own API keys, you can find them on your [dashboard](https://dashboard.smartpay.co/settings/credentials).
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
Smartpay.configure do |config|
|
47
|
+
config.public_key = '<YOUR_PUBLIC_KEY>' # the one starts with pk_test_
|
48
|
+
config.secret_key = '<YOUR_SECRET_KEY>' # the one starts with sk_test_
|
49
|
+
end
|
50
|
+
```
|
51
|
+
|
52
|
+
### Create Checkout session
|
53
|
+
|
54
|
+
You can find the description and requirement for request payload in [API Document](https://api-doc.smartpay.co/#8a3538b1-530c-448c-8bae-4a41cdf0b8fd).
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
payloaad = {
|
58
|
+
"customerInfo": {
|
59
|
+
"emailAddress": "success@smartpay.co",
|
60
|
+
},
|
61
|
+
"orderData": {
|
62
|
+
"amount": 250,
|
63
|
+
"currency": "JPY",
|
64
|
+
"shippingInfo": {
|
65
|
+
"address": {
|
66
|
+
"line1": "line1",
|
67
|
+
"locality": "locality",
|
68
|
+
"postalCode": "123",
|
69
|
+
"country": "JP"
|
70
|
+
},
|
71
|
+
},
|
72
|
+
"lineItemData": [{
|
73
|
+
"priceData": {
|
74
|
+
"productData": {
|
75
|
+
"name": "レブロン 18 LOW",
|
76
|
+
},
|
77
|
+
"amount": 250,
|
78
|
+
"currency": "JPY",
|
79
|
+
},
|
80
|
+
"quantity": 1
|
81
|
+
}]
|
82
|
+
},
|
83
|
+
"reference": "order_ref_1234567",
|
84
|
+
"successUrl": "https://docs.smartpay.co/example-pages/checkout-successful",
|
85
|
+
"cancelUrl": "https://docs.smartpay.co/example-pages/checkout-canceled"
|
86
|
+
}
|
87
|
+
```
|
88
|
+
|
89
|
+
Create a checkout session by using `Smartpay::Api.create_checkout_session` with your request payload.
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
session = Smartpay::Api.create_checkout_session(payload)
|
93
|
+
```
|
94
|
+
|
95
|
+
Then, you can redirect your customer to the session url by calling `redirect_url`:
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
session.redirect_url
|
99
|
+
```
|
100
|
+
|
101
|
+
## Use with your favorite frameworks
|
102
|
+
|
103
|
+
### Ruby on Rails (RoR)
|
104
|
+
|
105
|
+
#### Install Rails
|
106
|
+
|
107
|
+
```sh
|
108
|
+
gem install rails
|
109
|
+
```
|
110
|
+
|
111
|
+
#### Create your app
|
112
|
+
|
113
|
+
```sh
|
114
|
+
rails new app-with-smartpay
|
115
|
+
```
|
116
|
+
|
117
|
+
#### Add Smartpay
|
118
|
+
|
119
|
+
```sh
|
120
|
+
cd app-with-smartpay
|
121
|
+
bundle add smartpay
|
122
|
+
```
|
123
|
+
|
124
|
+
#### Generator
|
125
|
+
|
126
|
+
```sh
|
127
|
+
bundle exec rails generate smartpay:install
|
128
|
+
```
|
129
|
+
|
130
|
+
This introduces 4 changes for a pre-built Smartpay Checkout example:
|
131
|
+
|
132
|
+
> 1. A new initializer - `config/initializers/smartpay.rb`. You will have to update the `config.public_key` and `config.secret_key` with your own credentials to make this work.
|
133
|
+
> 2. A new controller - `app/controllers/smartpays_controller.rb`. This is where you can see how a Checkout session is configured & created.
|
134
|
+
> 3. A new view - `app/views/smartpays/index.html.erb`. The minimum frontend required.
|
135
|
+
> 4. A new route in config/routes.rb.
|
136
|
+
|
137
|
+
#### Fill in your API keys
|
138
|
+
|
139
|
+
Edit the keys with your own credentials in `config/initializers/smartpay.rb`.
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
...
|
143
|
+
config.public_key = '<YOUR_PUBLIC_KEY>' # the one starts with pk_test_
|
144
|
+
config.secret_key = '<YOUR_SECRET_KEY>' # the one starts with sk_test_
|
145
|
+
...
|
146
|
+
```
|
147
|
+
|
148
|
+
#### Start your server
|
149
|
+
|
150
|
+
```sh
|
151
|
+
bundle exec rails server
|
152
|
+
```
|
153
|
+
|
154
|
+
### Test with Checkout Session
|
155
|
+
|
156
|
+
Visit [http://localhost:3000/smartpays](http://localhost:3000/smartpays).
|
157
|
+
|
158
|
+
Click the `checkout` button on the page to be redirected to Smartpay's Checkout.
|
159
|
+
|
160
|
+
To try out different cases, you can use the following test credit cards for different cases:
|
161
|
+
|
162
|
+
- Payment succeeds: `4242 4242 4242 4242`
|
163
|
+
- Payment is declined: `4100 0000 0000 0019`
|
164
|
+
|
165
|
+
## Development
|
166
|
+
|
167
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
168
|
+
|
169
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
170
|
+
|
171
|
+
## Contributing
|
172
|
+
|
173
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/smartpay. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/smartpay/blob/master/CODE_OF_CONDUCT.md).
|
174
|
+
|
175
|
+
## License
|
176
|
+
|
177
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
178
|
+
|
179
|
+
## Code of Conduct
|
180
|
+
|
181
|
+
Everyone interacting in the Smartpay project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/smartpay/blob/master/CODE_OF_CONDUCT.md).
|
@@ -5,8 +5,8 @@ module Smartpay
|
|
5
5
|
class CheckoutSession
|
6
6
|
attr_accessor :payload
|
7
7
|
|
8
|
-
REQUIREMENT_KEY_NAME = [:
|
9
|
-
CAN_FALLBACK_KEYS = [:customerInfo
|
8
|
+
REQUIREMENT_KEY_NAME = [:successUrl, :cancelUrl, :customerInfo, :currency, :items].freeze
|
9
|
+
CAN_FALLBACK_KEYS = [:customerInfo].freeze
|
10
10
|
|
11
11
|
def initialize(raw_payload)
|
12
12
|
@payload = raw_payload.transform_keys(&:to_sym)
|
@@ -27,25 +27,21 @@ module Smartpay
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def normalize_payload
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
shipping_info = payload.dig(:shippingInfo) || normalize_shipping(payload.dig(:shipping))
|
31
|
+
if shipping_info && shipping_info[:feeCurrency].nil? && !(shipping_info[:feeAmount].nil?)
|
32
|
+
shipping_info[:feeCurrency] = payload.dig(:currency)
|
33
|
+
end
|
34
34
|
|
35
35
|
{
|
36
36
|
customerInfo: normalize_customer_info(payload.dig(:customerInfo) || payload.dig(:customer) || {}),
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
description: payload.dig(:orderDescription),
|
46
|
-
metadata: payload.dig(:orderMetadata),
|
47
|
-
reference: payload.dig(:reference),
|
48
|
-
}),
|
37
|
+
amount: payload.dig(:amount),
|
38
|
+
captureMethod: payload.dig(:captureMethod),
|
39
|
+
currency: payload.dig(:currency),
|
40
|
+
description: payload.dig(:description),
|
41
|
+
shippingInfo: shipping_info,
|
42
|
+
items: normalize_items(payload.dig(:items)),
|
43
|
+
metadata: payload.dig(:metadata) || {},
|
44
|
+
reference: payload.dig(:reference),
|
49
45
|
successUrl: payload.dig(:successURL),
|
50
46
|
cancelUrl: payload.dig(:cancelURL),
|
51
47
|
test: payload.dig(:test) || false
|
@@ -92,118 +88,33 @@ module Smartpay
|
|
92
88
|
}
|
93
89
|
end
|
94
90
|
|
95
|
-
def
|
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)
|
91
|
+
def normalize_items(data)
|
112
92
|
return [] if data.nil?
|
113
93
|
|
114
94
|
data.map do |item|
|
115
95
|
line_item = item.transform_keys(&:to_sym)
|
116
96
|
{
|
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
97
|
quantity: line_item.dig(:quantity),
|
98
|
+
label: line_item.dig(:label),
|
99
|
+
name: line_item.dig(:name),
|
100
|
+
description: line_item.dig(:description),
|
101
|
+
amount: line_item.dig(:amount),
|
102
|
+
currency: line_item.dig(:currency),
|
103
|
+
brand: line_item.dig(:brand),
|
104
|
+
categories: line_item.dig(:categories),
|
105
|
+
gtin: line_item.dig(:gtin),
|
106
|
+
images: line_item.dig(:images),
|
107
|
+
reference: line_item.dig(:reference),
|
108
|
+
url: line_item.dig(:url),
|
137
109
|
description: line_item.dig(:description),
|
138
|
-
|
110
|
+
priceDescription: line_item.dig(:priceDescription),
|
111
|
+
productDescription: line_item.dig(:productDescription),
|
112
|
+
metadata: line_item.dig(:metadata),
|
113
|
+
productMetadata: line_item.dig(:productMetadata),
|
114
|
+
priceMetadata: line_item.dig(:priceMetadata)
|
139
115
|
}
|
140
116
|
end
|
141
117
|
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
118
|
end
|
208
119
|
end
|
209
120
|
end
|
data/lib/smartpay/version.rb
CHANGED
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.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Smartpay
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-02-
|
11
|
+
date: 2022-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|