smartpay 0.7.0 → 0.9.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: 7b7941ccf3a44139633152fbb1ec945e3fa8687889b370fa039cbe9a28ec54fd
4
- data.tar.gz: 4c823a7e41688255cc6d81289658e183da4b2a9d9d85a340e668dd11b7118309
3
+ metadata.gz: 00410e1e92eac18110d098a09a4750d33d8a6f1b06c996b2cfaab3d8894fdfd6
4
+ data.tar.gz: b8efe4cb9dd735fb8b34f21a8cff1b21c19dd87994d74a2baf5b27960040e7f0
5
5
  SHA512:
6
- metadata.gz: b25f291898db670b7e164f64e9d4e37b3bfbf490f69b89896cb763d5cb6f8300bb2adcaf05de6226a37f57130765caf0808ff44d043a4afa19c50de3533ba214
7
- data.tar.gz: 0fe3d4a49422422f9ebef68453b8bfdc8ca2b4ca45f3c55b349f74575c12b221ea9b4421e6f1b96555ffc919f389cb4053739964ceab18f516d4267e8f322b0f
6
+ metadata.gz: 19fce14ce1eb29e8513d9b1f7c7594a6ed822f1b9ba5f5cc7b69c657458d79af3e54ee3413182b550e91426e064b3aa683d4d0de4f47bab9f3911ff8c2accc9f
7
+ data.tar.gz: 25123f86a91d9d6053e66798d5db35594c433383ec5d76728981d500e241e8b95169e3d4907305a4e1bc1fb360b3403bc2b29cc0e560e1468669816c2a6cf0fc
data/.whitesource ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "scanSettings": {
3
+ "baseBranches": []
4
+ },
5
+ "checkRunSettings": {
6
+ "vulnerableCheckRunConclusionLevel": "failure",
7
+ "displayMode": "diff"
8
+ },
9
+ "issueSettings": {
10
+ "minSeverityLevel": "LOW"
11
+ }
12
+ }
data/lib/smartpay/api.rb CHANGED
@@ -3,23 +3,23 @@
3
3
  module Smartpay
4
4
  class Api
5
5
  class << self
6
- def create_checkout_session(payload)
7
- return create_checkout_session_for_token(payload) if payload[:mode] == "token"
6
+ def create_checkout_session(payload, idempotency_key: nil)
7
+ return create_checkout_session_for_token(payload, idempotency_key: idempotency_key) if payload[:mode] == "token"
8
8
 
9
9
  Responses::CheckoutSession.new(
10
- Client.post("/checkout-sessions", params: {}, payload: Requests::CheckoutSession.new(payload).as_hash)
10
+ Client.post("/checkout-sessions", params: {}, payload: Requests::CheckoutSession.new(payload).as_hash, idempotency_key: idempotency_key)
11
11
  )
12
12
  end
13
13
 
14
- def create_checkout_session_for_token(payload)
14
+ def create_checkout_session_for_token(payload, idempotency_key: nil)
15
15
  Responses::CheckoutSession.new(
16
- Client.post("/checkout-sessions", params: {}, payload: Requests::CheckoutSessionForToken.new(payload).as_hash)
16
+ Client.post("/checkout-sessions", params: {}, payload: Requests::CheckoutSessionForToken.new(payload).as_hash, idempotency_key: idempotency_key)
17
17
  )
18
18
  end
19
19
 
20
- def create_order(payload)
20
+ def create_order(payload, idempotency_key: nil)
21
21
  Responses::Base.new(
22
- Client.post("/orders", params:{}, payload: Requests::Order.new(payload).as_hash)
22
+ Client.post("/orders", params:{}, payload: Requests::Order.new(payload).as_hash, idempotency_key: idempotency_key)
23
23
  )
24
24
  end
25
25
 
@@ -31,34 +31,34 @@ module Smartpay
31
31
  Responses::Base.new(Client.get("/orders/%s" % id, params: { expand: expand }))
32
32
  end
33
33
 
34
- def cancel_order(id)
34
+ def cancel_order(id, idempotency_key: nil)
35
35
  Responses::Base.new(
36
- Client.put("/orders/%s/cancellation" % id)
36
+ Client.put("/orders/%s/cancellation" % id, idempotency_key: idempotency_key)
37
37
  )
38
38
  end
39
39
 
40
- def create_payment(payload)
40
+ def create_payment(payload, idempotency_key: nil)
41
41
  Responses::Base.new(
42
- Client.post("/payments", params:{}, payload: Requests::Payment.new(payload).as_hash)
42
+ Client.post("/payments", params:{}, payload: Requests::Payment.new(payload).as_hash, idempotency_key: idempotency_key)
43
43
  )
44
44
  end
45
45
 
46
- def capture(payload)
47
- create_payment(payload)
46
+ def capture(payload, idempotency_key: nil)
47
+ create_payment(payload, idempotency_key: idempotency_key)
48
48
  end
49
49
 
50
50
  def get_payment(id, expand: '' )
51
51
  Responses::Base.new(Client.get("/payments/%s" % id, params: { expand: expand }))
