mandarin-api 0.0.1 → 0.0.2

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: 15f0096f101bdda10a4a47882006909f52ef444f
4
- data.tar.gz: b4fa4f3db47d56941cb6f4e3f5dfd4bed2585c46
3
+ metadata.gz: 6f71dbf499f89bd7b5e57c3f2d08fafbe72eb640
4
+ data.tar.gz: 44df666a2b13a8f9c4f6aa084e18a12ced5afeff
5
5
  SHA512:
6
- metadata.gz: 2be9a637c30f3b11e8e22de6de3b0e22c2f3c9816709e23431d26be138aedc65a6c31ad2c8aeca7b0c04cd2a097c4057722f650ab256d0d29f6699d824b9765c
7
- data.tar.gz: 60c27b365ca7db424245972da36f246ac8bb34605c5008f8384587e6049782be68c1886cd665b842fa625b2c0b3f7a5ac33ab9ce6f79add886b5d17e885e2bee
6
+ metadata.gz: b3f55d18a9f8a1c7219e161a67e307480d0a17ab76b820387b0cdcb49a248ba35a0da4fde98930534eb58d2a07a7be3eb948406a2bfa9779339163229c75cc75
7
+ data.tar.gz: e167e4abe4e2a7461b8d36ea741f802a8cdb5527a27d80c226de905fea97571164fd8d2726b56ac257f4fb62059048feaef530d1ecd7411725bc392f4dcafea6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mandarin-api (0.0.1)
4
+ mandarin-api (0.0.2)
5
5
  dry-configurable (>= 0.1.0, < 1.0)
6
6
  rest-client (>= 2.0, < 3.0)
7
7
 
data/README.md CHANGED
@@ -1,11 +1,12 @@
1
1
  # mandarin-api-rb
