smartpay 0.2.6 → 0.2.10

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: fd9d36f1c0b628dcafc5308503663e63f628eb9467f237b750c03d7416e565d8
4
- data.tar.gz: 2c8aa53f89d35801c11657357e1cd01c79a647dcb1adb9a58dbb912538506152
3
+ metadata.gz: 12e94e9a107f36c71ff8aebd7b84b003df802033793c19cc5adc418320ea9c2f
4
+ data.tar.gz: 88c3044a95a05a57927ec59df5b78217ee3be450f2fb764f271907dd66d565c8
5
5
  SHA512:
6
- metadata.gz: 71e24b5936a52552e97675081d462154d527dd9effecf42cba3867dffe18640c6916b48cbffb7140e11c0b9fab50105821ee68271b7746685ad0021ba96b27a4
7
- data.tar.gz: f2f84b245783023dad0bb44e203c427d5b57f5d9ce14826c7bec5a312535f735bba133295d7e962f2dec7d8400c9d4760b3ca9c3f62262dd18ae08159c504369
6
+ metadata.gz: 7acc9bba7dcddaafab82fdecdcbe0a74a33a6cae7466241fe154882c19540d415bae65668fd62c04fd6828617f7407eeb23df466bda3427ecb3639b14eb41ee7
7
+ data.tar.gz: 9e1a06d03b2f328e6d2cc466745a102630c8b772b52f30275051c2b1b3edbb9222be205ebc861ccb1676048a447d208a3513b64fa21994588007a74856c88285
@@ -4,25 +4,41 @@ class SmartpaysController < ApplicationController
4
4
 
5
5
  def create
6
6
  session = Smartpay::Api.create_checkout_session({
7
- items: [
8
- {
9
- name: "レブロン 18 LOW",
10
- amount: 250,
11
- currency: "JPY",
12
- quantity: 1,
7
+ items: [{
8
+ name: "オリジナルス STAN SMITH",
9
+ amount: 250,
10
+ currency: "JPY",
11
+ quantity: 1
12
+ }],
13
+ customer: {
14
+ accountAge: 20,
15
+ email: "merchant-support@smartpay.co",
16
+ firstName: "田中",
17
+ lastName: "太郎",
18
+ firstNameKana: "たなか",
19
+ lastNameKana: "たろう",
20
+ address: {
21
+ line1: "3-6-7",
22
+ line2: "青山パラシオタワー 11階",
23
+ subLocality: "",
24
+ locality: "港区北青山",
25
+ administrativeArea: "東京都",
26
+ postalCode: "107-0061",
27
+ country: "JP"
13
28
  },
14
- ],
15
-
29
+ dateOfBirth: "1985-06-30",
30
+ gender: "male"
31
+ },
16
32
  shipping: {
17
33
  line1: "line1",
18
34
  locality: "locality",
19
35
  postalCode: "123",
20
- country: "JP",
36
+ country: "JP"
21
37
  },
22
38
  reference: "order_ref_1234567",
23
39
  successURL: "https://docs.smartpay.co/example-pages/checkout-successful",
24
40
  cancelURL: "https://docs.smartpay.co/example-pages/checkout-canceled",
25
- test: true,
41
+ test: true
26
42
  })
27
43
  redirect_to session.redirect_url
28
44
  end
@@ -27,13 +27,8 @@ module Smartpay
27
27
  end
28
28
 
29
29
  def normalize_payload
30
- currency = nil
31
- total_amount = 0
32
- items = payload.dig(:lineItemData) || payload.dig(:items)
33
- if items.count > 0
34
- total_amount = items.inject(0) { |sum, item| sum + (item[:amount] || 0) }
35
- currency = items.first.dig(:currency)
36
- end
30
+ currency = get_currency
31
+ total_amount = get_total_amount
37
32
 
38
33
  {
39
34
  customerInfo: normalize_customer_info(payload.dig(:customerInfo) || payload.dig(:customer) || {}),
@@ -44,7 +39,7 @@ module Smartpay
44
39
  confirmationMethod: payload.dig(:confirmationMethod),
45
40
  coupons: payload.dig(:coupons),
46
41
  shippingInfo: payload.dig(:shippingInfo) || normalize_shipping(payload.dig(:shipping)),
47
- lineItemData: items,
42
+ lineItemData: payload.dig(:orderData, :lineItemData) || payload.dig(:items),
48
43
  description: payload.dig(:orderDescription),
49
44
  metadata: payload.dig(:orderMetadata)
50
45
  }),
@@ -76,6 +71,7 @@ module Smartpay
76
71
 
77
72
  def normalize_shipping(shipping)
78
73
  return if shipping.nil?
74
+ shipping= shipping.transform_keys(&:to_sym)
79
75
  {
80
76
  address: shipping.dig(:address) || {
81
77
  line1: shipping.dig(:line1),
@@ -165,6 +161,34 @@ module Smartpay
165
161
  metadata: product.dig(:metadata)
166
162
  }
167
163
  end
164
+
165
+ def get_currency
166
+ currency = payload.dig(:orderData, :currency) || payload.dig(:orderData, 'currency')
167
+ if currency.nil?
168
+ items = get_items
169
+ if !items.nil? && items.count > 0
170
+ currency = items.first.dig(:currency) || items.first.dig('currency')
171
+ end
172
+ end
173
+ currency
174
+ end
175
+
176
+ def get_total_amount
177
+ total_amount = payload.dig(:orderData, :amount) || payload.dig(:orderData, 'amount')
178
+ if total_amount.nil?
179
+ items = get_items
180
+ if !items.nil? && items.count > 0
181
+ total_amount = items.inject(0) { |sum, item| sum + (item[:amount] || item['amount'] || 0) }
182
+ end
183
+ end
184
+ total_amount
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
168
192
  end
169
193
  end
170
194
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Smartpay
4
- VERSION = "0.2.6"
4
+ VERSION = "0.2.10"
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.6
4
+ version: 0.2.10
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-24 00:00:00.000000000 Z
11
+ date: 2021-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client