qiwi-pay 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2c519d36dfabe76d9e0be3b19758e66575a73528be25c8ab497b5d5f08a0d9f3
4
+ data.tar.gz: 7ef5979eaf0f79a4b87299f375327279a14e5cd5c14ad6897c84bc82f7ad79f0
5
+ SHA512:
6
+ metadata.gz: 6ce3d7ebdf28060e4cd6909aa38f8cc53e8a62e64e49df2025cd51efe75932d945af453e8fb8f5f51fc88f21a687f9ecadb18bf772bb34a27a22ec2558593e49
7
+ data.tar.gz: d4f4958767bad7d99f8553be4abd0fadd3afdfaee36e0114c690672b0197d458be29cb3d582d0f3401d580ac52fca83dcb93451a381cabe07338bfa4fe4b2346
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,8 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.1
3
+
4
+ Style/AsciiComments:
5
+ Enabled: false
6
+
7
+ Rails:
8
+ Enabled: false
@@ -0,0 +1 @@
1
+ 2.3.5
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.5
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in qiwi-pay.gemspec
6
+ gemspec
@@ -0,0 +1,65 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ qiwi-pay (0.1.0)
5
+ rest-client (>= 1.8.0, < 2.1)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.5.2)
11
+ public_suffix (>= 2.0.2, < 4.0)
12
+ crack (0.4.3)
13
+ safe_yaml (~> 1.0.0)
14
+ diff-lcs (1.3)
15
+ domain_name (0.5.20180417)
16
+ unf (>= 0.0.5, < 1.0.0)
17
+ hashdiff (0.3.7)
18
+ http-cookie (1.0.3)
19
+ domain_name (~> 0.5)
20
+ luhn (1.0.2)
21
+ mime-types (3.1)
22
+ mime-types-data (~> 3.2015)
23
+ mime-types-data (3.2016.0521)
24
+ netrc (0.11.0)
25
+ public_suffix (3.0.2)
26
+ rake (10.5.0)
27
+ rest-client (2.0.2)
28
+ http-cookie (>= 1.0.2, < 2.0)
29
+ mime-types (>= 1.16, < 4.0)
30
+ netrc (~> 0.8)
31
+ rspec (3.7.0)
32
+ rspec-core (~> 3.7.0)
33
+ rspec-expectations (~> 3.7.0)
34
+ rspec-mocks (~> 3.7.0)
35
+ rspec-core (3.7.1)
36
+ rspec-support (~> 3.7.0)
37
+ rspec-expectations (3.7.0)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.7.0)
40
+ rspec-mocks (3.7.0)
41
+ diff-lcs (>= 1.2.0, < 2.0)
42
+ rspec-support (~> 3.7.0)
43
+ rspec-support (3.7.1)
44
+ safe_yaml (1.0.4)
45
+ unf (0.1.4)
46
+ unf_ext
47
+ unf_ext (0.0.7.5)
48
+ webmock (2.3.2)
49
+ addressable (>= 2.3.6)
50
+ crack (>= 0.3.2)
51
+ hashdiff
52
+
53
+ PLATFORMS
54
+ ruby
55
+
56
+ DEPENDENCIES
57
+ bundler (~> 1.16)
58
+ luhn (~> 1.0)
59
+ qiwi-pay!
60
+ rake (~> 10.0)
61
+ rspec (~> 3.0)
62
+ webmock (~> 2)
63
+
64
+ BUNDLED WITH
65
+ 1.16.2
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Onlinetours.Ru
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,296 @@
1
+ [![Build Status](https://travis-ci.org/OnlinetoursGit/qiwi-pay.svg?branch=master)](https://travis-ci.org/OnlinetoursGit/qiwi-pay)
2
+ [![Maintainability](https://api.codeclimate.com/v1/badges/eb4dda5c934aec79ef99/maintainability)](https://codeclimate.com/github/OnlinetoursGit/qiwi-pay/maintainability)
3
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/eb4dda5c934aec79ef99/test_coverage)](https://codeclimate.com/github/OnlinetoursGit/qiwi-pay/test_coverage)
4
+
5
+ # QiwiPay
6
+
7
+ QiwiPay WPF/API binding for Ruby.
8
+
9
+ Provides support for payment operations using QiwiPay WPF and API services.
10
+
11
+ See [Official QiwiPay documentation](https://developer.qiwi.com/ru/qiwipay) for detailed API description.
12
+
13
+ ## Table of contents
14
+
15
+ * [Installation](#installation)
16
+ * [Usage](#usage)
17
+ * [Prepare credentials object](#prepare-credentials-object)
18
+ * [Create cheque object](#create-cheque-object)
19
+ * [Perform payment operations using WPF](#perform-payment-operations-using-wpf)
20
+ * [Process QiwiPay confirmation callback](#process-qiwipay-confirmation-callback)
21
+ * [Perform payment operations using JSON API](#perform-payment-operations-using-json-api)
22
+ * [Development](#development)
23
+ * [Contributing](#contributing)
24
+
25
+ ## Installation
26
+
27
+ Add this line to your application's Gemfile:
28
+
29
+ ```ruby
30
+ gem 'qiwi-pay'
31
+ ```
32
+
33
+ And then execute:
34
+
35
+ $ bundle
36
+
37
+ Or install it yourself as:
38
+
39
+ $ gem install qiwi-pay
40
+
41
+
42
+ ## Usage
43
+
44
+ There are three types of interactions with QiwiPay service:
45
+
46
+ 1. Performing Web Payment Form requests
47
+ 2. Performing JSON API requests
48
+ 3. Handling callback confirmation requests
49
+
50
+ ### Prepare credentials object
51
+ To perform any request you must provide your QiwiPay credentials. For doing that the `Credentials` object should be used.
52
+
53
+ ```ruby
54
+ # Create credentials object
55
+ # You can use PKCS#12 container
56
+ p12 = OpenSSL::PKCS12.new(File.read('qiwi.p12'))
57
+
58
+ crds = QiwiPay::Credentials.new secret: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
59
+ p12: p12
60
+
61
+ # ... or provide certificate and key objects explicitly
62
+ crds = QiwiPay::Credentials.new secret: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
63
+ cert: p12.certificate,
64
+ key: p12.key
65
+
66
+ # ... or load from separate files
67
+ crds = QiwiPay::Credentials.new secret: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
68
+ cert: 'my.crt',
69
+ key: 'my.key'
70
+ ```
71
+
72
+ ### Create cheque object
73
+
74
+ See [Cheque section of Official QiwiPay documentation](https://developer.qiwi.com/ru/qiwipay/index.html?json#cheque) for details.
75
+ ```ruby
76
+ cheque = QiwiPay::Cheque.new seller_id: 12345678901,
77
+ cheque_type: QiwiPay::Cheque::Type::INFLOW,
78
+ customer_contact: 'client@example.com',
79
+ tax_system: QiwiPay::Cheque::TaxMode::USN_DR,
80
+ positions: [{
81
+ quantity: 1,
82
+ price: 10_000,
83
+ tax: QiwiPay::Cheque::VAT::NONE,
84
+ description: 'Order #1234 payment'
85
+ }]
86
+ ```
87
+
88
+ ### Perform payment operations using WPF
89
+ Only two types of payment operations are available for now:
90
+ * *sale* - single-step payment operation
91
+ * *auth* - initiate multi-steps payment operation
92
+
93
+ Operations are used in very similar way. Use `QiwiPay::Wpf::SaleOperation` class for *sale* operation and `QiwiPay::Wpf::AuthOperation` class for *auth* operation.
94
+
95
+ See [WPF section of Official QiwiPay documentation](https://developer.qiwi.com/ru/qiwipay/index.html?json#qiwipay-wpf) for details.
96
+
97
+ #### Create payment operation object
98
+ ```ruby
99
+ op = QiwiPay::Wpf::SaleOperation.new crds,
100
+ merchant_site: 111_111,
101
+ currency: 643,
102
+ email: 'client@example.com',
103
+ country: 'RUS',
104
+ city: 'Moscow',
105
+ amount: 10_000,
106
+ order_id: 1234,
107
+ product_name: 'Flowers',
108
+ merchant_uid: 432101,
109
+ order_expire: Time.now + 3600,
110
+ callback_url: 'https://example.com/payment/callback'
111
+ op.cheque = cheque
112
+ ```
113
+
114
+ #### Build redirection URL for sale operation form
115
+ ```ruby
116
+ op.url
117
+ => 'https://pay.qiwi.com/paypage/initial?opcode=1&merchant_site=111111&currency=643&amount=1000.00&order_id=1234&email=client@example.com&country=RUS&city=Moscow&product_name=%D0%9E%D0%BF%D0%BB%D0%B0%D1%82%D0%B0+%D1%82%D1%83%D1%80%D0%B0&merchant_uid=432101&callback_url=https%3A%2F%example.com%2Fpayment%2Fcallback&sign=...c4dbf...'
118
+ ```
119
+
120
+ #### Build form params WPF sale operation
121
+ This may be useful if you would like to construct redirection URL or invisible payment form by yourself.
122
+ ```ruby
123
+ op.params
124
+ => {:method=>:get,
125
+ :url=>"https://pay.qiwi.com/paypage/initial",
126
+ :opcode=>"1",
127
+ :merchant_site=>"111111",
128
+ :currency=>"643",
129
+ :amount=>"1000.00",
130
+ :order_id=>"1234",
131
+ :email=>"client@example.com",
132
+ :country=>"RUS",
133
+ :city=>"Moscow",
134
+ :product_name=>"Flowers",
135
+ :merchant_uid=>"432101",
136
+ :callback_url=>"https://example.com/payment/callback",
137
+ :sign=>"...c4dbf..."}
138
+ ```
139
+
140
+ ### Process QiwiPay confirmation callback
141
+ After payment operation has been finished you will receive a confirmation callback request from Qiwi service. Use the request's (`ActionDispatch::Request`, `Rack::Request` or whatever it is) parameters hash to build `QiwiPay::Confirmation` object.
142
+
143
+ ```ruby
144
+ conf = QiwiPay::Confirmation.new crds, request.params
145
+ ```
146
+
147
+ Now you have a seamless way to access confirmation data and perform some tests on it.
148
+
149
+ ```ruby
150
+ # Check if ip address is a valid Qiwi server address
151
+ conf.valid_server_ip? request.ip
152
+ => true
153
+
154
+ # Check signature
155
+ conf.valid_sign?
156
+ => true
157
+
158
+ # Read confirmation data
159
+ conf.txn_id
160
+ => 11728960050
161
+
162
+ conf.order_id
163
+ => 1234
164
+
165
+ conf.error_code
166
+ => 0
167
+
168
+ conf.error_message
169
+ => "No error"
170
+
171
+ conf.error?
172
+ => false
173
+
174
+ conf.txn_status_message
175
+ => "Authorized"
176
+
177
+ conf.txn_type_message
178
+ => "Purchase: auth"
179
+
180
+ # Check if transaction was successful (valid signature and no error)
181
+ conf.success?
182
+ => true
183
+
184
+ # Get all confirmation data as a hash
185
+ conf.to_h
186
+ => {:txn_id=>11728960050,
187
+ :txn_status=>2,
188
+ :txn_type=>1,
189
+ :txn_date=>"2018-05-03T15:55:18+00:00",
190
+ :error_code=>0,
191
+ :pan=>"510000******0082",
192
+ :amount=>"10000.00",
193
+ :currency=>643,
194
+ :auth_code=>nil,
195
+ :eci=>nil,
196
+ :card_name=>nil,
197
+ :card_bank=>nil,
198
+ :order_id=>1234,
199
+ :ip=>"196.54.55.20",
200
+ :email=>"client@example.com",
201
+ :country=>"RUS",
202
+ :city=>"Moscow",
203
+ :region=>nil,
204
+ :address=>nil,
205
+ :phone=>nil,
206
+ :cf1=>nil,
207
+ :cf2=>nil,
208
+ :cf3=>nil,
209
+ :cf4=>nil,
210
+ :cf5=>nil,
211
+ :product_name=>"Flowers",
212
+ :card_token=>nil,
213
+ :card_token_expire=>nil,
214
+ :sign=>"27A56431CD3A14BA34...8A",
215
+ :txn_status_message=>"Authorized",
216
+ :txn_type_message=>"Single-step purchase"}
217
+ ```
218
+
219
+ ### Perform payment operations using JSON API
220
+ Following operations are available for now:
221
+
222
+ * *capture* - `QiwiPay::Api::CaptureOperation` class
223
+ * *refund* - `QiwiPay::Api::RefundOperation` class
224
+ * *reversal* - `QiwiPay::Api::ReversalOperation` class
225
+ * *status* - `QiwiPay::Api::StatusOperation` class
226
+
227
+ #### Status operation
228
+ ##### Create and perform `status` operation object
229
+ ```ruby
230
+ op = QiwiPay::Api::StatusOperation.new crds,
231
+ merchant_site: 111111,
232
+ txn_id: 11728960050,
233
+ order_id: 1234
234
+ response = op.perform
235
+ ```
236
+
237
+ Operations' `perform` methods return `QiwiPay::Api::Response` object. It allow you to get text messages for errors, codes and statuses. See [Transaction statuses section of Official QiwiPay documentation](https://developer.qiwi.com/ru/qiwipay/index.html?json#txn_status)
238
+
239
+ ##### Operation succeeded
240
+ ```ruby
241
+ response.success?
242
+ => true
243
+ response.error_code
244
+ => 0
245
+ response.error_message
246
+ => "No errors"
247
+ ```
248
+
249
+ ##### Operation failed
250
+ ```ruby
251
+ response.success?
252
+ => false
253
+ response.http_code
254
+ => 200
255
+ response.error_code
256
+ => 8021
257
+ response.error_message
258
+ => "Merchant site not found"
259
+ ```
260
+
261
+ #### Refund/reversal operation
262
+ Both operations are performed in the same way, just use the right class.
263
+
264
+ ```ruby
265
+ op = QiwiPay::Api::RefundOperation.new crds,
266
+ merchant_site: 111111,
267
+ txn_id: 11728960050,
268
+ amount: 500,
269
+ cheque: cheque
270
+ response = op.perform
271
+ => #<QiwiPay::Api::Response http_code=200 error_code=8018 ...>
272
+ response.success?
273
+ => false
274
+ response.http_code
275
+ => 200
276
+ response.error_code
277
+ => 8018
278
+ response.error_message
279
+ => "Parsing error"
280
+ response.to_h
281
+ => {:request_id => "01234567-89ab-cdef-0123-456789abcdef",
282
+ :error_message => "Parsing error",
283
+ :error_code => 8018,
284
+ :http_code => 200
285
+ }
286
+ ```
287
+
288
+ ## Development
289
+
290
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` or `rake console` or `rake c` for an interactive prompt that will allow you to experiment.
291
+
292
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
293
+
294
+ ## Contributing
295
+
296
+ Bug reports and pull requests are welcome on GitHub at https://github.com/OnlinetoursGit/qiwi-pay.
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
8
+ task :c => :console
9
+ task :console do
10
+ sh 'bundle exec irb -r qiwi-pay'
11
+ end