smartpay 0.5.0 → 0.7.0

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: c0cd94594c52188072ee764c3d9abbab864773af324310b3f0a6e5747570e04e
4
- data.tar.gz: 7fe589e25744b8891af1b91786d26c4f7e67e13fcf4ba80c9d847ea31461181f
3
+ metadata.gz: 7b7941ccf3a44139633152fbb1ec945e3fa8687889b370fa039cbe9a28ec54fd
4
+ data.tar.gz: 4c823a7e41688255cc6d81289658e183da4b2a9d9d85a340e668dd11b7118309
5
5
  SHA512:
6
- metadata.gz: 8973913b6c40ddd9fa7449d43696c823b25ac36483f070c3fe1a6cafffe8f030b70171ee2ff7c8ae9876b336a820efaf17b1de85f0bc2b0245b2d6add321f47e
7
- data.tar.gz: 6b7e1721a942ace0254e701c23186f0b2c0eaa6d2821e9fd5bf4339b782e58b8eaa9d2b6aa39e40b6c1babbb462c199f964f4bf9a9f2ec4664f8d39b9bef25d8
6
+ metadata.gz: b25f291898db670b7e164f64e9d4e37b3bfbf490f69b89896cb763d5cb6f8300bb2adcaf05de6226a37f57130765caf0808ff44d043a4afa19c50de3533ba214
7
+ data.tar.gz: 0fe3d4a49422422f9ebef68453b8bfdc8ca2b4ca45f3c55b349f74575c12b221ea9b4421e6f1b96555ffc919f389cb4053739964ceab18f516d4267e8f322b0f
data/README.md CHANGED
@@ -55,35 +55,66 @@ You can find the description and requirement for request payload in [API Documen
55
55
 
56
56
  ```ruby
57
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
- }
58
+ currency: "JPY",
59
+ items: [
60
+ {
61
+ name: "オリジナルス STAN SMITH",
62
+ amount: 1000,
63
+ currency: "JPY",
64
+ quantity: 1
65
+ },
66
+ {
67
+ currency: "JPY",
68
+ amount: 500,
69
+ name: "Merchant special discount",
70
+ kind: "discount"
71
+ },
72
+ {
73
+ currency: "JPY",
74
+ amount: 100,
75
+ name: "explicit taxes",
76
+ kind: "tax"
77
+ }
78
+ ],
79
+ customerInfo: {
80
+ accountAge: 20,
81
+ email: "merchant-support@smartpay.co",
82
+ firstName: "田中",
83
+ lastName: "太郎",
84
+ firstNameKana: "たなか",
85
+ lastNameKana: "たろう",
86
+ address: {
87
+ line1: "北青山 3-6-7",
88
+ line2: "青山パラシオタワー 11階",
89
+ subLocality: "",
90
+ locality: "港区",
91
+ administrativeArea: "東京都",
92
+ postalCode: "107-0061",
93
+ country: "JP"
94
+ },
95
+ dateOfBirth: "1985-06-30",
96
+ gender: "male"
97
+ },
98
+ shippingInfo: {
99
+ address: {
100
+ line1: "北青山 3-6-7",
101
+ line2: "青山パラシオタワー 11階",
102
+ subLocality: "",
103
+ locality: "港区",
104
+ administrativeArea: "東京都",
105
+ postalCode: "107-0061",
106
+ country: "JP"
107
+ },
108
+ feeAmount: 100,
109
+ feeCurrency: "JPY"
110
+ },
111
+
112
+ captureMethod: "manual",
113
+
114
+ reference: "order_ref_1234567",
115
+ successUrl: "https://docs.smartpay.co/example-pages/checkout-successful",
116
+ cancelUrl: "https://docs.smartpay.co/example-pages/checkout-canceled"
117
+ }
87
118
  ```
88
119
 
89
120
  Create a checkout session by using `Smartpay::Api.create_checkout_session` with your request payload.
@@ -170,7 +201,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
170
201
 
171
202
  ## Contributing
172
203
 
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).
204
+ Bug reports and pull requests are welcome on GitHub at https://github.com/smartpay-co/sdk-ruby. 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/smartpay-co/sdk-ruby/blob/master/CODE_OF_CONDUCT.md).
174
205
 
175
206
  ## License
176
207
 
@@ -178,4 +209,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
178
209
 
179
210
  ## Code of Conduct
