mandarin-api 0.0.3 → 0.0.4

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
  SHA1:
3
- metadata.gz: e82917fcfb1de6c137305c01795d5809427c6d28
4
- data.tar.gz: 9eca43e46586b76d79c1d12c467a60c05163175d
3
+ metadata.gz: 9a6ae4c3a5ebe5e9a08ea002ed1d93c42d72432d
4
+ data.tar.gz: 9eb2052849656b16cc2c54af1f4f57c2ab4eae19
5
5
  SHA512:
6
- metadata.gz: ba82ccce25ca6336cf4a6979f08dc99dfde9e125f09416534856a80862cc27c15afb55b5fe6818d0188f2bae0e8d4f5f48747e2818037e3affec6beae084f1e7
7
- data.tar.gz: 34150934e997cfba3ab2f4ac0ede94f85eadfc02a2a808949d294967ffa0b0c62de71f6e9a89dafeac7c1beed51647a5ea4b451e5d3aec0213b3a421bd020a30
6
+ metadata.gz: ff7b51c2a95501e21272ee44e861da921d9cddca993d9a139bec5823e78d63ee2e3bec22d80c390f08cf5370f2274ad84f9aa08498edfe2457a80697850febe3
7
+ data.tar.gz: 9df49f1d4a9d2c99bea8f28fd71276de13399beb2fbf6aa0e020cace04b5d42af0843411c0ebd886937c9ff2018893dfadc0dbe45635602c1673c304bb9081bb
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mandarin-api (0.0.3)
4
+ mandarin-api (0.0.4)
5
5
  rest-client (>= 2.0, < 3.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -68,6 +68,19 @@ MandarinApi.refund(order_id, transaction_uuid)
68
68
  { 'id' => '721a5185314740aaa304278fb1d8ee63' }
69
69
  ```
70
70
 
71
+ ###**Example of performing rebill:**
72
+ ```ruby
73
+ # order_id - id of order/bill, etc. in your system.
74
+ # amount - sum of payment
75
+ # transaction_uuid - the uuid you received performing transaction
76
+ MandarinApi.rebill(order_id, amount, transaction_uuid)
77
+ ```
78
+ `#rebill` will return a hash with transaction id.
79
+ ###**Example:**
80
+ ```ruby
81
+ { 'id' => '721a5185314740aaa304278fb1d8ee63' }
82
+ ```
83
+
71
84
 
72
85
  You will have to provide a link to receive callbacks from Mandarin.
73
86
  MandarinApi.process_callback takes as arguments body of a callback serialized
data/lib/mandarin_api.rb CHANGED
@@ -29,6 +29,14 @@ module MandarinApi
29
29
  MandarinApi::PaymentManager.new.perform_refund params
30
30
  end
31
31
 
32
+ def self.rebill(order_id, amount, transaction_uuid)
33
+ params = {
34
+ order_id: order_id, amount: amount,
35
+ transaction_uuid: transaction_uuid
36
+ }
37
+ MandarinApi::PaymentManager.new.perform_rebill params
38
+ end
39
+
32
40
  def self.process_callback(request_params, response_handler)
33
41
  response = MandarinApi::Responder.new.process(request_params)
34
42
  response_handler.success(response.data) if response.success
@@ -14,6 +14,10 @@ module MandarinApi
14
14
  perform(params, 'reversal', :refund_request_body)
15
15
  end
16
16
 
17
+ def perform_rebill(params)
18
+ perform(params, 'pay', :rebill_request_body)
19
+ end
20
+
17
21
  private
18
22
 
19
23
  def perform(params, action, body)
@@ -25,9 +29,7 @@ module MandarinApi
25
29
 
26
30
  def normal_request_body(params, action)
27
31
  {
28
- payment: {
29
- order_id: params[:order_id], action: action, price: params[:amount]
30
- },
32
+ payment: payment(params, action),
31
33
  target: { card: params[:assigned_card_uuid] }
32
34
  }
33
35
  end
@@ -38,5 +40,16 @@ module MandarinApi
38
40
  target: { transaction: params[:transaction_uuid] }
39
41
  }
40
42
  end
43
+
44
+ def rebill_request_body(params, action)
45
+ {
46
+ payment: payment(params, action),
47
+ target: { rebill: params[:transaction_uuid] }
48
+ }
49
+ end
50
+
51
+ def payment(params, action)
52
+ { order_id: params[:order_id], action: action, price: params[:amount] }
53
+ end
41
54
  end
42
55
  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.3'
4
+ s.version = '0.0.4'
5
5
  s.authors = ['Vladimir Bogaevsky', 'Boris Kraportov']
6
6
  s.email = 'gitvbogaevsky@gmail.com'
7
7
  s.licenses = ['MIT']
@@ -69,4 +69,30 @@ RSpec.describe MandarinApi::PaymentManager do
69
69
  payment_manager.perform_refund params
70
70
  end
71
71
  end
72
+
73
+ describe '#perform_rebill' do
74
+ let(:rebill_request_body) do
75
+ {
76
+ payment: { order_id: 123_321, action: 'pay', price: 35_000 },
77
+ target: { rebill: '43913ddc000c4d3990fddbd3980c1725' }
78
+ }
79
+ end
80
+ let(:params) do
81
+ {
82
+ order_id: 123_321, amount: 35_000,
83
+ transaction_uuid: '43913ddc000c4d3990fddbd3980c1725'
84
+ }
85
+ end
86
+ it 'calls wrapper instance with args' do
87
+ allow(MandarinApi).to \
88
+ receive_message_chain(:config, :merchant_id).and_return(merchant_id)
89
+ allow(MandarinApi).to \
90
+ receive_message_chain(:config, :secret).and_return(merchant_id)
91
+ allow_any_instance_of(MandarinApi::Wrapper).to receive(:request)
92
+ .with('/api/transactions', rebill_request_body)
93
+ expect_any_instance_of(MandarinApi::Wrapper).to receive(:request)
94
+ .with('/api/transactions', rebill_request_body)
95
+ payment_manager.perform_rebill params
96
+ end
97
+ end
72
98
  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.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Bogaevsky