mandarin-api 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6f71dbf499f89bd7b5e57c3f2d08fafbe72eb640
4
- data.tar.gz: 44df666a2b13a8f9c4f6aa084e18a12ced5afeff
3
+ metadata.gz: e82917fcfb1de6c137305c01795d5809427c6d28
4
+ data.tar.gz: 9eca43e46586b76d79c1d12c467a60c05163175d
5
5
  SHA512:
6
- metadata.gz: b3f55d18a9f8a1c7219e161a67e307480d0a17ab76b820387b0cdcb49a248ba35a0da4fde98930534eb58d2a07a7be3eb948406a2bfa9779339163229c75cc75
7
- data.tar.gz: e167e4abe4e2a7461b8d36ea741f802a8cdb5527a27d80c226de905fea97571164fd8d2726b56ac257f4fb62059048feaef530d1ecd7411725bc392f4dcafea6
6
+ metadata.gz: ba82ccce25ca6336cf4a6979f08dc99dfde9e125f09416534856a80862cc27c15afb55b5fe6818d0188f2bae0e8d4f5f48747e2818037e3affec6beae084f1e7
7
+ data.tar.gz: 34150934e997cfba3ab2f4ac0ede94f85eadfc02a2a808949d294967ffa0b0c62de71f6e9a89dafeac7c1beed51647a5ea4b451e5d3aec0213b3a421bd020a30
data/Gemfile.lock CHANGED
@@ -1,8 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mandarin-api (0.0.2)
5
- dry-configurable (>= 0.1.0, < 1.0)
4
+ mandarin-api (0.0.3)
6
5
  rest-client (>= 2.0, < 3.0)
7
6
 
8
7
  GEM
@@ -11,14 +10,11 @@ GEM
11
10
  addressable (2.4.0)
12
11
  ast (2.3.0)
13
12
  coderay (1.1.1)
14
- concurrent-ruby (1.0.2)
15
13
  crack (0.4.3)
16
14
  safe_yaml (~> 1.0.0)
17
15
  diff-lcs (1.2.5)
18
16
  domain_name (0.5.20160826)
19
17
  unf (>= 0.0.5, < 1.0.0)
20
- dry-configurable (0.1.7)
21
- concurrent-ruby (~> 1.0)
22
18
  faker (1.6.6)
23
19
  i18n (~> 0.5)
24
20
  hashdiff (0.3.0)
data/README.md CHANGED
@@ -37,7 +37,7 @@ Keep id, it will be used for pay/payouts requests. Use userWebLink to redirect u
37
37
  # assigned_card_uuid - the id you received assigning the card
38
38
  MandarinApi.payment(order_id, amount, assigned_card_uuid)
39
39
  ```
40
- #payout will return a hash with transaction id.
40
+ `#payment` will return a hash with transaction id.
41
41
  ###**Example:**
42
42
  ```ruby
43
43
  { 'id' => '721a5185314740aaa304278fb1d8ee63' }
@@ -50,11 +50,25 @@ MandarinApi.payment(order_id, amount, assigned_card_uuid)
50
50
  # assigned_card_uuid - the id you received assigning the card
51
51
  MandarinApi.payout(order_id, amount, assigned_card_uuid)
52
52
  ```
53
- #payout will return a hash with transaction id.
53
+ `#payout` will return a hash with transaction id.
54
54
  ###**Example:**
55
55
  ```ruby
56
56
  { 'id' => '721a5185314740aaa304278fb1d8ee63' }
57
57
  ```
58
+
59
+ ###**Example of performing refund:**
60
+ ```ruby
61
+ # order_id - id of order/bill, etc. in your system.
62
+ # transaction_uuid - the uuid you received performing transaction
63
+ MandarinApi.refund(order_id, transaction_uuid)
64
+ ```
65
+ `#refund` will return a hash with transaction id.
66
+ ###**Example:**
67
+ ```ruby
68
+ { 'id' => '721a5185314740aaa304278fb1d8ee63' }
69
+ ```
70
+
71
+
58
72
  You will have to provide a link to receive callbacks from Mandarin.