180
211
 
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).
212
+ 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/smartpay-co/sdk-ruby/blob/master/CODE_OF_CONDUCT.md).
data/lib/smartpay/api.rb CHANGED
@@ -4,11 +4,25 @@ module Smartpay
4
4
  class Api
5
5
  class << self
6
6
  def create_checkout_session(payload)
7
+ return create_checkout_session_for_token(payload) if payload[:mode] == "token"
8
+
7
9
  Responses::CheckoutSession.new(
8
10
  Client.post("/checkout-sessions", params: {}, payload: Requests::CheckoutSession.new(payload).as_hash)
9
11
  )
10
12
  end
11
13
 
14
+ def create_checkout_session_for_token(payload)
15
+ Responses::CheckoutSession.new(
16
+ Client.post("/checkout-sessions", params: {}, payload: Requests::CheckoutSessionForToken.new(payload).as_hash)
17
+ )
18
+ end
19
+
20
+ def create_order(payload)
21
+ Responses::Base.new(
22
+ Client.post("/orders", params:{}, payload: Requests::Order.new(payload).as_hash)
23
+ )
24
+ end
25
+
12
26
  def get_orders(page_token: nil, max_results: nil, expand: '' )
13
27
  Responses::Base.new(Client.get("/orders", params: { pageToken: page_token, maxResults: max_results, expand: expand }))
14
28
  end
@@ -51,6 +65,25 @@ module Smartpay
51
65
  Responses::Base.new(Client.get("/refunds/%s" % id, params: { expand: expand }))
52
66
  end
53
67
 
68
+ def get_tokens(page_token: nil, max_results: nil)
69
+ Responses::Base.new(Client.get("/tokens", params: { pageToken: page_token, maxResults: max_results }))
70
+ end
71
+
72
+ def get_token(id)
73
+ Responses::Base.new(Client.get("/tokens/%s" % id))
74
+ end
75
+
76
+ def enable_token(id)
77
+ Responses::Base.new(Client.put("/tokens/%s/enable" % id))
78
+ end
79
+
80
+ def disable_token(id)
81
+ Responses::Base.new(Client.put("/tokens/%s/disable" % id))
82
+ end
83
+
84
+ def delete_token(id)
85
+ Responses::Base.new(Client.delete("/tokens/%s" % id))
86
+ end
54
87
  end
55
88
  end
56
89
  end
@@ -9,38 +9,46 @@ module Smartpay
9
9
  class << self
10
10
  def get(path, params: {})
11
11
  request_params = default_params.merge(params)
