smartpay 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/smartpay/requests/checkout_session.rb +24 -19
- data/lib/smartpay/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 446eb4c4c827e38b97a57ecbceee0b43a932d53cdb11a6bd22215250c5897583
|
4
|
+
data.tar.gz: a6e513f1be63893df11793c7b74c66cea109e715423c2f0fbbb25c8869ed5089
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a274f5a5917cb8bef8bdabe0360f284436be5bc8f8052f7db9b6233eb6f7a18cfd798f4d1a63bd3d0a57e8e8cae1defc8f477e7e7bfe388531f13384e59245ce
|
7
|
+
data.tar.gz: 58c21a2d55b9fac38a560ac032d6af7f27f8bc2a61a6477fd1dcd2e884b2791d20f734c79dcd7be8c2b5b49f32eafec8f26604438cc55bf84313a46e5d864a3d
|
@@ -6,6 +6,7 @@ module Smartpay
|
|
6
6
|
attr_accessor :payload
|
7
7
|
|
8
8
|
REQUIREMENT_KEY_NAME = [:successUrl, :cancelUrl, :customer, :currency, :items].freeze
|
9
|
+
LINE_ITEM_KINDS = %w[product tax discount].freeze
|
9
10
|
CAN_FALLBACK_KEYS = [:customer].freeze
|
10
11
|
|
11
12
|
def initialize(raw_payload)
|
@@ -32,11 +33,8 @@ module Smartpay
|
|
32
33
|
shipping_info[:feeCurrency] = payload.dig(:currency)
|
33
34
|
end
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
{
|
36
|
+
normalized = {
|
38
37
|
customerInfo: normalize_customer_info(payload.dig(:customerInfo) || payload.dig(:customer) || {}),
|
39
|
-
amount: total_amount,
|
40
38
|
captureMethod: payload.dig(:captureMethod),
|
41
39
|
currency: payload.dig(:currency),
|
42
40
|
description: payload.dig(:description),
|
@@ -47,6 +45,10 @@ module Smartpay
|
|
47
45
|
successUrl: payload.dig(:successUrl),
|
48
46
|
cancelUrl: payload.dig(:cancelUrl),
|
49
47
|
}
|
48
|
+
|
49
|
+
normalized[:amount] = get_total_amount(normalized)
|
50
|
+
|
51
|
+
return normalized
|
50
52
|
end
|
51
53
|
|
52
54
|
def normalize_customer_info(info)
|
@@ -111,29 +113,32 @@ module Smartpay
|
|
111
113
|
productDescription: line_item.dig(:productDescription),
|
112
114
|
metadata: line_item.dig(:metadata),
|
113
115
|
productMetadata: line_item.dig(:productMetadata),
|
114
|
-
priceMetadata: line_item.dig(:priceMetadata)
|
116
|
+
priceMetadata: line_item.dig(:priceMetadata),
|
117
|
+
kind: LINE_ITEM_KINDS.include?(line_item.dig(:kind)) ? line_item.dig(:kind) : nil
|
115
118
|
}
|
116
119
|
end
|
117
120
|
end
|
118
121
|
|
122
|
+
def get_total_amount(raw_payload = nil)
|
123
|
+
total_amount = raw_payload.dig(:amount) || raw_payload.dig("amount")
|
124
|
+
return total_amount if total_amount
|
119
125
|
|
120
|
-
|
121
|
-
total_amount = payload.dig(:amount) || payload.dig('amount')
|
126
|
+
items = raw_payload.dig(:items)
|
122
127
|
|
123
|
-
if
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
shipping_fee = payload.dig(:shippingInfo, :feeAmount) ||
|
131
|
-
payload.dig(:shippingInfo, 'feeAmount') ||
|
132
|
-
0
|
133
|
-
total_amount = shipping_fee + (total_amount || 0)
|
128
|
+
if !items.nil? && items.count.positive?
|
129
|
+
total_amount = items.inject(0) { |sum, item|
|
130
|
+
amount = item[:amount] || item["amount"] || 0
|
131
|
+
amount = -amount if item[:kind] == "discount"
|
132
|
+
sum + amount
|
133
|
+
}
|
134
134
|
end
|
135
135
|
|
136
|
-
|
136
|
+
shipping_fee = raw_payload.dig(:shippingInfo, :feeAmount) ||
|
137
|
+
raw_payload.dig(:shippingInfo, "feeAmount") ||
|
138
|
+
0
|
139
|
+
total_amount += shipping_fee
|
140
|
+
|
141
|
+
return total_amount
|
137
142
|
end
|
138
143
|
end
|
139
144
|
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.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Smartpay
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -38,7 +38,7 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '3.0'
|
41
|
-
description:
|
41
|
+
description:
|
42
42
|
email:
|
43
43
|
- uxe@smartpay.co
|
44
44
|
executables: []
|
@@ -78,7 +78,7 @@ metadata:
|
|
78
78
|
homepage_uri: https://smartpay.co
|
79
79
|
source_code_uri: https://github.com/smartpay-co/sdk-ruby
|
80
80
|
changelog_uri: https://github.com/smartpay-co/sdk-ruby/blob/main/CHANGELOG.md
|
81
|
-
post_install_message:
|
81
|
+
post_install_message:
|
82
82
|
rdoc_options: []
|
83
83
|
require_paths:
|
84
84
|
- lib
|
@@ -93,8 +93,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
93
|
- !ruby/object:Gem::Version
|
94
94
|
version: '0'
|
95
95
|
requirements: []
|
96
|
-
rubygems_version: 3.3.
|
97
|
-
signing_key:
|
96
|
+
rubygems_version: 3.0.3.1
|
97
|
+
signing_key:
|
98
98
|
specification_version: 4
|
99
99
|
summary: The Smartpay Ruby SDK offers easy access to Smartpay API from applications
|
100
100
|
written in Ruby.
|