smartpay 0.2.7 → 0.2.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 56d3e609ce7f1842742670dff4b7eac351f6e653e199362cdd75b6715ec60501
4
- data.tar.gz: 35b80a47568eee0755b4335d3aa68922b5b68767ed8e2371c7a45949783b3269
3
+ metadata.gz: 0353211f9e0231c5524115accebba99be527dd01361f2706d587626d81e8129f
4
+ data.tar.gz: b96ca9b9bd0aaac4746f5849ea29ef9e098de79f0de59fa4e9acb0f3ebf05a21
5
5
  SHA512:
6
- metadata.gz: 32ce2b368f3a40956d8fea8929fcf54f3a442688bdc5cb49d3fcb5d1a5b81bb5ba43adcaebd30c0dd1d004fdefa56aeb7e38687bb9912d23157f5d3ead0a33d7
7
- data.tar.gz: db3ed60db92f3246636eb173025aefc1aa0f3153e38f67a3a690e4ad381183f6b916d59cc0f88871d0c69544c2f479a85da9eba9d04d06124e9acc1a32b98434
6
+ metadata.gz: 7778f540af382892db264134748b4e1be41e1bc1292e4ab569393b342fe4e3c7caf55b36b70b1b41a125b99e882ba7b5ef1bea6c38276d76695546cedaa1101c
7
+ data.tar.gz: cc1a7c500e098b63d5650472f50b5c23c072d88c1569a7e4b457ead20c2bf99434b48a86c59da786d4baa4c6df7d0045a4f4884e6a2b407566b597346cd3d6e4
@@ -2,11 +2,11 @@
2
2
 
3
3
  module Smartpay
4
4
  class Configuration
5
- attr_accessor :post_timeout
6
- attr_accessor :public_key, :secret_key, :api_url, :checkout_url
5
+ attr_accessor :public_key, :secret_key
6
+ attr_writer :post_timeout, :api_url, :checkout_url
7
7
 
8
8
  DEFAULT_TIMEOUT_SETTING = 30
9
- DEFAULT_API_URL = 'https://api.smartpay.co'
9
+ DEFAULT_API_URL = 'https://api.smartpay.co/v1'
10
10
  DEFAULT_CHECKOUT_URL = 'https://checkout.smartpay.co'
11
11
 
12
12
  def initialize
@@ -14,5 +14,17 @@ module Smartpay
14
14
  @api_url = DEFAULT_API_URL
15
15
  @checkout_url = DEFAULT_CHECKOUT_URL
16
16
  end
17
+
18
+ def post_timeout
19
+ @post_timeout || DEFAULT_TIMEOUT_SETTING
20
+ end
21
+
22
+ def api_url
23
+ @api_url || DEFAULT_API_URL
24
+ end
25
+
26
+ def checkout_url
27
+ @checkout_url || DEFAULT_CHECKOUT_URL
28
+ end
17
29
  end
18
30
  end
@@ -71,6 +71,7 @@ module Smartpay
71
71
 
72
72
  def normalize_shipping(shipping)
73
73
  return if shipping.nil?
74
+ shipping= shipping.transform_keys(&:to_sym)
74
75
  {
75
76
  address: shipping.dig(:address) || {
76
77
  line1: shipping.dig(:line1),
@@ -164,9 +165,9 @@ module Smartpay
164
165
  def get_currency
165
166
  currency = payload.dig(:orderData, :currency) || payload.dig(:orderData, 'currency')
166
167
  if currency.nil?
167
- items = payload.dig(:orderData, :lineItemData, :priceData) || payload.dig(:items)
168
+ items = get_items
168
169
  if !items.nil? && items.count > 0
169
- currency = items.first.dig(:currency)
170
+ currency = items.first.dig(:currency) || items.first.dig('currency')
170
171
  end
171
172
  end
172
173
  currency
@@ -175,13 +176,19 @@ module Smartpay
175
176
  def get_total_amount
176
177
  total_amount = payload.dig(:orderData, :amount) || payload.dig(:orderData, 'amount')
177
178
  if total_amount.nil?
178
- items = payload.dig(:orderData, :lineItemData, :priceData) || payload.dig(:items)
179
+ items = get_items
179
180
  if !items.nil? && items.count > 0
180
- total_amount = items.inject(0) { |sum, item| sum + (item[:amount] || 0) }
181
+ total_amount = items.inject(0) { |sum, item| sum + (item[:amount] || item['amount'] || 0) }
181
182
  end
182
183
  end
183
184
  total_amount
184
185
  end
186
+
187
+ def get_items
188
+ @items ||= payload.dig(:orderData, :lineItemData, :priceData) ||
189
+ payload.dig(:orderData, 'lineItemData', 'priceData') ||
190
+ payload.dig(:items)
191
+ end
185
192
  end
186
193
  end
187
194
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Smartpay
4
- VERSION = "0.2.7"
4
+ VERSION = "0.2.11"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smartpay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Smartpay