12
- response = RestClient::Request.execute(method: :get, url: api_url(path),
12
+ RestClient::Request.execute(method: :get, url: api_url(path),
13
13
  headers: headers.merge(params: request_params),
14
14
  timeout: timeout)
15
- JSON.parse(response.body, symbolize_names: true)
16
15
  end
17
16
 
18
17
  def post(path, params: {}, payload: {})
19
18
  request_params = default_params.merge(params)
20
19
  request_payload = default_payload.merge(payload)
21
20
  idempotency_key = nonce
22
- response = with_retries(:max_tries => 1, :rescue => [RestClient::BadRequest, RestClient::BadGateway, RestClient::ServiceUnavailable, RestClient::GatewayTimeout]) do
21
+ with_retries(:max_tries => 1, :rescue => [RestClient::BadRequest, RestClient::BadGateway, RestClient::ServiceUnavailable, RestClient::GatewayTimeout]) do
23
22
  RestClient::Request.execute(method: :post, url: api_url(path),
24
23
  params: request_params,
25
24
  headers: headers.merge({Idempotency_Key: idempotency_key}).merge(params: request_params),
26
25
  timeout: timeout,
27
26
  payload: request_payload.to_json)
28
27
  end
29
- JSON.parse(response.body, symbolize_names: true)
30
28
  end
31
29
 
32
30
  def put(path, params: {}, payload: {})
33
31
  request_params = default_params.merge(params).merge({'Idempotency-Key': nonce})
34
32
  request_payload = default_payload.merge(payload)
35
33
  idempotency_key = nonce
36
- response = with_retries(:max_tries => 1, :rescue => [RestClient::InternalServerError, RestClient::BadGateway, RestClient::ServiceUnavailable, RestClient::GatewayTimeout]) do
34
+ with_retries(:max_tries => 1, :rescue => [RestClient::InternalServerError, RestClient::BadGateway, RestClient::ServiceUnavailable, RestClient::GatewayTimeout]) do
37
35
  RestClient::Request.execute(method: :put, url: api_url(path),
38
36
  params: request_params,
39
37
  headers: headers.merge({Idempotency_Key: idempotency_key}).merge(params: request_params),
40
38
  timeout: timeout,
41
39
  payload: request_payload.to_json)
42
40
  end
43
- JSON.parse(response.body, symbolize_names: true)
41
+ end
42
+
43
+ def delete(path, params: {})
44
+ request_params = default_params.merge(params).merge({'Idempotency-Key': nonce})
45
+ idempotency_key = nonce
46
+ with_retries(:max_tries => 1, :rescue => [RestClient::InternalServerError, RestClient::BadGateway, RestClient::ServiceUnavailable, RestClient::GatewayTimeout]) do
47
+ RestClient::Request.execute(method: :delete, url: api_url(path),
48
+ params: request_params,
49
+ headers: headers.merge({Idempotency_Key: idempotency_key}).merge(params: request_params),
50
+ timeout: timeout)
51
+ end
44
52
  end
45
53
 
46
54
  private
@@ -1,140 +1,51 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "validator"
4
+ require_relative "normalizer"
5
+
3
6
  module Smartpay
4
7
  module Requests
8
+ # Request Object to create a CheckoutSession for order
5
9
  class CheckoutSession
10
+ include Validator
11
+ include Normalizer
12
+
6
13
  attr_accessor :payload
7
14
 
8
- REQUIREMENT_KEY_NAME = [:successUrl, :cancelUrl, :customer, :currency, :items].freeze
9
- CAN_FALLBACK_KEYS = [:customer].freeze
15
+ REQUIREMENT_KEY_NAME = %i[successUrl cancelUrl customerInfo shippingInfo currency items].freeze
10
16
 
11
17
  def initialize(raw_payload)
12
18
  @payload = raw_payload.transform_keys(&:to_sym)
13
19
  end
14
20
 
15
21
  def as_hash
16
- check_requirement!
22
+ check_requirement!(REQUIREMENT_KEY_NAME)
17
23
  normalize_payload
18
24
  end
19
25
 
20
26
  private
21
27
 
22
- def check_requirement!
23
- REQUIREMENT_KEY_NAME.each do |key_name|
24
- next if CAN_FALLBACK_KEYS.include?(key_name)
25
- raise Errors::InvalidRequestPayloadError, key_name unless payload.include?(key_name)
26
- end
27
- end
28
-
29
28
  def normalize_payload
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
-
35
- total_amount = get_total_amount
36
-
37
- {
38
- customerInfo: normalize_customer_info(payload.dig(:customerInfo) || payload.dig(:customer) || {}),
39
- amount: total_amount,
40
- captureMethod: payload.dig(:captureMethod),
41
- currency: payload.dig(:currency),
42
- description: payload.dig(:description),
43
- shippingInfo: shipping_info,
44
- items: normalize_items(payload.dig(:items)),
45
- metadata: payload.dig(:metadata) || {},
46
- reference: payload.dig(:reference),
47
- successUrl: payload.dig(:successUrl),
48
- cancelUrl: payload.dig(:cancelUrl),
49
- }
50
- end
51
-
52
- def normalize_customer_info(info)
53
- return if info.nil?
54
- customer = info.transform_keys(&:to_sym)
55
- {
56
- accountAge: customer.dig(:accountAge),
57
- emailAddress: customer.dig(:emailAddress) || customer.dig(:email),
58
- firstName: customer.dig(:firstName),
59
- lastName: customer.dig(:lastName),
60
- firstNameKana: customer.dig(:firstNameKana),
61
- lastNameKana: customer.dig(:lastNameKana),
62
- address: customer.dig(:address),
63
- phoneNumber: customer.dig(:phoneNumber) || customer.dig(:phone),
64
- dateOfBirth: customer.dig(:dateOfBirth),
65
- legalGender: customer.dig(:legalGender) || customer.dig(:gender),
66
- reference: customer.dig(:reference)
29
+ normalized = {
30
+ customerInfo: normalize_customer_info(payload[:customerInfo] || {}),
31
+ captureMethod: payload[:captureMethod],
32
+ currency: payload[:currency],
33
+ description: payload[:description],
34
+ shippingInfo: normalize_shipping(payload[:shippingInfo], payload[:currency]),
35
+ items: normalize_items(payload[:items]),
36
+ locale: payload[:locale],
37
+ metadata: payload[:metadata] || {},
38
+ reference: payload[:reference],
39
+ successUrl: payload[:successUrl],
40
+ cancelUrl: payload[:cancelUrl]
67
41
  }
68
- end
69
42
 
70
- def normalize_shipping(shipping)
71
- return if shipping.nil?
72
- shipping= shipping.transform_keys(&:to_sym)
73
- {
74
- address: shipping.dig(:address) || {
75
- line1: shipping.dig(:line1),
76
- line2: shipping.dig(:line2),
77
- line3: shipping.dig(:line3),
78
- line4: shipping.dig(:line4),
79
- line5: shipping.dig(:line5),
80
- subLocality: shipping.dig(:subLocality),
81
- locality: shipping.dig(:locality),
82
- administrativeArea: shipping.dig(:administrativeArea),
83
- postalCode: shipping.dig(:postalCode),
84
- country: shipping.dig(:country),
85
- },
86
- addressType: shipping.dig(:addressType),
87
- feeAmount: shipping.dig(:feeAmount),
88
- feeCurrency: shipping.dig(:feeCurrency),
89
- }
90
- end
43
+ normalized[:amount] = get_total_amount(normalized)
91
44
 
92
- def normalize_items(data)
93
- return [] if data.nil?
94
-
95
- data.map do |item|
96
- line_item = item.transform_keys(&:to_sym)
97
- {
98
- quantity: line_item.dig(:quantity),
99
- label: line_item.dig(:label),
100
- name: line_item.dig(:name),
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),
109
- description: line_item.dig(:description),
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)
115
- }
116
- end
45
+ normalized
117
46
  end
