smartpay 0.4.0 → 0.5.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: 794e3de526f66e64a6c05638932f2c3c8a3cb7bcea3708f8df266ad9f02e7d4a
4
- data.tar.gz: f04b6f575b3be6e2320336a343fa9db842560654c5c7076d6b7bf07b2fcdab70
3
+ metadata.gz: c0cd94594c52188072ee764c3d9abbab864773af324310b3f0a6e5747570e04e
4
+ data.tar.gz: 7fe589e25744b8891af1b91786d26c4f7e67e13fcf4ba80c9d847ea31461181f
5
5
  SHA512:
6
- metadata.gz: 54c1bd5ae7e587b67409e4eb9eed4c50d36690f09958e9003f3b9e9aadf927c429a41dc8c7b9fb18581f5594653f15fa0b3271896486f1276b07c1dd022f8910
7
- data.tar.gz: 7cefc78c6463a95317d3f87abfc3e9ccc83cf5aeac7f2efed30194fba42faa2069e8e35ce695720ed9a83cdb523cec27a494b0611d51cee90d92bd62ecefd0a9
6
+ metadata.gz: 8973913b6c40ddd9fa7449d43696c823b25ac36483f070c3fe1a6cafffe8f030b70171ee2ff7c8ae9876b336a820efaf17b1de85f0bc2b0245b2d6add321f47e
7
+ data.tar.gz: 6b7e1721a942ace0254e701c23186f0b2c0eaa6d2821e9fd5bf4339b782e58b8eaa9d2b6aa39e40b6c1babbb462c199f964f4bf9a9f2ec4664f8d39b9bef25d8
data/Gemfile CHANGED
@@ -5,10 +5,14 @@ source "https://rubygems.org"
5
5
  # Specify your gem's dependencies in smartpay.gemspec
6
6
  gemspec
7
7
 
8
+ gem "rest-client", "~> 2.1.0"
9
+
10
+ gem "securerandom", "~> 0.2.0"
11
+
12
+ gem "retries", "~> 0.0.5"
13
+
8
14
  gem "rake", "~> 13.0"
9
15
 
10
16
  gem "rspec", "~> 3.0"
11
17
 
12
18
  gem "rubocop", "~> 1.7"
13
-
14
- gem "thin"
data/lib/smartpay/api.rb CHANGED
@@ -5,21 +5,27 @@ 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", params: {}, payload: Requests::CheckoutSession.new(payload).as_hash)
9
9
  )
10
10
  end
11
11
 
12
12
  def get_orders(page_token: nil, max_results: nil, expand: '' )
13
- Responses::Base.new(Client.get("/orders", { pageToken: page_token, maxResults: max_results, expand: expand }))
13
+ Responses::Base.new(Client.get("/orders", params: { pageToken: page_token, maxResults: max_results, expand: expand }))
14
14
  end
15
15
 
16
16
  def get_order(id, expand: '' )
17
- Responses::Base.new(Client.get("/orders/%s" % id, { expand: expand }))
17
+ Responses::Base.new(Client.get("/orders/%s" % id, params: { expand: expand }))
18
+ end
19
+
20
+ def cancel_order(id)
21
+ Responses::Base.new(
22
+ Client.put("/orders/%s/cancellation" % id)
23
+ )
18
24
  end
19
25
 
20
26
  def create_payment(payload)
21
27
  Responses::Base.new(
22
- Client.post("/payments", Requests::Payment.new(payload).as_hash)
28
+ Client.post("/payments", params:{}, payload: Requests::Payment.new(payload).as_hash)
23
29
  )
24
30
  end
25
31
 
@@ -27,9 +33,13 @@ module Smartpay
27
33
  create_payment(payload)
28
34
  end
29
35
 
36
+ def get_payment(id, expand: '' )
37
+ Responses::Base.new(Client.get("/payments/%s" % id, params: { expand: expand }))
38
+ end
39
+
30
40
  def create_refund(payload)
31
41
  Responses::Base.new(
32
- Client.post("/refunds", Requests::Refund.new(payload).as_hash)
42
+ Client.post("/refunds", params:{}, payload: Requests::Refund.new(payload).as_hash)
33
43
  )
34
44
  end
35
45
 
@@ -37,6 +47,10 @@ module Smartpay
37
47
  create_refund(payload)
