privatbank 0.0.1 → 0.0.2

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: f9b16d95ce52d90e7dd14a8f02772d29e9fc134c
4
- data.tar.gz: 15645d623b673158795b30f7bcbbb5989b6772cd
3
+ metadata.gz: 0063d46768ff5ca9bf0530e948e539313369ee26
4
+ data.tar.gz: 13675dcfd167fc5664958bc9ada847d46eb3a178
5
5
  SHA512:
6
- metadata.gz: b85d5627ede60a681f259c790903e114f4c7131b29ea36701239cb9776f33f81f7aaead4d7659bd4be4598773b25429772dd9ea2f84f0d2113e2a6597863d64d
7
- data.tar.gz: 3a456126a87f16075ee9f49d7a7dd692adbcfe8bd3a02ad84db1818a9e363f09f29ce66b31ec5dfdadc50e176044527824d67db8b1cb2089e37f5284490bffb5
6
+ metadata.gz: 08c9aa382565f5cc43161e435cd2cfa757807920bff70a28bef2f2c176ad1bbc5c44a847dea6a48bff6002ff9480a7830b10563b8e4b834ac8634554c79834c0
7
+ data.tar.gz: 0b508526e889b1885ba3305935a6a1a9e56353814d2c976888844bf702c1910d59951bf12a1c4a93b3f417d6b15ccddc55f99f2b4790aa4fb7e5d6541af662f2
data/README.md CHANGED
@@ -75,6 +75,50 @@ Privatbank::P24::ExchangeRates.card
75
75
  # {"ccy"=>"USD", "base_ccy"=>"UAH", "buy"=>"15.09624", "sale"=>"15.09624"}]