118
47
 
119
48
 
120
- def get_total_amount
121
- total_amount = payload.dig(:amount) || payload.dig('amount')
122
-
123
- if total_amount.nil?
124
- items = payload.dig(:items)
125
-
126
- if !items.nil? && items.count > 0
127
- total_amount = items.inject(0) { |sum, item| sum + (item[:amount] || item['amount'] || 0) }
128
- end
129
-
130
- shipping_fee = payload.dig(:shippingInfo, :feeAmount) ||
131
- payload.dig(:shippingInfo, 'feeAmount') ||
132
- 0
133
- total_amount = shipping_fee + (total_amount || 0)
134
- end
135
-
136
- total_amount
137
- end
138
49
  end
139
50
  end
140
51
  end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "validator"
4
+ require_relative "normalizer"
5
+
6
+ module Smartpay
7
+ module Requests
8
+ # Request Object to create a CheckoutSession for token
9
+ class CheckoutSessionForToken
10
+ include Validator
11
+ include Normalizer
12
+
13
+ attr_accessor :payload
14
+
15
+ REQUIREMENT_KEY_NAME = %i[successUrl cancelUrl customerInfo mode].freeze
16
+
17
+ def initialize(raw_payload)
18
+ @payload = raw_payload.transform_keys(&:to_sym)
19
+ raise Errors::InvalidRequestPayloadError, "mode" unless payload[:mode] == "token"
20
+ end
21
+
22
+ def as_hash
23
+ check_requirement!(REQUIREMENT_KEY_NAME)
24
+ normalize_payload
25
+ end
26
+
27
+ private
28
+
29
+ def normalize_payload
30
+ {
31
+ mode: payload[:mode],
32
+ customerInfo: normalize_customer_info(payload[:customerInfo] || {}),
33
+ metadata: payload[:metadata] || {},
34
+ locale: payload[:locale],
35
+ reference: payload[:reference],
36
+ successUrl: payload[:successUrl],
37
+ cancelUrl: payload[:cancelUrl]
38
+ }
39
+ end
40
+
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,108 @@
1
+ module Smartpay
2
+ module Requests
3
+ module Normalizer
4
+
5
+ LINE_ITEM_KINDS = %w[product tax discount].freeze
6
+
7
+ private
8
+
9
+ def normalize_customer_info(info)
10
+ return if info.nil?
11
+
12
+ customer = info.transform_keys(&:to_sym)
13
+ {
14
+ accountAge: customer[:accountAge],
15
+ emailAddress: customer[:emailAddress] || customer[:email],
16
+ firstName: customer[:firstName],
17
+ lastName: customer[:lastName],
18
+ firstNameKana: customer[:firstNameKana],
19
+ lastNameKana: customer[:lastNameKana],
20
+ address: customer[:address],
21
+ phoneNumber: customer[:phoneNumber] || customer[:phone],
22
+ dateOfBirth: customer[:dateOfBirth],
23
+ legalGender: customer[:legalGender] || customer[:gender],
24
+ reference: customer[:reference]
25
+ }
26
+ end
27
+
28
+ def normalize_shipping(shipping, fallback_currency = nil)
29
+ return if shipping.nil?
30
+
31
+ shipping = shipping.transform_keys(&:to_sym)
32
+ normalized_shipping = {
33
+ address: shipping[:address] || {
34
+ line1: shipping[:line1],
35
+ line2: shipping[:line2],
36
+ line3: shipping[:line3],
37
+ line4: shipping[:line4],
38
+ line5: shipping[:line5],
39
+ subLocality: shipping[:subLocality],
40
+ locality: shipping[:locality],
41
+ administrativeArea: shipping[:administrativeArea],
42
+ postalCode: shipping[:postalCode],
43
+ country: shipping[:country]
44
+ },
45
+ addressType: shipping[:addressType],
46
+ feeAmount: shipping[:feeAmount],
47
+ feeCurrency: shipping[:feeCurrency]
48
+ }
49
+
50
+ if normalized_shipping && normalized_shipping[:feeCurrency].nil? && !(normalized_shipping[:feeAmount].nil?)
51
+ normalized_shipping[:feeCurrency] = fallback_currency
52
+ end
53
+ normalized_shipping
54
+ end
55
+
56
+ def normalize_items(data)
57
+ return [] if data.nil?
58
+
59
+ data.map do |item|
60
+ line_item = item.transform_keys(&:to_sym)
61
+ {
62
+ quantity: line_item[:quantity],
63
+ label: line_item[:label],
64
+ name: line_item[:name],
65
+ amount: line_item[:amount],
66
+ currency: line_item[:currency],
67
+ brand: line_item[:brand],
68
+ categories: line_item[:categories],
69
+ gtin: line_item[:gtin],
70
+ images: line_item[:images],
71
+ reference: line_item[:reference],
72
+ url: line_item[:url],
73
+ description: line_item[:description],
74
+ priceDescription: line_item[:priceDescription],
75
+ productDescription: line_item[:productDescription],
76
+ metadata: line_item[:metadata],
77
+ productMetadata: line_item[:productMetadata],
78
+ priceMetadata: line_item[:priceMetadata],
79
+ kind: LINE_ITEM_KINDS.include?(line_item[:kind]) ? line_item[:kind] : nil
80
+ }
81
+ end
82
+ end
83
+
84
+ def get_total_amount(raw_payload = nil)
85
+ total_amount = raw_payload[:amount] || raw_payload["amount"]
86
+ return total_amount if total_amount
87
+
88
+ items = raw_payload[:items]
89
+
90
+ if !items.nil? && items.count.positive?
91
+ total_amount = items.inject(0) { |sum, item|
92
+ amount = item[:amount] || item["amount"] || 0
93
+ amount = -amount if item[:kind] == "discount"
94
+ sum + amount
95
+ }
96
+ end
97
+
98
+ shipping_fee = raw_payload.dig(:shippingInfo, :feeAmount) ||
99
+ raw_payload.dig(:shippingInfo, "feeAmount") ||
100
+ 0
101
+ total_amount += shipping_fee
102
+
103
+ total_amount
104
+ end
105
+
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "validator"
4
+ require_relative "normalizer"
5
+
6
+ module Smartpay
7
+ module Requests
8
+ # Request Object to create a CheckoutSession for order
9
+ class Order
10
+ include Validator
11
+ include Normalizer
12
+
13
+ attr_accessor :payload
14
+
15
+ REQUIREMENT_KEY_NAME = %i[token customerInfo shippingInfo currency items].freeze
16
+
17
+ def initialize(raw_payload)
18
+ @payload = raw_payload.transform_keys(&:to_sym)
19
+ end
20
+
21
+ def as_hash
22
+ check_requirement!(REQUIREMENT_KEY_NAME)
23
+ normalize_payload
24
+ end
25
+
26
+ private
27
+
28
+ def normalize_payload
29
+ normalized = {
30
+ token: payload[:token],
31
+ customerInfo: normalize_customer_info(payload[:customerInfo] || {}),
32
+ captureMethod: payload[:captureMethod],
33
+ currency: payload[:currency],
34
+ shippingInfo: normalize_shipping(payload[:shippingInfo], payload[:currency]),
35
+ items: normalize_items(payload[:items]),
36
+ metadata: payload[:metadata] || {},
37
+ reference: payload[:reference]
38
+ }
39
+
40
+ normalized[:amount] = get_total_amount(normalized)
41
+
42
+ normalized
43
+ end
44
+
45
+
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,15 @@
1
+ module Smartpay
2
+ module Requests
3
+ module Validator
4
+
5
+ private
6
+
7
+ def check_requirement!(requirement_keys = [])
8
+ requirement_keys.each do |key_name|
9
+ raise Errors::InvalidRequestPayloadError, key_name unless payload.include?(key_name)
10
+ end
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -5,8 +5,13 @@ module Smartpay
5
5
  class Base
