qiwi-pay 0.1.8 → 0.2.0

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
  SHA256:
3
- metadata.gz: 207c392de35d581c92ec94e7f061ffe459b7696b26c5df1c9858b38f65086968
4
- data.tar.gz: 79aeecf6651f791bc84bdd22ddb0a5d2e575b5cf9f3161208dbc6161de1460be
3
+ metadata.gz: 6ccf37796f11498182ae5435a6659542138b03026a0f6cb86c124f4b832919a6
4
+ data.tar.gz: f296cf13928751188c6db623b05181ac3e3ee1383c561062ed3bb6dc811681dd
5
5
  SHA512:
6
- metadata.gz: 5f134f6dc051d53c5566d5ff27fae6d2ddb2191427c8e90d32ffdcb1b1de4918fd571374d5b69dab04f91846ec876ceabb936b734b08f33112a49e20ec7bb257
7
- data.tar.gz: 78c191e259ce655377b1770441088495275811e5ba3db6da2fd25ab4db59455f1463aae154327d21975a60f2440593dcb1c762864424df06241756c899e1bd49
6
+ metadata.gz: d0ceec3bf10ff6f8375dc64a6e57c6b9520500cc4ac5e121f6a3be5717a570d865c18b75179e4a88bfc98bf18f3eae0eb9f77c6fe3ba1fd092c58899614cbac3
7
+ data.tar.gz: 91375b823e65e4149f3724a1301b14127f62f89da50822ab2f9b2bc37143e6e2af040353095ccdd6990e46a8debb9f3db04a9c75ab50eb3f541e515c9c769aa8
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- qiwi-pay (0.1.8)
4
+ qiwi-pay (0.2.0)
5
5
  rest-client (>= 1.8.0, < 2.1)
6
6
 
7
7
  GEM
@@ -37,6 +37,9 @@ GEM
37
37
  rspec-expectations (3.7.0)
38
38
  diff-lcs (>= 1.2.0, < 2.0)
39
39
  rspec-support (~> 3.7.0)
40
+ rspec-its (1.3.0)
41
+ rspec-core (>= 3.0.0)
42
+ rspec-expectations (>= 3.0.0)
40
43
  rspec-mocks (3.7.0)
41
44
  diff-lcs (>= 1.2.0, < 2.0)
42
45
  rspec-support (~> 3.7.0)
@@ -59,7 +62,8 @@ DEPENDENCIES
59
62
  qiwi-pay!
60
63
  rake (~> 10.0)
61
64
  rspec (~> 3.0)
65
+ rspec-its (~> 1)
62
66
  webmock (~> 2)
63
67
 
64
68
  BUNDLED WITH
65
- 1.16.2
69
+ 1.17.3
data/README.md CHANGED
@@ -237,6 +237,8 @@ response = op.perform
237
237
 
238
238
  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)
239
239
 
240
+ In case the JSON API response parsing fails, the whole response body is returned by `Response`'s `error_message` method and the `error_code` is set to -1.
241
+
240
242
  ##### Operation succeeded
241
243
  ```ruby
242
244
  response.success?
@@ -15,6 +15,10 @@ module QiwiPay::Api
15
15
  ).post(request_params.to_json)
16
16
 
17
17
  Response.new res.code, res.body
18
+ rescue RestClient::Unauthorized, RestClient::Forbidden
19
+ Response.new 403, 'Access denied'
20
+ rescue RestClient::ExceptionWithResponse => e
21
+ Response.new e.response.code, e.response.body
18
22
  end
19
23
 
20
24
  private
@@ -20,11 +20,16 @@ module QiwiPay::Api
20
20
  # @param response_code [Integer] HTTP response status code
21
21
  # @param response_body [String] Response body in JSON
22
22
  def initialize(response_code, response_body)
23
- params = JSON.parse(response_body)
24
- (INTEGER_PARAMS & params.keys).each do |p|
25
- params[p] = params[p] && params[p].to_i
23
+ begin
24
+ params = JSON.parse(response_body)
25
+ (INTEGER_PARAMS & params.keys).each do |p|
26
+ params[p] = params[p] && params[p].to_i
27
+ end
28
+ super params
29
+ rescue JSON::ParserError
30
+ super error_code: -1
31
+ define_singleton_method :error_message, ->{ response_body }
26
32
  end
27
- super params
28
33
  send(:http_code=, response_code)
29
34
  end
30
35
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module QiwiPay
4
- VERSION = "0.1.8"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -17,5 +17,18 @@ RSpec.describe QiwiPay::Api::Response do
17
17
  expect(subject.http_code).to eq 200
18
18
  end
19
19
  end
20
+
21
+ describe 'received HTTP body with error description' do
22
+ let(:http_code) { 400 }
23
+ let(:json) do
24
+ '<html><head><title>400 The SSL certificate error</title></head>'\
25
+ '<body bgcolor="white"><center><h1>400 Bad Request</h1></center>'\
26
+ '<center>The SSL certificate error</center></body></html>'
27
+ end
28
+
29
+ its(:http_code) { is_expected.to eq 400 }
30
+ its(:error_code) { is_expected.to eq -1 }
31
+ its(:error_message) { is_expected.to include '400 The SSL certificate error' }
32
+ end
20
33
  end
21
34
  end
@@ -102,7 +102,11 @@ RSpec.describe QiwiPay::Api::StatusOperation do
102
102
  describe 'making forbidden request' do
103
103
  it 'raises error' do
104
104
  expect(api_client).to receive(:post).and_raise(RestClient::Forbidden)
105
- expect { subject.perform }.to raise_error(RuntimeError)
105
+ r = subject.perform
106
+ expect(r).to be_a QiwiPay::Api::Response
107
+ expect(r.http_code).to eq 403
108
+ expect(r.error_code).to eq(-1)
109
+ expect(r.error_message).to eq 'Access denied'
106
110
  end
107
111
  end
108
112
  end
@@ -36,5 +36,24 @@ RSpec.shared_examples "api_payment_operation" do
36
36
  expect(r.txn_date).to eq '2017-03-09T17:16:06+00:00'
37
37
  end
38
38
  end
39
+
40
+ describe 'receiving http error from QiwiPay' do
41
+ before do
42
+ WebMock.stub_request(:post, %r{\Ahttps://acquiring\.qiwi\.com.+})
43
+ .to_return(status: 400,
44
+ body: '<html><head><title>400 The SSL certificate error</title></head>'\
45
+ '<body bgcolor="white"><center><h1>400 Bad Request</h1></center>'\
46
+ '<center>The SSL certificate error</center></body></html>')
47
+ end
48
+
49
+ it 'perform signed POST request to QiwiPay API URL' do
50
+ r = subject.perform
51
+ expect(r).to be_a QiwiPay::Api::Response
52
+ expect(r.http_code).to eq 400
53
+ expect(r.error_code).to eq -1
54
+ expect(r.error_message).to include '400 The SSL certificate error'
55
+ end
56
+
57
+ end
39
58
  end
40
59
  end
@@ -1,3 +1,4 @@
1
+ require 'rspec/its'
1
2
  require 'qiwi-pay'
2
3
  require_relative 'support/external_requests'
3
4
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qiwi-pay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Klimenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-02 00:00:00.000000000 Z
11
+ date: 2019-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -86,6 +86,20 @@ dependencies:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
88
  version: '3.0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rspec-its
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '1'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '1'
89
103
  - !ruby/object:Gem::Dependency
90
104
  name: webmock
91
105
  requirement: !ruby/object:Gem::Requirement