59
73
  MandarinApi.process_callback takes as arguments body of a callback serialized
60
74
  to hash with symbolized keys and an instance with `#success` and `#failure` methods,
data/lib/mandarin_api.rb CHANGED
@@ -1,6 +1,4 @@
1
1
  # frozen_string_literal: true
2
-
3
- require 'dry-configurable'
4
2
  # Main module
5
3
  module MandarinApi
6
4
  class << self
@@ -26,6 +24,11 @@ module MandarinApi
26
24
  MandarinApi::PaymentManager.new.perform_payout params
27
25
  end
28
26
 
27
+ def self.refund(order_id, transaction_uuid)
28
+ params = { order_id: order_id, transaction_uuid: transaction_uuid }
29
+ MandarinApi::PaymentManager.new.perform_refund params
30
+ end
31
+
29
32
  def self.process_callback(request_params, response_handler)
30
33
  response = MandarinApi::Responder.new.process(request_params)
31
34
  response_handler.success(response.data) if response.success
@@ -3,30 +3,39 @@ module MandarinApi
3
3
  # Pergorms payouts and payins
4
4
  class PaymentManager
5
5
  def perform_payout(params)
6
- perform(params, 'payout')
6
+ perform(params, 'payout', :normal_request_body)
7
7
  end
8
8
 
9
9
  def perform_payment(params)
10
- perform(params, 'pay')
10
+ perform(params, 'pay', :normal_request_body)
11
+ end
12
+
13
+ def perform_refund(params)
14
+ perform(params, 'reversal', :refund_request_body)
11
15
  end
12
16
 
13
17
  private
14
18
 
15
- def perform(params, action)
19
+ def perform(params, action, body)
16
20
  MandarinApi::Wrapper.new(
17
21
  merchant_id: MandarinApi.config.merchant_id,
18
22
  secret: MandarinApi.config.secret
19
- ).request('/api/transactions', request_body(params, action))
23
+ ).request('/api/transactions', send(body, params, action))
20
24
  end
21
25
 
22
- def request_body(params, action)
26
+ def normal_request_body(params, action)
23
27
  {
24
28
  payment: {
25
29
  order_id: params[:order_id], action: action, price: params[:amount]
26
30
  },
27
- target: {
28
- card: params[:assigned_card_uuid]
29
- }
31
+ target: { card: params[:assigned_card_uuid] }
32
+ }
33
+ end
34
+
35
+ def refund_request_body(params, action)
36
+ {
37
+ payment: { order_id: params[:order_id], action: action },
38
+ target: { transaction: params[:transaction_uuid] }
30
39
  }
31
40
  end
32
41
  end
data/mandarin-api.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  Gem::Specification.new do |s|
3
3
  s.name = 'mandarin-api'
4
- s.version = '0.0.2'
4
+ s.version = '0.0.3'
5
5
  s.authors = ['Vladimir Bogaevsky', 'Boris Kraportov']
6
6
  s.email = 'gitvbogaevsky@gmail.com'
7
7
  s.licenses = ['MIT']
@@ -21,7 +21,6 @@ Gem::Specification.new do |s|
21
21
  s.add_development_dependency('faker', '>= 1.6', '< 1.7')
22
22
 
23
23
  s.add_dependency 'rest-client', '>= 2.0', '< 3.0'
24
- s.add_dependency 'dry-configurable', '>= 0.1.0', '< 1.0'
25
24
 
26
25
  s.required_ruby_version = '>= 2.2.0'
27
26
  end
@@ -9,7 +9,7 @@ RSpec.describe MandarinApi::PaymentManager do
9
9
  assigned_card_uuid: '0eb51e74-e704-4c36-b5cb-8f0227621518'