6
6
  attr_reader :response
7
7
 
8
- def initialize(response)
9
- @response = response
8
+ def initialize(raw_response)
9
+ @raw_response = raw_response
10
+ @response = begin
11
+ JSON.parse(@raw_response.body, symbolize_names: true)
12
+ rescue JSON::ParserError
13
+ { body: @raw_response.body }
14
+ end if @raw_response
10
15
  end
11
16
 
12
17
  def as_hash
@@ -16,6 +21,10 @@ module Smartpay
16
21
  def as_json
17
22
  @response.to_json
18
23
  end
24
+
25
+ def http_code
26
+ @raw_response.code
27
+ end
19
28
  end
20
29
  end
21
30
  end
@@ -12,7 +12,7 @@ module Smartpay
12
12
 
13
13
  return "#{url}#{qs}"
14
14
  end
15
-
15
+
16
16
  url
17
17
  end
18
18
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Smartpay
4
- VERSION = "0.5.0"
4
+ VERSION = "0.7.0"
5
5
  end
data/lib/smartpay.rb CHANGED
@@ -8,6 +8,8 @@ require_relative "smartpay/client"
8
8
  require_relative "smartpay/api"
9
9
  require_relative "smartpay/errors/invalid_request_payload_error"
10
10
  require_relative "smartpay/requests/checkout_session"
