killbill-client 0.32.1 → 0.34.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/killbill_client/api/errors.rb +20 -3
- data/lib/killbill_client/api/net_http_adapter.rb +12 -6
- data/lib/killbill_client/models/combo_transaction.rb +18 -8
- data/lib/killbill_client/models/subscription.rb +2 -0
- data/lib/killbill_client/models/transaction.rb +80 -51
- data/lib/killbill_client/version.rb +2 -2
- data/spec/killbill_client/errors_spec.rb +52 -0
- metadata +35 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7884db06718c90098514ddffc4d5840fdf2eea57
|
4
|
+
data.tar.gz: c062ac56ca9e7c9037d49fe6ec26563c76b09fff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f67cdd02e9ede604d08f25f35cdb27402953d4222ef7863d5cd1608c1d8154887a05e175033950c1a0a793a459f91874ebbdd67b9983caf7c976b95387992f4
|
7
|
+
data.tar.gz: c2a63017349eedd279f487fd431145711db6b15dfc2fcb5649826ac40e4ebf6746f0bb060d793b97f1bc942a99979f2d061100ef28edf038f8f49b172e2dc4d8
|
@@ -26,6 +26,10 @@ module KillBillClient
|
|
26
26
|
]
|
27
27
|
end
|
28
28
|
|
29
|
+
def self.error_for(status, request, response)
|
30
|
+
ERRORS[status].new(request, response)
|
31
|
+
end
|
32
|
+
|
29
33
|
private
|
30
34
|
|
31
35
|
def description
|
@@ -69,6 +73,12 @@ module KillBillClient
|
|
69
73
|
class Unauthorized < ClientError
|
70
74
|
end
|
71
75
|
|
76
|
+
# === 402 Payment Required
|
77
|
+
#
|
78
|
+
# The payment failed with a transaction declined error
|
79
|
+
class PaymentRequired < ClientError
|
80
|
+
end
|
81
|
+
|
72
82
|
# === 403 Forbidden
|
73
83
|
#
|
74
84
|
# The login is attempting to perform an action it does not have privileges
|
@@ -116,8 +126,7 @@ module KillBillClient
|
|
116
126
|
|
117
127
|
# === 422 Unprocessable Entity
|
118
128
|
#
|
119
|
-
#
|
120
|
-
# See the response body for more details.
|
129
|
+
# The payment was aborted before anything happened
|
121
130
|
class UnprocessableEntity < ClientError
|
122
131
|
end
|
123
132
|
|
@@ -146,6 +155,12 @@ module KillBillClient
|
|
146
155
|
class ServiceUnavailable < ServerError
|
147
156
|
end
|
148
157
|
|
158
|
+
# === 504 Gateway Timeout
|
159
|
+
#
|
160
|
+
# The service did not receive a timely response from the upstream server.
|
161
|
+
class GatewayTimeout < ServerError
|
162
|
+
end
|
163
|
+
|
149
164
|
# Error mapping by status code.
|
150
165
|
ERRORS = Hash.new { |hash, code|
|
151
166
|
unless hash.key? code
|
@@ -162,6 +177,7 @@ module KillBillClient
|
|
162
177
|
304 => NotModified,
|
163
178
|
400 => BadRequest,
|
164
179
|
401 => Unauthorized,
|
180
|
+
402 => PaymentRequired,
|
165
181
|
403 => Forbidden,
|
166
182
|
404 => NotFound,
|
167
183
|
406 => NotAcceptable,
|
@@ -169,7 +185,8 @@ module KillBillClient
|
|
169
185
|
422 => UnprocessableEntity,
|
170
186
|
500 => InternalServerError,
|
171
187
|
502 => GatewayError,
|
172
|
-
503 => ServiceUnavailable
|
188
|
+
503 => ServiceUnavailable,
|
189
|
+
504 => GatewayTimeout
|
173
190
|
).freeze
|
174
191
|
end
|
175
192
|
end
|
@@ -68,11 +68,17 @@ module KillBillClient
|
|
68
68
|
head.update options[:head] if options[:head]
|
69
69
|
head.delete_if { |_, value| value.nil? }
|
70
70
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
71
|
+
if URI(relative_uri).scheme.nil?
|
72
|
+
uri = (options[:base_uri] || base_uri)
|
73
|
+
uri = URI.parse(uri) unless uri.is_a?(URI)
|
74
|
+
# Note: make sure to keep the full path (if any) from URI::HTTP, for non-ROOT deployments
|
75
|
+
# See https://github.com/killbill/killbill/issues/221#issuecomment-151980263
|
76
|
+
base_path = uri.request_uri == '/' ? '' : uri.request_uri
|
77
|
+
uri += (base_path + URI.escape(relative_uri))
|
78
|
+
else
|
79
|
+
uri = relative_uri
|
80
|
+
uri = URI.parse(uri) unless uri.is_a?(URI)
|
81
|
+
end
|
76
82
|
uri += encode_params(options).to_s
|
77
83
|
request = METHODS[method].new uri.request_uri, head
|
78
84
|
|
@@ -198,7 +204,7 @@ module KillBillClient
|
|
198
204
|
when 200...300 then
|
199
205
|
response
|
200
206
|
else
|
201
|
-
raise
|
207
|
+
raise ResponseError.error_for(code, request, response)
|
202
208
|
end
|
203
209
|
end
|
204
210
|
end
|
@@ -23,14 +23,24 @@ module KillBillClient
|
|
23
23
|
private
|
24
24
|
|
25
25
|
def combo_payment(user, reason, comment, options, refresh_options = nil)
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
26
|
+
begin
|
27
|
+
created_transaction = self.class.post "#{Payment::KILLBILL_API_PAYMENTS_PREFIX}/combo",
|
28
|
+
to_json,
|
29
|
+
{},
|
30
|
+
{
|
31
|
+
:user => user,
|
32
|
+
:reason => reason,
|
33
|
+
:comment => comment,
|
34
|
+
}.merge(options)
|
35
|
+
rescue KillBillClient::API::ResponseError => error
|
36
|
+
response = error.response
|
37
|
+
if response.header['location']
|
38
|
+
created_transaction = ComboTransaction.new
|
39
|
+
created_transaction.uri = response.header['location']
|
40
|
+
else
|
41
|
+
raise error
|
42
|
+
end
|
43
|
+
end
|
34
44
|
created_transaction.refresh(refresh_options || options, Payment)
|
35
45
|
end
|
36
46
|
end
|
@@ -7,6 +7,8 @@ module KillBillClient
|
|
7
7
|
KILLBILL_API_ENTITLEMENT_PREFIX = "#{KILLBILL_API_PREFIX}/subscriptions"
|
8
8
|
|
9
9
|
has_many :events, KillBillClient::Model::EventSubscription
|
10
|
+
has_many :price_overrides, KillBillClient::Model::PhasePriceOverrideAttributes
|
11
|
+
|
10
12
|
has_custom_fields KILLBILL_API_ENTITLEMENT_PREFIX, :subscription_id
|
11
13
|
|
12
14
|
class << self
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'killbill_client/api/errors'
|
2
|
+
|
1
3
|
module KillBillClient
|
2
4
|
module Model
|
3
5
|
class Transaction < PaymentTransactionAttributes
|
@@ -61,53 +63,58 @@ module KillBillClient
|
|
61
63
|
end
|
62
64
|
|
63
65
|
def capture(user = nil, reason = nil, comment = nil, options = {})
|
64
|
-
created_transaction =
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
66
|
+
created_transaction = with_payment_failure_handling do
|
67
|
+
self.class.post "#{follow_up_path(payment_id)}",
|
68
|
+
to_json,
|
69
|
+
{},
|
70
|
+
{
|
71
|
+
:user => user,
|
72
|
+
:reason => reason,
|
73
|
+
:comment => comment,
|
74
|
+
}.merge(options)
|
75
|
+
end
|
72
76
|
created_transaction.refresh(options, Payment)
|
73
77
|
end
|
74
78
|
|
75
79
|
def refund(user = nil, reason = nil, comment = nil, options = {})
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
80
|
+
created_transaction = with_payment_failure_handling do
|
81
|
+
self.class.post "#{follow_up_path(payment_id)}/refunds",
|
82
|
+
to_json,
|
83
|
+
{},
|
84
|
+
{
|
85
|
+
:user => user,
|
86
|
+
:reason => reason,
|
87
|
+
:comment => comment,
|
88
|
+
}.merge(options)
|
89
|
+
end
|
85
90
|
created_transaction.refresh(options, Payment)
|
86
91
|
end
|
87
92
|
|
88
93
|
def void(user = nil, reason = nil, comment = nil, options = {})
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
94
|
+
created_transaction = with_payment_failure_handling do
|
95
|
+
self.class.delete "#{follow_up_path(payment_id)}",
|
96
|
+
to_json,
|
97
|
+
{},
|
98
|
+
{
|
99
|
+
:user => user,
|
100
|
+
:reason => reason,
|
101
|
+
:comment => comment,
|
102
|
+
}.merge(options)
|
103
|
+
end
|
98
104
|
created_transaction.refresh(options, Payment)
|
99
105
|
end
|
100
106
|
|
101
107
|
def chargeback(user = nil, reason = nil, comment = nil, options = {})
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
108
|
+
created_transaction = with_payment_failure_handling do
|
109
|
+
self.class.post "#{follow_up_path(payment_id)}/chargebacks",
|
110
|
+
to_json,
|
111
|
+
{},
|
112
|
+
{
|
113
|
+
:user => user,
|
114
|
+
:reason => reason,
|
115
|
+
:comment => comment,
|
116
|
+
}.merge(options)
|
117
|
+
end
|
111
118
|
created_transaction.refresh(options, Payment)
|
112
119
|
end
|
113
120
|
|
@@ -123,28 +130,50 @@ module KillBillClient
|
|
123
130
|
def create_initial_transaction(path, query_map, payment_method_id, user, reason, comment, options)
|
124
131
|
query_map[:paymentMethodId] = payment_method_id unless payment_method_id.nil?
|
125
132
|
|
126
|
-
created_transaction =
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
133
|
+
created_transaction = with_payment_failure_handling do
|
134
|
+
self.class.post path,
|
135
|
+
to_json,
|
136
|
+
query_map,
|
137
|
+
{
|
138
|
+
:user => user,
|
139
|
+
:reason => reason,
|
140
|
+
:comment => comment
|
141
|
+
}.merge(options)
|
142
|
+
end
|
134
143
|
created_transaction.refresh(options, Payment)
|
135
144
|
end
|
136
145
|
|
137
146
|
def complete_initial_transaction(user, reason, comment, options)
|
138
|
-
created_transaction =
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
147
|
+
created_transaction = with_payment_failure_handling do
|
148
|
+
self.class.put follow_up_path(payment_id),
|
149
|
+
to_json,
|
150
|
+
{},
|
151
|
+
{
|
152
|
+
:user => user,
|
153
|
+
:reason => reason,
|
154
|
+
:comment => comment
|
155
|
+
}.merge(options)
|
156
|
+
end
|
146
157
|
created_transaction.refresh(options, Payment)
|
147
158
|
end
|
159
|
+
|
160
|
+
private
|
161
|
+
|
162
|
+
def with_payment_failure_handling
|
163
|
+
begin
|
164
|
+
created_transaction = yield
|
165
|
+
rescue KillBillClient::API::ResponseError => error
|
166
|
+
response = error.response
|
167
|
+
if response.header['location']
|
168
|
+
created_transaction = Transaction.new
|
169
|
+
created_transaction.uri = response.header['location']
|
170
|
+
else
|
171
|
+
raise error
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
created_transaction
|
176
|
+
end
|
148
177
|
end
|
149
178
|
end
|
150
179
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe KillBillClient::API::ResponseError do
|
4
|
+
describe '::error_for' do
|
5
|
+
let(:request) { double('request') }
|
6
|
+
let(:response) { double('response') }
|
7
|
+
before do
|
8
|
+
allow(response).to receive(:body)
|
9
|
+
allow(response).to receive(:code)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'maps 402 errors' do
|
13
|
+
error = described_class.error_for(402, request, response)
|
14
|
+
|
15
|
+
expect(error).to be_a(KillBillClient::API::PaymentRequired)
|
16
|
+
expect(error.request).to eq(request)
|
17
|
+
expect(error.response).to eq(response)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'maps 422 errors' do
|
21
|
+
error = described_class.error_for(422, request, response)
|
22
|
+
|
23
|
+
expect(error).to be_a(KillBillClient::API::UnprocessableEntity)
|
24
|
+
expect(error.request).to eq(request)
|
25
|
+
expect(error.response).to eq(response)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'maps 502 errors' do
|
29
|
+
error = described_class.error_for(502, request, response)
|
30
|
+
|
31
|
+
expect(error).to be_a(KillBillClient::API::GatewayError)
|
32
|
+
expect(error.request).to eq(request)
|
33
|
+
expect(error.response).to eq(response)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'maps 503 errors' do
|
37
|
+
error = described_class.error_for(503, request, response)
|
38
|
+
|
39
|
+
expect(error).to be_a(KillBillClient::API::ServiceUnavailable)
|
40
|
+
expect(error.request).to eq(request)
|
41
|
+
expect(error.response).to eq(response)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'maps 504 errors' do
|
45
|
+
error = described_class.error_for(504, request, response)
|
46
|
+
|
47
|
+
expect(error).to be_a(KillBillClient::API::GatewayTimeout)
|
48
|
+
expect(error.request).to eq(request)
|
49
|
+
expect(error.response).to eq(response)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
metadata
CHANGED
@@ -1,71 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: killbill-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.34.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Killbill core team
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
15
|
-
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 1.2.0
|
20
|
-
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirement: !ruby/object:Gem::Requirement
|
23
21
|
requirements:
|
24
|
-
- -
|
22
|
+
- - '>='
|
25
23
|
- !ruby/object:Gem::Version
|
26
24
|
version: 1.2.0
|
25
|
+
prerelease: false
|
26
|
+
type: :runtime
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
|
-
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 10.0.0
|
34
|
-
- -
|
34
|
+
- - <
|
35
35
|
- !ruby/object:Gem::Version
|
36
36
|
version: 11.0.0
|
37
|
-
|
38
|
-
prerelease: false
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirement: !ruby/object:Gem::Requirement
|
40
38
|
requirements:
|
41
|
-
- -
|
39
|
+
- - '>='
|
42
40
|
- !ruby/object:Gem::Version
|
43
41
|
version: 10.0.0
|
44
|
-
- -
|
42
|
+
- - <
|
45
43
|
- !ruby/object:Gem::Version
|
46
44
|
version: 11.0.0
|
45
|
+
prerelease: false
|
46
|
+
type: :development
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
|
-
- -
|
51
|
+
- - ~>
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '3.4'
|
54
|
-
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirement: !ruby/object:Gem::Requirement
|
57
55
|
requirements:
|
58
|
-
- -
|
56
|
+
- - ~>
|
59
57
|
- !ruby/object:Gem::Version
|
60
58
|
version: '3.4'
|
59
|
+
prerelease: false
|
60
|
+
type: :development
|
61
61
|
description: An API client library for Kill Bill.
|
62
62
|
email: killbilling-users@googlegroups.com
|
63
63
|
executables: []
|
64
64
|
extensions: []
|
65
65
|
extra_rdoc_files: []
|
66
66
|
files:
|
67
|
-
-
|
68
|
-
-
|
67
|
+
- .gitignore
|
68
|
+
- .travis.yml
|
69
69
|
- Gemfile
|
70
70
|
- README.md
|
71
71
|
- Rakefile
|
@@ -182,6 +182,7 @@ files:
|
|
182
182
|
- lib/rails/killbill_client.rb
|
183
183
|
- spec/killbill_client/base_uri_spec.rb
|
184
184
|
- spec/killbill_client/encoding_spec.rb
|
185
|
+
- spec/killbill_client/errors_spec.rb
|
185
186
|
- spec/killbill_client/model_relation_spec.rb
|
186
187
|
- spec/killbill_client/remote/api_spec.rb
|
187
188
|
- spec/killbill_client/remote/model_spec.rb
|
@@ -192,34 +193,26 @@ homepage: http://www.killbilling.org
|
|
192
193
|
licenses:
|
193
194
|
- Apache License (2.0)
|
194
195
|
metadata: {}
|
195
|
-
post_install_message:
|
196
|
+
post_install_message:
|
196
197
|
rdoc_options:
|
197
|
-
-
|
198
|
-
-
|
198
|
+
- --exclude
|
199
|
+
- .
|
199
200
|
require_paths:
|
200
201
|
- lib
|
201
202
|
required_ruby_version: !ruby/object:Gem::Requirement
|
202
203
|
requirements:
|
203
|
-
- -
|
204
|
+
- - '>='
|
204
205
|
- !ruby/object:Gem::Version
|
205
206
|
version: 1.8.6
|
206
207
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
207
208
|
requirements:
|
208
|
-
- -
|
209
|
+
- - '>='
|
209
210
|
- !ruby/object:Gem::Version
|
210
211
|
version: '0'
|
211
212
|
requirements: []
|
212
|
-
rubyforge_project:
|
213
|
-
rubygems_version: 2.
|
214
|
-
signing_key:
|
213
|
+
rubyforge_project:
|
214
|
+
rubygems_version: 2.4.6
|
215
|
+
signing_key:
|
215
216
|
specification_version: 4
|
216
217
|
summary: Kill Bill client library.
|
217
|
-
test_files:
|
218
|
-
- spec/killbill_client/base_uri_spec.rb
|
219
|
-
- spec/killbill_client/encoding_spec.rb
|
220
|
-
- spec/killbill_client/model_relation_spec.rb
|
221
|
-
- spec/killbill_client/remote/api_spec.rb
|
222
|
-
- spec/killbill_client/remote/model_spec.rb
|
223
|
-
- spec/killbill_client/resource_spec.rb
|
224
|
-
- spec/killbill_client/resources_spec.rb
|
225
|
-
- spec/spec_helper.rb
|
218
|
+
test_files: []
|