52
52
  end
53
53
 
54
- def create_refund(payload)
54
+ def create_refund(payload, idempotency_key: nil)
55
55
  Responses::Base.new(
56
- Client.post("/refunds", params:{}, payload: Requests::Refund.new(payload).as_hash)
56
+ Client.post("/refunds", params:{}, payload: Requests::Refund.new(payload).as_hash, idempotency_key: idempotency_key)
57
57
  )
58
58
  end
59
59
 
60
- def refund(payload)
61
- create_refund(payload)
60
+ def refund(payload, idempotency_key: nil)
61
+ create_refund(payload, idempotency_key: idempotency_key)
62
62
  end
63
63
 
64
64
  def get_refund(id, expand: '' )
@@ -73,16 +73,16 @@ module Smartpay
73
73
  Responses::Base.new(Client.get("/tokens/%s" % id))
74
74
  end
75
75
 
76
- def enable_token(id)
77
- Responses::Base.new(Client.put("/tokens/%s/enable" % id))
76
+ def enable_token(id, idempotency_key: nil)
77
+ Responses::Base.new(Client.put("/tokens/%s/enable" % id, idempotency_key: idempotency_key))
78
78
  end
79
79
 
80
- def disable_token(id)
81
- Responses::Base.new(Client.put("/tokens/%s/disable" % id))
80
+ def disable_token(id, idempotency_key: nil)
81
+ Responses::Base.new(Client.put("/tokens/%s/disable" % id, idempotency_key: idempotency_key))
82
82
  end
83
83
 
84
- def delete_token(id)
85
- Responses::Base.new(Client.delete("/tokens/%s" % id))
84
+ def delete_token(id, idempotency_key: nil)
85
+ Responses::Base.new(Client.delete("/tokens/%s" % id, idempotency_key: idempotency_key))
86
86
  end
87
87
  end
88
88
  end
@@ -9,45 +9,57 @@ module Smartpay
9
9
  class << self
10
10
  def get(path, params: {})
11
11
  request_params = default_params.merge(params)
12
- RestClient::Request.execute(method: :get, url: api_url(path),
13
- headers: headers.merge(params: request_params),
14
- timeout: timeout)
12
+ with_retries(retry_options) do
13
+ RestClient::Request.execute(
14
+ method: :get,
15
+ url: api_url(path),
16
+ headers: headers.merge(params: request_params),
17
+ timeout: timeout
18
+ )
19
+ end
15
20
  end
16
21
 
17
- def post(path, params: {}, payload: {})
22
+
23
+ def post(path, params: {}, payload: {}, idempotency_key: nil)
18
24
  request_params = default_params.merge(params)
19
25
  request_payload = default_payload.merge(payload)
20
- idempotency_key = nonce
21
- with_retries(:max_tries => 1, :rescue => [RestClient::BadRequest, RestClient::BadGateway, RestClient::ServiceUnavailable, RestClient::GatewayTimeout]) do
22
- RestClient::Request.execute(method: :post, url: api_url(path),
23
- params: request_params,
24
- headers: headers.merge({Idempotency_Key: idempotency_key}).merge(params: request_params),
25
- timeout: timeout,
26
- payload: request_payload.to_json)
26
+ idempotency_key ||= nonce
27
+ with_retries(retry_options) do
28
+ RestClient::Request.execute(
29
+ method: :post,
30
+ url: api_url(path),
31
+ headers: headers.merge({ Idempotency_Key: idempotency_key }).merge(params: request_params),
32
+ timeout: timeout,
33
+ payload: request_payload.to_json
34
+ )
27
35
  end
28
36
  end
29
37
 
30
- def put(path, params: {}, payload: {})
31
- request_params = default_params.merge(params).merge({'Idempotency-Key': nonce})
38
+ def put(path, params: {}, payload: {}, idempotency_key: nil)
39
+ request_params = default_params.merge(params)
32
40
  request_payload = default_payload.merge(payload)
33
- idempotency_key = nonce
34
- with_retries(:max_tries => 1, :rescue => [RestClient::InternalServerError, RestClient::BadGateway, RestClient::ServiceUnavailable, RestClient::GatewayTimeout]) do
35
- RestClient::Request.execute(method: :put, url: api_url(path),
36
- params: request_params,
37
- headers: headers.merge({Idempotency_Key: idempotency_key}).merge(params: request_params),
38
- timeout: timeout,
39
- payload: request_payload.to_json)
41
+ idempotency_key ||= nonce
42
+ with_retries(retry_options) do
43
+ RestClient::Request.execute(
44
+ method: :put,
45
+ url: api_url(path),
46
+ headers: headers.merge({ Idempotency_Key: idempotency_key }).merge(params: request_params),
47
+ timeout: timeout,
48
+ payload: request_payload.to_json
49
+ )
40
50
  end
41
51
  end