76
76
  ```
77
77
 
78
+ #### Send money
79
+
80
+ For sending money to privatbank/visa cards:
81
+
82
+ ```ruby
83
+ require 'privatbank/p24'
84
+
85
+ receiver = '1111222233334444'
86
+ full_name = 'Some Full Name' #only for visa cards
87
+ payment_id = '12345'
88
+ amount = 100
89
+ currency = 'UAH' #optional
90
+ details = 'some-details'
91
+
92
+ Privatbank::P24.send_money_pb(receiver, payment_id, amount, details)
93
+ Privatbank::P24.send_money_visa(receiver, full_name, payment_id, amount, details)
94
+ ```
95
+
96
+ #### Payment status
97
+
98
+ For obtaining payment current state:
99
+
100
+ ```ruby
101
+ require 'privatbank/p24'
102
+
103
+ payment_id = 'some-id'
104
+ ref = 'P123451234512341'
105
+
106
+ Privatbank::P24.payment_status(payment_id, ref)
107
+ ```
108
+
109
+ #### Card info
110
+
111
+ For obtaining balance and other information:
112
+
113
+ ```ruby
114
+ require 'privatbank/p24'
115
+
116
+ card_number = '1111222233334444'
117
+ country = 'UA' #optional
118
+
119
+ Privatbank::P24.info(card_number)
120
+ ```
121
+
78
122
  ## Contributing
79
123
 
80
124
  1. Fork it ( https://github.com/greshny/privatbank/fork )
@@ -0,0 +1,65 @@
1
+ require 'date'
2
+ require 'builder'
3
+ require 'privatbank/signature'
4
+ require 'httparty'
5
+
6
+ module Privatbank
7
+ module P24
8
+ class Info
9
+
10
+ include HTTParty
11
+
12
+ base_uri 'https://api.privatbank.ua'
13
+
14
+ def initialize card_number, country, options
15
+ @card_number = card_number
16
+ @country = country
17
+ @merchant_id = options[:merchant_id]
18
+ @merchant_password = options[:merchant_password]
19
+ end
20
+
21
+ def request
22
+ response = self.class.post('/p24api/balance', body: outgoing_xml)
23
+ response['error'] || response['response']['data']['info']['cardbalance']
24
+ end
25
+
26
+ def outgoing_xml
27
+ builder = Builder::XmlMarkup.new
28
+ builder.instruct!
29
+ builder.request(version: '1.0') do |req|
30
+ req.merchant do |merch|
31
+ merch.id(@merchant_id)
32
+ merch.signature(signature)
33
+ end
34
+ req.data do |d|
35
+ d.oper('cmt')
36
+ d.wait(0)
37
+ d.test(0)
38
+ d.payment(id: '') do |p|
39
+ p.prop(name: 'cardnum', value: @card_number)
40
+ p.prop(name: 'country', value: @country)
41
+ end
42
+ end
43
+ end
44
+ builder.target!
45
+ end
46
+
47
+ def request_xml_data
48
+ builder = Builder::XmlMarkup.new
49
+ builder.oper('cmt')
50
+ builder.wait(0)
51
+ builder.test(0)
52
+ builder.payment(id: '') do |p|
53
+ p.prop(name: 'cardnum', value: @card_number)
54
+ p.prop(name: 'country', value: @country)
55
+ end
56
+ builder.target!
57
+ end
58
+
59
+ def signature
60
+ Privatbank::Signature.generate(request_xml_data, @merchant_password)
61
+ end
62
+
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,66 @@
1
+ require 'date'
2
+ require 'builder'
3
+ require 'privatbank/signature'
4
+ require 'httparty'
5
+
6
+ module Privatbank
7
+ module P24
8
+ class PaymentStatus
9
+
10
+ include HTTParty
11
+
12
+ base_uri 'https://api.privatbank.ua'
13
+
14
+ def initialize payment_id, ref, options={}
15
+ @payment_id = payment_id
16
+ @ref = ref
17
+ @merchant_id = options[:merchant_id]
18
+ @merchant_password = options[:merchant_password]
19
+ end
20
+
21
+ def request
22
+ response = self.class.post('/p24api/check_pay', body: outgoing_xml)
23
+ return 'error' if response.fetch('error', nil)
24
+ response['response']['data']
25
+ end
26
+
27
+ def outgoing_xml
28
+ builder = Builder::XmlMarkup.new
29
+ builder.instruct!
30
+ builder.request(version: '1.0') do |req|
31
+ req.merchant do |merch|
32
+ merch.id(@merchant_id)
33
+ merch.signature(signature)
34
+ end
35
+ req.data do |d|
36
+ d.oper('cmt')
37
+ d.wait(0)
38
+ d.test(0)
39
+ d.payment(id: @payment_id) do |p|
40
+ p.prop(name: 'id', value: @payment_id)
41
+ p.prop(name: 'ref', value: @ref)
42
+ end
43
+ end
44
+ end
45
+ builder.target!
46
+ end
47
+
48
+ def request_xml_data
49
+ builder = Builder::XmlMarkup.new
50
+ builder.oper('cmt')
51
+ builder.wait(0)
52
+ builder.test(0)
53
+ builder.payment(id: @payment_id) do |p|
54
+ p.prop(name: 'id', value: @payment_id)
55
+ p.prop(name: 'ref', value: @ref)
56
+ end
57
+ builder.target!
58
+ end
59
+
60
+ def signature
61
+ Privatbank::Signature.generate(request_xml_data, @merchant_password)
62
+ end
63
+
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,73 @@
1
+ require 'date'
2
+ require 'builder'
3
+ require 'privatbank/signature'
4
+ require 'httparty'
5
+
6
+ module Privatbank
7
+ module P24
8
+ class SendMoneyPB
9
+
10
+ include HTTParty
11
+
12
+ base_uri 'https://api.privatbank.ua'
13
+
14
+ def initialize receiver, payment_id, amount, currency, details, options
15
+ @receiver = receiver
16
+ @payment_id = payment_id
17
+ @amount = amount
18
+ @details = details
19
+ @currency = currency
20
+ @merchant_id = options[:merchant_id]
21
+ @merchant_password = options[:merchant_password]
22
+ end
23
+
24
+ def request
25
+ response = self.class.post('/p24api/pay_pb', body: outgoing_xml)
26
+ return 'error' if response.fetch('error', nil)
27
+ response['response']['data']
28
+ end
29
+
30
+ def outgoing_xml
31
+ builder = Builder::XmlMarkup.new
32
+ builder.instruct!
33
+ builder.request(version: '1.0') do |req|
34
+ req.merchant do |merch|
35
+ merch.id(@merchant_id)
36
+ merch.signature(signature)
37
+ end
38
+ req.data do |d|
39
+ d.oper('cmt')
40
+ d.wait(0)
41
+ d.test(0)
42
+ d.payment(id: @payment_id) do |p|
43
+ p.prop(name: 'b_card_or_acc', value: @receiver)
44
+ p.prop(name: 'amt', value: @amount)
45
+ p.prop(name: 'ccy', value: @currency)
46
+ p.prop(name: 'details', value: @details)
47
+ end
48
+ end
49
+ end
50
+ builder.target!
51
+ end
52
+
53
+ def request_xml_data
54
+ builder = Builder::XmlMarkup.new
55
+ builder.oper('cmt')
56
+ builder.wait(0)
57
+ builder.test(0)
58
+ builder.payment(id: @payment_id) do |p|
59
+ p.prop(name: 'b_card_or_acc', value: @receiver)
60
+ p.prop(name: 'amt', value: @amount)
61
+ p.prop(name: 'ccy', value: @currency)
62
+ p.prop(name: 'details', value: @details)
63
+ end
64
+ builder.target!
65
+ end
66
+
67
+ def signature
68
+ Privatbank::Signature.generate(request_xml_data, @merchant_password)
69
+ end
70
+
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,76 @@
1
+ require 'date'
2
+ require 'builder'
3
+ require 'privatbank/signature'
4
+ require 'httparty'
5
+
6
+ module Privatbank
7
+ module P24
8
+ class SendMoneyVisa
9
+
10
+ include HTTParty
11
+
12
+ base_uri 'https://api.privatbank.ua'
13
+
14
+ def initialize receiver, full_name, payment_id, amount, currency, details, options
15
+ @receiver = receiver
16
+ @full_name = full_name
17
+ @payment_id = payment_id
18
+ @amount = amount
19
+ @details = details
20
+ @currency = currency
21
+ @merchant_id = options[:merchant_id]
22
+ @merchant_password = options[:merchant_password]
23
+ end
24
+
25
+ def request
26
+ response = self.class.post('/p24api/pay_visa', body: outgoing_xml)
27
+ return 'error' if response.fetch('error', nil)
28
+ response['response']['data']
29
+ end
30
+
31
+ def outgoing_xml
32
+ builder = Builder::XmlMarkup.new
33
+ builder.instruct!
34
+ builder.request(version: '1.0') do |req|
35
+ req.merchant do |merch|
36
+ merch.id(@merchant_id)
37
+ merch.signature(signature)
38
+ end
39
+ req.data do |d|
40
+ d.oper('cmt')
41
+ d.wait(0)
42
+ d.test(0)
43
+ d.payment(id: @payment_id) do |p|
44
+ p.prop(name: 'b_card_or_acc', value: @receiver)
45
+ p.prop(name: 'amt', value: @amount)
46
+ p.prop(name: 'ccy', value: @currency)
47
+ p.prop(name: 'b_name', value: @full_name)
48
+ p.prop(name: 'details', value: @details)
49
+ end
50
+ end
51
+ end
52
+ builder.target!
53
+ end
54
+
55
+ def request_xml_data
56
+ builder = Builder::XmlMarkup.new
57
+ builder.oper('cmt')
58
+ builder.wait(0)
59
+ builder.test(0)
60
+ builder.payment(id: @payment_id) do |p|
61
+ p.prop(name: 'b_card_or_acc', value: @receiver)
62
+ p.prop(name: 'amt', value: @amount)
63
+ p.prop(name: 'ccy', value: @currency)
64
+ p.prop(name: 'b_name', value: @full_name)
65
+ p.prop(name: 'details', value: @details)
66
+ end
67
+ builder.target!
68
+ end
69
+
70
+ def signature
71
+ Privatbank::Signature.generate(request_xml_data, @merchant_password)
72
+ end
73
+
74
+ end
75
+ end
76
+ end
@@ -1,4 +1,8 @@
1
1
  require 'privatbank/p24/account_statement'
2
+ require 'privatbank/p24/send_money_pb'
3
+ require 'privatbank/p24/send_money_visa'
4
+ require 'privatbank/p24/payment_status'
5
+ require 'privatbank/p24/info'
2
6
 
3
7
  module Privatbank
4
8
  module P24
@@ -9,5 +13,29 @@ module Privatbank
9
13
  AccountStatement.new(card_number, options).request
10
14
  end
11
15
 
16
+ def self.send_money_pb receiver, payment_id, amount, details, currency = 'UAH', options = {}
17
+ options.merge!(merchant_id: Privatbank.configuration.merchant_id,
18
+ merchant_password: Privatbank.configuration.merchant_password)
19
+ SendMoneyPB.new(receiver, payment_id, amount, currency, details, options).request
20
+ end
21
+
22
+ def self.send_money_visa receiver, full_name, payment_id, amount, details, currency = 'UAH', options = {}
23
+ options.merge!(merchant_id: Privatbank.configuration.merchant_id,
24
+ merchant_password: Privatbank.configuration.merchant_password)
25
+ SendMoneyVisa.new(receiver, full_name, payment_id, amount, currency, details, options).request
26
+ end
27
+
28
+ def self.info card_number, country = 'UA', options = {}
29
+ options.merge!(merchant_id: Privatbank.configuration.merchant_id,
30
+ merchant_password: Privatbank.configuration.merchant_password)
31
+ Info.new(card_number, country, options).request
32
+ end
33
+
34
+ def self.payment_status payment_id, ref, options = {}
35
+ options.merge!(merchant_id: Privatbank.configuration.merchant_id,
36
+ merchant_password: Privatbank.configuration.merchant_password)
37
+ PaymentStatus.new(payment_id, ref, options).request
38
+ end
39
+
12
40
  end
13
41
  end
@@ -1,3 +1,3 @@
1
1
  module Privatbank
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
data/test/test_p24.rb CHANGED
@@ -24,4 +24,53 @@ class TestP24 < MiniTest::Unit::TestCase
24
24
 
25
25
  VCR.eject_cassette 'account_statement'
26
26
  end
27
+
28
+ def test_send_money_pb
29
+ VCR.insert_cassette 'send_money_pb'
30
+
31
+ receiver = '1111222233334444'
32
+ payment_id = '12345'
33
+ amount = 100
34
+ details = 'some-details'
35
+
36
+ assert_equal true, Privatbank::P24.send_money_pb(receiver, payment_id, amount, details) != ''
37
+
38
+ VCR.eject_cassette 'send_money_pb'
39
+ end
40
+
41
+ def test_send_money_visa
42
+ VCR.insert_cassette 'send_money_visa'
43
+
44
+ receiver = '1111222233334444'
45
+ full_name = 'Some Full Name'
46
+ payment_id = '12345'
47
+ amount = 100
48
+ details = 'some-details'
49
+
50
+ assert_equal true, Privatbank::P24.send_money_visa(receiver, full_name, payment_id, amount, details) != ''
51
+
52
+ VCR.eject_cassette 'send_money_visa'
53
+ end
54
+
55
+ def test_info
56
+ VCR.insert_cassette 'info'
57
+
58
+ card_number = '1111222233334444'
59
+
60
+ assert_equal true, Privatbank::P24.info(card_number) != ''
61
+
62
+ VCR.eject_cassette 'info'
63
+ end
64
+
65
+
66
+ def test_payment_info
67
+ VCR.insert_cassette 'payment_status'
68
+
69
+ payment_id = 'some-id'
70
+ ref = 'P123451234512341'
71
+
72
+ assert_equal true, Privatbank::P24.payment_status(payment_id, ref) != ''
73
+
74
+ VCR.eject_cassette 'payment_status'
75
+ end
27
76
  end
@@ -0,0 +1,21 @@
1
+ require 'minitest_helper'
2
+ require 'privatbank/p24/info'
3
+
4
+ class TestP24Info < MiniTest::Unit::TestCase
5
+
6
+ def test_outgoing_xml
7
+ merchant_id = 'some-id-of-merchant'
8
+ merchant_password = 'some-secret-password'
9
+ card_number = '1111222233334444'
10
+ country = 'UA'
11
+
12
+ options = {
13
+ merchant_id: merchant_id,
14
+ merchant_password: merchant_password,
15
+ }
16
+
17
+ as = Privatbank::P24::Info.new(card_number, country, options)
18
+ assert_equal true, as.outgoing_xml != ''
19
+ end
20
+
21
+ end
@@ -0,0 +1,21 @@
1
+ require 'minitest_helper'
2
+ require 'privatbank/p24/payment_status'
3
+
4
+ class TestP24PaymentStatus < MiniTest::Unit::TestCase
5
+
6
+ def test_outgoing_xml
7
+ merchant_id = 'some-id-of-merchant'
8
+ merchant_password = 'some-secret-password'
9
+ payment_id = 'some-id'
10
+ ref = 'P123451234512341'
11
+
12
+ options = {
13
+ merchant_id: merchant_id,
14
+ merchant_password: merchant_password,
15
+ }
16
+
17
+ as = Privatbank::P24::PaymentStatus.new(payment_id, ref, options)
18
+ assert_equal true, as.outgoing_xml != ''
19
+ end
20
+
21
+ end
@@ -0,0 +1,24 @@
1
+ require 'minitest_helper'
2
+ require 'privatbank/p24/send_money_pb'
3
+
4
+ class TestP24SendMoneyPB < MiniTest::Unit::TestCase
5
+
6
+ def test_outgoing_xml
7
+ merchant_id = 'some-id-of-merchant'
8
+ merchant_password = 'some-secret-password'
9
+ receiver = '1111222233334444'
10
+ payment_id = '12345'
11
+ amount = 100
12
+ currency = 'UAH'
13
+ details = 'some-details'
14
+
15
+ options = {
16
+ merchant_id: merchant_id,
17
+ merchant_password: merchant_password,
18
+ }
19
+
20
+ as = Privatbank::P24::SendMoneyPB.new(receiver, payment_id, amount, currency, details, options)
21
+ assert_equal true, as.outgoing_xml != ''
22
+ end
23
+
24
+ end
@@ -0,0 +1,25 @@
1
+ require 'minitest_helper'
2
+ require 'privatbank/p24/send_money_visa'
3
+
4
+ class TestP24SendMoneyVisa < MiniTest::Unit::TestCase
5
+
6
+ def test_outgoing_xml
7
+ merchant_id = 'some-id-of-merchant'
8
+ merchant_password = 'some-secret-password'
9
+ receiver = '1111222233334444'
10
+ full_name = 'Some Full Name'
11
+ payment_id = '12345'
12
+ amount = 100
13
+ currency = 'UAH'
14
+ details = 'some-details'
15
+
16
+ options = {
17
+ merchant_id: merchant_id,
18
+ merchant_password: merchant_password,
19
+ }
20
+
21
+ as = Privatbank::P24::SendMoneyVisa.new(receiver, full_name, payment_id, amount, currency, details, options)
22
+ assert_equal true, as.outgoing_xml != ''
23
+ end
24
+
25
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: privatbank
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
  - Roman Greshny
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-12 00:00:00.000000000 Z
11
+ date: 2016-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie
@@ -154,8 +154,12 @@ files:
154
154
  - lib/privatbank/p24.rb
155
155
  - lib/privatbank/p24/account_statement.rb
156
156
  - lib/privatbank/p24/exchange_rates.rb
157
+ - lib/privatbank/p24/info.rb
157
158
  - lib/privatbank/p24/items/exchanges.rb
158
159
  - lib/privatbank/p24/items/transaction.rb
160
+ - lib/privatbank/p24/payment_status.rb
161
+ - lib/privatbank/p24/send_money_pb.rb
162
+ - lib/privatbank/p24/send_money_visa.rb
159
163
  - lib/privatbank/signature.rb
160
164
  - lib/privatbank/version.rb
161
165
  - privatbank.gemspec
@@ -163,6 +167,10 @@ files:
163
167
  - test/test_exchange_rates.rb
164
168
  - test/test_p24.rb
165
169
  - test/test_p24_account_statement.rb
170
+ - test/test_p24_info.rb
171
+ - test/test_p24_payment_status.rb
172
+ - test/test_p24_send_money_pb.rb
173
+ - test/test_p24_send_money_visa.rb
166
174
  - test/test_privatbank.rb
167
175
  - test/test_signature.rb
168
176
  - test/vcr_cassettes/account_statement.yml
@@ -189,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
197
  version: '0'
190
198
  requirements: []
191
199
  rubyforge_project:
192
- rubygems_version: 2.2.2
200
+ rubygems_version: 2.5.1
193
201
  signing_key:
194
202
  specification_version: 4
195
203
  summary: Privat24 API wrapper
@@ -198,6 +206,10 @@ test_files:
198
206
  - test/test_exchange_rates.rb
199
207
  - test/test_p24.rb
200
208
  - test/test_p24_account_statement.rb
209
+ - test/test_p24_info.rb
210
+ - test/test_p24_payment_status.rb
211
+ - test/test_p24_send_money_pb.rb
212
+ - test/test_p24_send_money_visa.rb
201
213
  - test/test_privatbank.rb
202
214
  - test/test_signature.rb
203
215
  - test/vcr_cassettes/account_statement.yml