11
+ require_relative "smartpay/requests/checkout_session_for_token"
12
+ require_relative "smartpay/requests/order"
11
13
  require_relative "smartpay/requests/payment"
12
14
  require_relative "smartpay/requests/refund"
13
15
  require_relative "smartpay/responses/base"
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.5.0
4
+ version: 0.7.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-04-18 00:00:00.000000000 Z
11
+ date: 2023-01-10 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: []
@@ -66,8 +66,12 @@ files:
66
66
  - lib/smartpay/configuration.rb
67
67
  - lib/smartpay/errors/invalid_request_payload_error.rb
68
68
  - lib/smartpay/requests/checkout_session.rb
69
+ - lib/smartpay/requests/checkout_session_for_token.rb
70
+ - lib/smartpay/requests/normalizer.rb
71
+ - lib/smartpay/requests/order.rb
69
72
  - lib/smartpay/requests/payment.rb
70
73
  - lib/smartpay/requests/refund.rb
74
+ - lib/smartpay/requests/validator.rb
71
75
  - lib/smartpay/responses/base.rb
72
76
  - lib/smartpay/responses/checkout_session.rb
73
77
  - lib/smartpay/version.rb
@@ -78,7 +82,7 @@ metadata:
78
82
  homepage_uri: https://smartpay.co
79
83
  source_code_uri: https://github.com/smartpay-co/sdk-ruby
80
84
  changelog_uri: https://github.com/smartpay-co/sdk-ruby/blob/main/CHANGELOG.md
81
- post_install_message:
85
+ post_install_message:
82
86
  rdoc_options: []
83
87
  require_paths:
84
88
  - lib
@@ -93,8 +97,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
97
  - !ruby/object:Gem::Version
94
98
  version: '0'
95
99
  requirements: []
96
- rubygems_version: 3.3.7
97
- signing_key:
100
+ rubygems_version: 3.0.3.1
101
+ signing_key:
98
102
  specification_version: 4
99
103
  summary: The Smartpay Ruby SDK offers easy access to Smartpay API from applications
100
104
  written in Ruby.