42
52
 
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)
53
+ def delete(path, params: {}, idempotency_key: nil)
54
+ request_params = default_params.merge(params)
55
+ idempotency_key ||= nonce
56
+ with_retries(retry_options) do
57
+ RestClient::Request.execute(
58
+ method: :delete,
59
+ url: api_url(path),
60
+ headers: headers.merge({ Idempotency_Key: idempotency_key }).merge(params: request_params),
61
+ timeout: timeout
62
+ )
51
63
  end
52
64
  end
53
65
 
@@ -62,7 +74,7 @@ module Smartpay
62
74
  end
63
75
 
64
76
  def timeout
65
- Smartpay.configuration.post_timeout
77
+ Smartpay.configuration.request_timeout
66
78
  end
67
79
 
68
80
  def headers
@@ -84,6 +96,10 @@ module Smartpay
84
96
  }.freeze
85
97
  end
86
98
 
99
+ def retry_options
100
+ Smartpay.configuration.retry_options
101
+ end
102
+
87
103
  def default_payload
88
104
  {}.freeze
89
105
  end
@@ -1,48 +1,33 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "rest-client"
4
+
3
5
  module Smartpay
6
+ # Smartpay configuration
4
7
  class Configuration
5
- attr_accessor :public_key, :secret_key
6
- attr_writer :post_timeout, :api_url, :checkout_url
8
+ attr_accessor :public_key, :secret_key, :request_timeout, :api_url, :retry_options
7
9
 
8
10
  DEFAULT_TIMEOUT_SETTING = 30
9
11
  DEFAULT_API_URL = "https://api.smartpay.co/v1"
10
- DEFAULT_CHECKOUT_URL = "https://checkout.smartpay.co"
12
+ DEFAULT_RETRY_OPTIONS = {
13
+ max_tries: 1,
14
+ base_sleep_seconds: 0.5,
15
+ max_sleep_seconds: 1.0,
16
+ rescue: [RestClient::InternalServerError,RestClient::BadGateway,
17
+ RestClient::ServiceUnavailable, RestClient::GatewayTimeout]
18
+ }.freeze
11
19
 
12
20
  def initialize
13
- @post_timeout = DEFAULT_TIMEOUT_SETTING
14
- @api_url = if in_development_mode?
15
- ENV["SMARTPAY_API_PREFIX"].downcase || DEFAULT_API_URL
16
- else
17
- DEFAULT_API_URL
18
- end
19
- @checkout_url = if in_development_mode? && ENV["SMARTPAY_CHECKOUT_URL"].is_a?(String)
20
- ENV["SMARTPAY_CHECKOUT_URL"].downcase || DEFAULT_CHECKOUT_URL
21
- else
22
- DEFAULT_CHECKOUT_URL
23
- end
24
- end
25
-
26
- def post_timeout
27
- @post_timeout || DEFAULT_TIMEOUT_SETTING
28
- end
29
-
30
- def api_url
31
- if in_development_mode?
32
- @api_url || ENV["SMARTPAY_API_PREFIX"].downcase || DEFAULT_API_URL
33
- else
34
- @api_url || DEFAULT_API_URL
35
- end
36
- end
37
-
38
- def checkout_url
39
- @checkout_url || DEFAULT_CHECKOUT_URL
21
+ reset
40
22
  end
41
23
 
42
- private
43
-
44
- def in_development_mode?
45
- ENV["SMARTPAY_API_PREFIX"].downcase.include?("api.smartpay") if ENV["SMARTPAY_API_PREFIX"].is_a?(String)
24
+ def reset
25
+ @request_timeout = DEFAULT_TIMEOUT_SETTING
26
+ @api_url = ENV.fetch("SMARTPAY_API_PREFIX", DEFAULT_API_URL).downcase
27
+ @retry_options = DEFAULT_RETRY_OPTIONS
28
+ @request_timeout = DEFAULT_TIMEOUT_SETTING
29
+ @public_key = ENV.fetch("SMARTPAY_PUBLIC_KEY", nil)
30
+ @secret_key = ENV.fetch("SMARTPAY_SECRET_KEY", nil)
46
31
  end
47
32
  end
48
33
  end
@@ -3,7 +3,6 @@
3
3
  module Smartpay
4
4
  module Responses
5
5
  class CheckoutSession < Base
6
-
7
6
  def redirect_url(options = {})
8
7
  url = response[:url]
9
8
 
@@ -15,16 +14,6 @@ module Smartpay
15
14
 
16
15
  url
17
16
  end
18
-
19
- private
20
-
21
- def checkout_url
22
- Smartpay.configuration.checkout_url
23
- end
24
-
25
- def public_key
26
- Smartpay.configuration.public_key
27
- end
28
17
  end
29
18
  end
30
19
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Smartpay
4
- VERSION = "0.7.0"
4
+ VERSION = "0.9.0"
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.7.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Smartpay
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-10 00:00:00.000000000 Z
11
+ date: 2023-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -47,6 +47,7 @@ extra_rdoc_files: []
47
47
  files:
48
48
  - ".rspec"
49
49
  - ".rubocop.yml"
50
+ - ".whitesource"
50
51
  - CHANGELOG.md
51
52
  - CODE_OF_CONDUCT.md
52
53
  - Gemfile