smartpay 0.2.8 → 0.2.12

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: b690d134a39f8c15358fddf3366232d36007e243d0f815d9f5c5b8a0d7c5ba97
4
- data.tar.gz: 65826519cd1b6eaf41b35b81da6ace598d51e9bfec6188a1e4a8ff5dd0c1c69c
3
+ metadata.gz: 86ae2589b7f59311ec99f52daf9396460008814a346545f13cd038205841ed66
4
+ data.tar.gz: adc26ad630d2f5286dbf1aeee347a0532ee9eee650c3688286ee4559efcfed75
5
5
  SHA512:
6
- metadata.gz: 760b95974a074df025f9d12bdd07477d16395deff65d7322ea35f0473e8aefe0a3055be7c741e6a0417aa9a13fe682b3fec21f41cf6f3968310892402e8ee066
7
- data.tar.gz: 803cb1451a936e3def75c46a6e7c4c702c070ea473066c68edc1a1b7163109d36062a6b579267c47b4fb0da075f34ae3a459d172801b28a13125c3c39eb01dd7
6
+ metadata.gz: a4efcc6b9891f3ea262e9b7721166ec5aa737e8e5b29f9e73ca7df22bff67981948e46477dc052afb6d246ebb5115b330e88729c5ca034ee017907a64c988a33
7
+ data.tar.gz: 3075c8c2cfe44f17c9feb649c36b3e845f0bd7d442146b775eff495fbb6f3333466d88cff2f23b44254ece606d7178b39b5a5371d0839fe328f735e0392f35f6
data/lib/smartpay/api.rb CHANGED
@@ -5,7 +5,7 @@ module Smartpay
5
5
  class << self
6
6
  def create_checkout_session(payload)
7
7
  Responses::CheckoutSession.new(
8
- Client.post('/checkout/sessions', Requests::CheckoutSession.new(payload).as_hash)
8
+ Client.post('/checkout-sessions', Requests::CheckoutSession.new(payload).as_hash)
9
9
  )
10
10
  end
11
11
  end
@@ -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) || item.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
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.8"
4
+ VERSION = "0.2.12"
5
5
  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.8
4
+ version: 0.2.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Smartpay
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-26 00:00:00.000000000 Z
11
+ date: 2021-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client