mandarin-api 0.0.9 → 0.0.10

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: 7a840b7956e5c3de1badf990f212d38815b48ac3
4
- data.tar.gz: 91b7d086c1e8df744c9d498479d7d38068aeaef1
3
+ metadata.gz: b0cc4f937ed0ff217d1bbc45f7c4e093939f52b9
4
+ data.tar.gz: 21987910a33fa8cd06069b2165db455a06ac829b
5
5
  SHA512:
6
- metadata.gz: f44e66aedf219a8856c71b736a32423098384b93e602ef8dfea611acfaa822f52b1589562e61e71e13016eb8a6b7c18d4f06740bd5cc97f10445db3ba0121345
7
- data.tar.gz: b258a6dc443d3bb979068eacb3f0deec2e235edb439a6fb1de0b2a38af7466a1bbc9e3988037b5e8377394988dc370a9c311921b59a5ee1f3fb3e78b2740bd27
6
+ metadata.gz: 0d019fc0d93105b39b98b9f8663fee60cf8ed3bdbd8e22de9fd298957710a7ba8ee792057095ba26f7b7487f2f09ef8762b63d973ebf7aaf8b3fa2f4a33e9472
7
+ data.tar.gz: 041f932ba4061b457fbbce2e8d85c34a871ea9a081540fa6bc5675c467333ce97fbd579aaaf024585b9fb133e531d2d46b68a59242e326da6d2930ee39865703
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mandarin-api (0.0.9)
4
+ mandarin-api (0.0.10)
5
5
  rest-client (>= 2.0, < 3.0)
6
6
 
7
7
  GEM
@@ -92,4 +92,4 @@ DEPENDENCIES
92
92
  webmock (~> 2.1)
93
93
 
94
94
  BUNDLED WITH
95
- 1.12.5
95
+ 1.13.6
data/README.md CHANGED
@@ -73,6 +73,17 @@ MandarinApi.payout(order_id, amount, assigned_card_uuid)
73
73
  { 'id' => '721a5185314740aaa304278fb1d8ee63' }
74
74
  ```
75
75
 
76
+ ###**Example of charging user without card binding**
77
+ ```ruby
78
+ # order_id - id of order/bill, etc. in your system.
79
+ # amount - sum of payout
80
+ MandarinApi.charge(order_id, amount, user)
81
+ ```
82
+ `user` should be an instance or a Struct, and should respond to `#email` and `#phone` methods
83
+ `#phone` should be serialized, for example '+79091234567' is correctly serialized number.
84
+ `#assign_card` will return a hash.
85
+
86
+
76
87
  ###**Example of performing refund:**
77
88
  ```ruby
78
89
  # order_id - id of order/bill, etc. in your system.
data/lib/mandarin_api.rb CHANGED
@@ -13,6 +13,13 @@ module MandarinApi
13
13
  MandarinApi::CardManager.new.one_side_assign_card user, card
14
14
  end
15
15
 
16
+ def self.charge(order_id, amount, user)
17
+ params = {
18
+ order_id: order_id, amount: amount, email: user.email, phone: user.phone
19
+ }
20
+ MandarinApi::PaymentManager.new.perform_charge params
21
+ end
22
+
16
23
  def self.pay(order_id, amount, assigned_card_uuid)
17
24
  params = {
18
25
  order_id: order_id, amount: amount,
@@ -2,6 +2,10 @@
2
2
  module MandarinApi
3
3
  # Pergorms payouts and payins
4
4
  class PaymentManager
5
+ def perform_charge(params)
6
+ perform(params, 'pay', :charge_request_body)
7
+ end
8
+
5
9
  def perform_payout(params)
6
10
  perform(params, 'payout', :normal_request_body)
7
11
  end
@@ -17,7 +21,7 @@ module MandarinApi
17
21
  def perform_rebill(params)
18
22
  perform(params, 'pay', :rebill_request_body)
19
23
  end
20
-
24
+
21
25
  private
22
26
 
23
27
  def perform(params, action, body)
@@ -34,6 +38,14 @@ module MandarinApi
34
38
  }
35
39
  end
36
40
 
41
+ def charge_request_body(params, action)
42
+ {
43
+ payment: payment(params, action),
44
+ customer_info: { email: params[:email], phone: params[:phone] },
45
+ custom_values: []
46
+ }
47
+ end
48
+
37
49
  def refund_request_body(params, action)
38
50
  {
39
51
  payment: { order_id: params[:order_id], action: action },
data/mandarin-api.gemspec CHANGED
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
  Gem::Specification.new do |s|
3
3
  s.name = 'mandarin-api'
4
- s.version = '0.0.9'
5
- s.authors = ['Vladimir Bogaevsky', 'Boris Kraportov']
4
+ s.version = '0.0.10'
5
+ s.authors = ['Vladimir Bogaevsky']
6
6
  s.email = 'gitvbogaevsky@gmail.com'
7
7
  s.licenses = ['MIT']
8
8
  s.summary = 'mandarinpay.com api wrapper for ruby'
@@ -15,6 +15,36 @@ RSpec.describe MandarinApi::PaymentManager do
15
15
  target: { card: '0eb51e74-e704-4c36-b5cb-8f0227621518' }
16
16
  }
17
17
  end
18
+ let(:charge_request_body) do
19
+ {
20
+ payment: { order_id: 123_321, action: action, price: 35_000 },
21
+ customer_info: { email: email, phone: phone },
22
+ custom_values: []
23
+ }
24
+ end
25
+ describe '#perform_charge' do
26
+ let(:email) { Faker::Internet.free_email }
27
+ let(:phone) { "+7#{Faker::Number.between(100_000_000, 999_999_999)}" }
28
+ let(:action) { 'pay' }
29
+ let(:params) do
30
+ {
31
+ order_id: 123_321, amount: 35_000,
32
+ email: email, phone: phone, custom_values: []
33
+ }
34
+ end
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', charge_request_body)
42
+ expect_any_instance_of(MandarinApi::Wrapper).to receive(:request)
43
+ .with('/api/transactions', charge_request_body)
44
+ payment_manager.perform_charge params
45
+ end
46
+ end
47
+
18
48
  describe '#perform_payout' do
19
49
  let(:action) { 'payout' }
20
50
  it 'calls wrapper instance with args' do
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mandarin-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Bogaevsky
8
- - Boris Kraportov
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2016-11-02 00:00:00.000000000 Z
11
+ date: 2016-12-07 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: webmock