affirm 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/affirm.gemspec +1 -1
- data/lib/affirm.rb +1 -0
- data/lib/affirm/api.rb +2 -2
- data/lib/affirm/charge.rb +14 -6
- data/lib/affirm/client.rb +0 -9
- data/lib/affirm/errors/charge_error.rb +3 -0
- data/spec/charge_spec.rb +18 -9
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7e00e989ab313897e9c4276f4b75e33399cefdb
|
4
|
+
data.tar.gz: a918946c0a75ffcf870e79208e8f4d30244a4ddb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf933ec1f98c796aeb348c80dcfe4d104528138a5ac47d2cff0041665efeec1651ee23f78302c4bf94517b507d185825a3aa2ae2099bf739ecd6791425b6ff03
|
7
|
+
data.tar.gz: 7dc451129c89024fc10618b6932918ca7f0cf5cf0b641987fb542d9dccffafe829ef96a01cf4c97f1c031131286ceee0a89852b3033939ed25cafce0002f9adc
|
data/README.md
CHANGED
@@ -92,8 +92,10 @@ charge.update(order_id: "1234", shipping_carrier: "USPS", shipping_confirmation:
|
|
92
92
|
Returns an `Affirm::ChargeEvent` object of type `update`.
|
93
93
|
|
94
94
|
## Exceptions
|
95
|
+
Errors due to failed requests with the charges api (ie http code 400) will raise an `Affirm::ChargeError`.
|
96
|
+
|
95
97
|
Special exceptions are raised for 5xx, 404 and 401 responses, yielding an `Affirm::ServerError`,
|
96
|
-
`Affirm::ResourceNotFoundError` and `Affirm::AuthenticationError`, respectively. These are subclassed from
|
98
|
+
`Affirm::ResourceNotFoundError` and `Affirm::AuthenticationError`, respectively. These are all subclassed from
|
97
99
|
`Affirm::Error`.
|
98
100
|
|
99
101
|
All exceptions have the following methods on them:
|
data/affirm.gemspec
CHANGED
@@ -2,7 +2,7 @@ Gem::Specification.new do |s|
|
|
2
2
|
s.name = "affirm"
|
3
3
|
s.summary = "Affirm Ruby Client Library"
|
4
4
|
s.description = "Ruby client library for integrating with Affirm financing payments"
|
5
|
-
s.version = "1.
|
5
|
+
s.version = "1.1.0"
|
6
6
|
s.license = "Apache License Version 2.0"
|
7
7
|
s.author = "Reverb.com"
|
8
8
|
s.email = "dev@reverb.com"
|
data/lib/affirm.rb
CHANGED
@@ -7,6 +7,7 @@ require 'affirm/charge_event'
|
|
7
7
|
require 'affirm/charge'
|
8
8
|
|
9
9
|
require 'affirm/errors/error'
|
10
|
+
require 'affirm/errors/charge_error'
|
10
11
|
require 'affirm/errors/authentication_error'
|
11
12
|
require 'affirm/errors/resource_not_found_error'
|
12
13
|
require 'affirm/errors/server_error'
|
data/lib/affirm/api.rb
CHANGED
@@ -2,10 +2,10 @@ module Affirm
|
|
2
2
|
class API
|
3
3
|
class << self
|
4
4
|
attr_accessor :public_key, :secret_key, :api_url
|
5
|
-
|
5
|
+
@client = nil
|
6
6
|
|
7
7
|
def client
|
8
|
-
|
8
|
+
@client ||= Affirm::Client.new(
|
9
9
|
public_key: public_key,
|
10
10
|
secret_key: secret_key,
|
11
11
|
api_url: api_url
|
data/lib/affirm/charge.rb
CHANGED
@@ -15,9 +15,13 @@ module Affirm
|
|
15
15
|
#
|
16
16
|
# checkout_token - (required) string. The charge token passed through the confirmation response.
|
17
17
|
def self.create(checkout_token, client: Affirm::API.client)
|
18
|
-
response = client.make_request
|
18
|
+
response = client.make_request("/charges", :post, checkout_token: checkout_token)
|
19
19
|
|
20
|
-
|
20
|
+
if response.success?
|
21
|
+
new(attrs: response.body, client: client)
|
22
|
+
else
|
23
|
+
raise ChargeError.from_response(response)
|
24
|
+
end
|
21
25
|
end
|
22
26
|
|
23
27
|
##
|
@@ -106,10 +110,14 @@ module Affirm
|
|
106
110
|
end
|
107
111
|
|
108
112
|
def api_request(url, method, params={})
|
109
|
-
response = @client.make_request
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
+
response = @client.make_request(url, method, params)
|
114
|
+
if response.success?
|
115
|
+
event = ChargeEvent.new(response.body)
|
116
|
+
@events << event
|
117
|
+
event
|
118
|
+
else
|
119
|
+
raise ChargeError.from_response(response)
|
120
|
+
end
|
113
121
|
end
|
114
122
|
end
|
115
123
|
end
|
data/lib/affirm/client.rb
CHANGED
@@ -28,15 +28,6 @@ module Affirm
|
|
28
28
|
handle_errors(affirm_response)
|
29
29
|
end
|
30
30
|
|
31
|
-
# like make_request, but raise error on failure
|
32
|
-
def make_request!(path, method, data={})
|
33
|
-
response = make_request(path, method, data)
|
34
|
-
|
35
|
-
raise Affirm::Error.from_response(response) if response.error?
|
36
|
-
|
37
|
-
response
|
38
|
-
end
|
39
|
-
|
40
31
|
private
|
41
32
|
|
42
33
|
def parse_response(response)
|
data/spec/charge_spec.rb
CHANGED
@@ -74,8 +74,17 @@ describe Affirm::Charge do
|
|
74
74
|
let(:response_code) { 422 }
|
75
75
|
let(:response_body) { load_fixture("charges/invalid_request.json") }
|
76
76
|
|
77
|
-
it "raises
|
78
|
-
expect { Affirm::Charge.create("token") }.to raise_error(Affirm::
|
77
|
+
it "raises a charge error" do
|
78
|
+
expect { Affirm::Charge.create("token") }.to raise_error(Affirm::ChargeError)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "other api error" do
|
83
|
+
let(:response_code) { 500 }
|
84
|
+
let(:response_body) { "" }
|
85
|
+
|
86
|
+
it "raises relevant error" do
|
87
|
+
expect { Affirm::Charge.create("token") }.to raise_error(Affirm::ServerError)
|
79
88
|
end
|
80
89
|
end
|
81
90
|
end
|
@@ -112,8 +121,8 @@ describe Affirm::Charge do
|
|
112
121
|
let(:response_code) { 422 }
|
113
122
|
let(:response_body) { load_fixture("charges/invalid_request.json") }
|
114
123
|
|
115
|
-
it "raises
|
116
|
-
expect { charge.capture }.to raise_error(Affirm::
|
124
|
+
it "raises a charge error" do
|
125
|
+
expect { charge.capture }.to raise_error(Affirm::ChargeError)
|
117
126
|
end
|
118
127
|
end
|
119
128
|
end
|
@@ -143,8 +152,8 @@ describe Affirm::Charge do
|
|
143
152
|
let(:response_code) { 422 }
|
144
153
|
let(:response_body) { load_fixture("charges/invalid_request.json") }
|
145
154
|
|
146
|
-
it "raises
|
147
|
-
expect { charge.void }.to raise_error(Affirm::
|
155
|
+
it "raises a charge error" do
|
156
|
+
expect { charge.void }.to raise_error(Affirm::ChargeError)
|
148
157
|
end
|
149
158
|
end
|
150
159
|
end
|
@@ -184,8 +193,8 @@ describe Affirm::Charge do
|
|
184
193
|
let(:response_code) { 422 }
|
185
194
|
let(:response_body) { load_fixture("charges/invalid_request.json") }
|
186
195
|
|
187
|
-
it "raises
|
188
|
-
expect { charge.refund }.to raise_error(Affirm::
|
196
|
+
it "raises a charge error" do
|
197
|
+
expect { charge.refund }.to raise_error(Affirm::ChargeError)
|
189
198
|
end
|
190
199
|
end
|
191
200
|
end
|
@@ -223,7 +232,7 @@ describe Affirm::Charge do
|
|
223
232
|
let(:response_body) { load_fixture("charges/invalid_request.json") }
|
224
233
|
|
225
234
|
it "raises an error" do
|
226
|
-
expect { charge.update }.to raise_error(Affirm::
|
235
|
+
expect { charge.update }.to raise_error(Affirm::ChargeError)
|
227
236
|
end
|
228
237
|
end
|
229
238
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: affirm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Reverb.com
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typhoeus
|
@@ -94,6 +94,7 @@ files:
|
|
94
94
|
- lib/affirm/charge_event.rb
|
95
95
|
- lib/affirm/client.rb
|
96
96
|
- lib/affirm/errors/authentication_error.rb
|
97
|
+
- lib/affirm/errors/charge_error.rb
|
97
98
|
- lib/affirm/errors/error.rb
|
98
99
|
- lib/affirm/errors/resource_not_found_error.rb
|
99
100
|
- lib/affirm/errors/server_error.rb
|