10
10
  }
11
11
  end
12
- let(:request_body) do
12
+ let(:normal_request_body) do
13
13
  {
14
14
  payment: { order_id: 123_321, action: action, price: 35_000 },
15
15
  target: { card: '0eb51e74-e704-4c36-b5cb-8f0227621518' }
@@ -23,9 +23,9 @@ RSpec.describe MandarinApi::PaymentManager do
23
23
  allow(MandarinApi).to \
24
24
  receive_message_chain(:config, :secret).and_return(merchant_id)
25
25
  allow_any_instance_of(MandarinApi::Wrapper).to receive(:request)
26
- .with('/api/transactions', request_body)
26
+ .with('/api/transactions', normal_request_body)
27
27
  expect_any_instance_of(MandarinApi::Wrapper).to receive(:request)
28
- .with('/api/transactions', request_body)
28
+ .with('/api/transactions', normal_request_body)
29
29
  payment_manager.perform_payout params
30
30
  end
31
31
  end
@@ -38,10 +38,35 @@ RSpec.describe MandarinApi::PaymentManager do
38
38
  allow(MandarinApi).to \
39
39
  receive_message_chain(:config, :secret).and_return(merchant_id)
40
40
  allow_any_instance_of(MandarinApi::Wrapper).to receive(:request)
41
- .with('/api/transactions', request_body)
41
+ .with('/api/transactions', normal_request_body)
42
42
  expect_any_instance_of(MandarinApi::Wrapper).to receive(:request)
43
- .with('/api/transactions', request_body)
43
+ .with('/api/transactions', normal_request_body)
44
44
  payment_manager.perform_payment params
45
45
  end
46
46
  end
47
+
48
+ describe '#perform_refund' do
49
+ let(:refund_request_body) do
50
+ {
51
+ payment: { order_id: 123_321, action: 'reversal' },
52
+ target: { transaction: '43913ddc000c4d3990fddbd3980c1725' }
53
+ }
54
+ end
55
+ let(:params) do
56
+ {
57
+ order_id: 123_321, transaction_uuid: '43913ddc000c4d3990fddbd3980c1725'
58
+ }
59
+ end
60
+ it 'calls wrapper instance with args' do
61
+ allow(MandarinApi).to \
62
+ receive_message_chain(:config, :merchant_id).and_return(merchant_id)
63
+ allow(MandarinApi).to \
64
+ receive_message_chain(:config, :secret).and_return(merchant_id)
65
+ allow_any_instance_of(MandarinApi::Wrapper).to receive(:request)
66
+ .with('/api/transactions', refund_request_body)
67
+ expect_any_instance_of(MandarinApi::Wrapper).to receive(:request)
68
+ .with('/api/transactions', refund_request_body)
69
+ payment_manager.perform_refund params
70
+ end
71
+ end
47
72
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mandarin-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Bogaevsky
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-10-21 00:00:00.000000000 Z
12
+ date: 2016-10-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: webmock
@@ -141,26 +141,6 @@ dependencies:
141
141
  - - "<"
142
142
  - !ruby/object:Gem::Version
143
143
  version: '3.0'
144
- - !ruby/object:Gem::Dependency
145
- name: dry-configurable
146
- requirement: !ruby/object:Gem::Requirement
147
- requirements:
148
- - - ">="
149
- - !ruby/object:Gem::Version
150
- version: 0.1.0
151
- - - "<"
152
- - !ruby/object:Gem::Version
153
- version: '1.0'
154
- type: :runtime
155
- prerelease: false
156
- version_requirements: !ruby/object:Gem::Requirement
157
- requirements:
158
- - - ">="
159
- - !ruby/object:Gem::Version
160
- version: 0.1.0
161
- - - "<"
162
- - !ruby/object:Gem::Version
163
- version: '1.0'
164
144
  description:
165
145
  email: gitvbogaevsky@gmail.com
166
146
  executables: []