2
- mandarinpay.com api wrapper for ruby
3
2
  [![CodeClimate](https://codeclimate.com/github/vbogaevsky/mandarin-api-rb/badges/gpa.svg)](https://codeclimate.com/github/vbogaevsky/mandarin-api-rb)
3
+
4
+ mandarinpay.com api wrapper for ruby
4
5
  **mandarin-api** provides necessary API to interact with **Mandarin**.
5
6
  ##**Usage:**
6
7
  To use mandarin-api you will need to specify config file with `merchant_id`, `secret`, and `request_url`.
7
8
  ###**Example of config:**
8
- ```
9
+ ```ruby
9
10
  MandarinApi.configure do |config|
10
11
  config.merchant_id = 123
11
12
  config.secret = 'secret'
@@ -13,14 +14,14 @@ MandarinApi.configure do |config|
13
14
  end
14
15
  ```
15
16
  ###**Example of assigning a card:**
16
- ```
17
+ ```ruby
17
18
  MandarinApi.assign_card user
18
19
  ```
19
20
  `user` should be an instance or a Struct, and should respond to `#email` and `#phone` methods
20
21
  `#phone` should be serialized, for example '+79091234567' is correctly serialized number.
21
22
  `#assign_card` will return a hash.
22
23
  ###**Example:**
23
- ```
24
+ ```ruby
24
25
  {
25
26
  'id' => '0eb51e74-e704-4c36-b5cb-8f0227621518',
26
27
  'userWebLink' => "https://secure.mandarinpay.com/CardBindings/New?' \
@@ -29,8 +30,21 @@ MandarinApi.assign_card user
29
30
  ```
30
31
  Keep id, it will be used for pay/payouts requests. Use userWebLink to redirect user to Mandarin page for card data input.
31
32
 
32
- ###**Example of performing payout:**
33
+ ###**Example of performing payment:**
34
+ ```ruby
35
+ # order_id - id of order/bill, etc. in your system.
36
+ # amount - sum of payout
37
+ # assigned_card_uuid - the id you received assigning the card
38
+ MandarinApi.payment(order_id, amount, assigned_card_uuid)
39
+ ```
40
+ #payout will return a hash with transaction id.
41
+ ###**Example:**
42
+ ```ruby
43
+ { 'id' => '721a5185314740aaa304278fb1d8ee63' }
33
44
  ```
45
+
46
+ ###**Example of performing payout:**
47
+ ```ruby
34
48
  # order_id - id of order/bill, etc. in your system.
35
49
  # amount - sum of payout
36
50
  # assigned_card_uuid - the id you received assigning the card
@@ -38,7 +52,7 @@ MandarinApi.payout(order_id, amount, assigned_card_uuid)
38
52
  ```
39
53
  #payout will return a hash with transaction id.
40
54
  ###**Example:**
41
- ```
55
+ ```ruby
42
56
  { 'id' => '721a5185314740aaa304278fb1d8ee63' }
43
57
  ```
44
58
  You will have to provide a link to receive callbacks from Mandarin.
@@ -46,7 +60,7 @@ MandarinApi.process_callback takes as arguments body of a callback serialized
46
60
  to hash with symbolized keys and an instance with `#success` and `#failure` methods,
47
61
  `#success` and `#failure` methods should take hash with symbolized keys as an argument.
48
62
  ###**Example:**
49
- ```
63
+ ```ruby
50
64
  class Application
51
65
  def assign_card(user)
52
66
  MandarinApi.assign_card(user)
data/lib/mandarin_api.rb CHANGED
@@ -10,8 +10,12 @@ module MandarinApi
10
10
  MandarinApi::CardManager.new.assign_card user
11
11
  end
12
12
 
13
- def self.pay(_client, _amount)
14
- # call api
13
+ def self.pay(order_id, amount, assigned_card_uuid)
14
+ params = {
15
+ order_id: order_id, amount: amount,
16
+ assigned_card_uuid: assigned_card_uuid
17
+ }
18
+ MandarinApi::PaymentManager.new.perform_payment params
15
19
  end
16
20
 
17
21
  def self.payout(order_id, amount, assigned_card_uuid)
@@ -3,17 +3,26 @@ module MandarinApi
3
3
  # Pergorms payouts and payins
4
4
  class PaymentManager
5
5
  def perform_payout(params)
6
- MandarinApi::Wrapper.new(merchant_id: MandarinApi.config.merchant_id,
7
- secret: MandarinApi.config.secret)
8
- .request('/api/transactions', reques_body(params))
6
+ perform(params, 'payout')
7
+ end
8
+
9
+ def perform_payment(params)
10
+ perform(params, 'pay')
9
11
  end
10
12
 
11
13
  private
12
14
 
13
- def reques_body(params)
15
+ def perform(params, action)
16
+ MandarinApi::Wrapper.new(
17
+ merchant_id: MandarinApi.config.merchant_id,
18
+ secret: MandarinApi.config.secret
19
+ ).request('/api/transactions', request_body(params, action))
20
+ end
21
+
22
+ def request_body(params, action)
14
23
  {
15
24
  payment: {
16
- order_id: params[:order_id], action: 'payout', price: params[:amount]
25
+ order_id: params[:order_id], action: action, price: params[:amount]
17
26
  },
18
27
  target: {
19
28
  card: params[:assigned_card_uuid]
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.1'
4
+ s.version = '0.0.2'
5
5
  s.authors = ['Vladimir Bogaevsky', 'Boris Kraportov']
6
6
  s.email = 'gitvbogaevsky@gmail.com'
7
7
  s.licenses = ['MIT']
@@ -1,21 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
  RSpec.describe MandarinApi::PaymentManager do
3
+ let(:payment_manager) { MandarinApi::PaymentManager.new }
4
+ let(:merchant_id) { 234 }
5
+ let(:secret) { 'secret' }
6
+ let(:params) do
7
+ {
8
+ order_id: 123_321, amount: 35_000,
9
+ assigned_card_uuid: '0eb51e74-e704-4c36-b5cb-8f0227621518'
10
+ }
11
+ end
12
+ let(:request_body) do
13
+ {
14
+ payment: { order_id: 123_321, action: action, price: 35_000 },
15
+ target: { card: '0eb51e74-e704-4c36-b5cb-8f0227621518' }
16
+ }
17
+ end
3
18
  describe '#perform_payout' do
4
- let(:payment_manager) { MandarinApi::PaymentManager.new }
5
- let(:merchant_id) { 234 }
6
- let(:secret) { 'secret' }
7
- let(:params) do
8
- {
9
- order_id: 123_321, amount: 35_000,
10
- assigned_card_uuid: '0eb51e74-e704-4c36-b5cb-8f0227621518'
11
- }
12
- end
13
- let(:request_body) do
14
- {
15
- payment: { order_id: 123_321, action: 'payout', price: 35_000 },
16
- target: { card: '0eb51e74-e704-4c36-b5cb-8f0227621518' }
17
- }
18
- end
19
+ let(:action) { 'payout' }
19
20
  it 'calls wrapper instance with args' do
20
21
  allow(MandarinApi).to \
21
22
  receive_message_chain(:config, :merchant_id).and_return(merchant_id)
@@ -28,4 +29,19 @@ RSpec.describe MandarinApi::PaymentManager do
28
29
  payment_manager.perform_payout params
29
30
  end
30
31
  end
32
+
33
+ describe '#perform_payment' do
34
+ let(:action) { 'pay' }
35
+ it 'calls wrapper instance with args' do
36
+ allow(MandarinApi).to \
37
+ receive_message_chain(:config, :merchant_id).and_return(merchant_id)
38
+ allow(MandarinApi).to \
39
+ receive_message_chain(:config, :secret).and_return(merchant_id)
40
+ allow_any_instance_of(MandarinApi::Wrapper).to receive(:request)
41
+ .with('/api/transactions', request_body)
42
+ expect_any_instance_of(MandarinApi::Wrapper).to receive(:request)
43
+ .with('/api/transactions', request_body)
44
+ payment_manager.perform_payment params
45
+ end
46
+ end
31
47
  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.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Bogaevsky