38
48
  end
39
49
 
50
+ def get_refund(id, expand: '' )
51
+ Responses::Base.new(Client.get("/refunds/%s" % id, params: { expand: expand }))
52
+ end
53
+
40
54
  end
41
55
  end
42
56
  end
@@ -1,27 +1,54 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "rest-client"
4
+ require "retries"
5
+ require "securerandom"
4
6
 
5
7
  module Smartpay
6
8
  class Client
7
9
  class << self
8
- def get(path, payload = {})
9
- request_payload = default_payload.merge(payload)
10
+ def get(path, params: {})
11
+ request_params = default_params.merge(params)
10
12
  response = RestClient::Request.execute(method: :get, url: api_url(path),
11
- headers: headers.merge(params: request_payload),
13
+ headers: headers.merge(params: request_params),
12
14
  timeout: timeout)
13
15
  JSON.parse(response.body, symbolize_names: true)
14
16
  end
15
17
 
16
- def post(path, payload = {})
18
+ def post(path, params: {}, payload: {})
19
+ request_params = default_params.merge(params)
20
+ request_payload = default_payload.merge(payload)
21
+ idempotency_key = nonce
22
+ response = with_retries(:max_tries => 1, :rescue => [RestClient::BadRequest, RestClient::BadGateway, RestClient::ServiceUnavailable, RestClient::GatewayTimeout]) do
23
+ RestClient::Request.execute(method: :post, url: api_url(path),
24
+ params: request_params,
25
+ headers: headers.merge({Idempotency_Key: idempotency_key}).merge(params: request_params),
26
+ timeout: timeout,
27
+ payload: request_payload.to_json)
28
+ end
29
+ JSON.parse(response.body, symbolize_names: true)
30
+ end
31
+
32
+ def put(path, params: {}, payload: {})
33
+ request_params = default_params.merge(params).merge({'Idempotency-Key': nonce})
17
34
  request_payload = default_payload.merge(payload)
18
- response = RestClient::Request.execute(method: :post, url: api_url(path), headers: headers, timeout: timeout,
19
- payload: request_payload.to_json)
35
+ idempotency_key = nonce
36
+ response = with_retries(:max_tries => 1, :rescue => [RestClient::InternalServerError, RestClient::BadGateway, RestClient::ServiceUnavailable, RestClient::GatewayTimeout]) do
37
+ RestClient::Request.execute(method: :put, url: api_url(path),
38
+ params: request_params,
39
+ headers: headers.merge({Idempotency_Key: idempotency_key}).merge(params: request_params),
40
+ timeout: timeout,
41
+ payload: request_payload.to_json)
42
+ end
20
43
  JSON.parse(response.body, symbolize_names: true)
21
44
  end
22
45
 
23
46
  private
24
47
 
48
+ def nonce
49
+ SecureRandom.hex
50
+ end
51
+
25
52
  def api_url(path)
26
53
  "#{Smartpay.configuration.api_url}#{path}"
27
54
  end
@@ -42,12 +69,16 @@ module Smartpay
42
69
  Smartpay.configuration.secret_key
43
70
  end
44
71
 
45
- def default_payload
72
+ def default_params
46
73
  {
47
74
  'dev-lang': :ruby,
48
75
  'sdk-version': Smartpay::VERSION
49
76
  }.freeze
50
77
  end
78
+
79
+ def default_payload
80
+ {}.freeze
81
+ end
51
82
  end
52
83
  end
53
84
  end
@@ -30,6 +30,7 @@ module Smartpay
30
30
  amount: payload.dig(:amount),
31
31
  currency: payload.dig(:currency),
32
32
  reference: payload.dig(:reference),
33
+ cancelRemainder: payload.dig(:cancel_remainder),
33
34
  description: payload.dig(:description),
34
35
  metadata: payload.dig(:metadata) || {},
35
36
  }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Smartpay
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.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.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Smartpay
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-10 00:00:00.000000000 Z
11
+ date: 2022-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  - !ruby/object:Gem::Version
94
94
  version: '0'
95
95
  requirements: []
96
- rubygems_version: 3.2.32
96
+ rubygems_version: 3.3.7
97
97
  signing_key:
98
98
  specification_version: 4
99
99
  summary: The Smartpay Ruby SDK offers easy access to Smartpay API from applications