spree_affirm 0.2.3 → 0.2.19
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.
- checksums.yaml +5 -5
- metadata +26 -75
- data/.gitignore +0 -15
- data/Gemfile +0 -19
- data/LICENSE +0 -29
- data/README.md +0 -51
- data/Rakefile +0 -15
- data/Versionfile +0 -5
- data/app/assets/javascripts/spree/backend/spree_affirm.js +0 -3
- data/app/assets/javascripts/spree/frontend/spree_affirm.js +0 -2
- data/app/assets/stylesheets/spree/backend/spree_affirm.css +0 -4
- data/app/assets/stylesheets/spree/frontend/spree_affirm.css +0 -4
- data/app/controllers/spree/affirm_controller.rb +0 -68
- data/app/models/spree/affirm_checkout.rb +0 -38
- data/app/models/spree/gateway/affirm.rb +0 -51
- data/app/views/spree/admin/log_entries/_affirm.html.erb +0 -4
- data/app/views/spree/admin/log_entries/index.html.erb +0 -28
- data/app/views/spree/admin/payments/source_forms/_affirm.html.erb +0 -19
- data/app/views/spree/admin/payments/source_views/_affirm.html.erb +0 -12
- data/app/views/spree/checkout/payment/_affirm.html.erb +0 -195
- data/bin/rails +0 -7
- data/config/locales/en.yml +0 -29
- data/config/routes.rb +0 -5
- data/db/migrate/20140514194315_create_affirm_checkout.rb +0 -10
- data/lib/active_merchant/billing/affirm.rb +0 -161
- data/lib/generators/spree_affirm/install/install_generator.rb +0 -21
- data/lib/spree_affirm.rb +0 -2
- data/lib/spree_affirm/engine.rb +0 -27
- data/lib/spree_affirm/factories.rb +0 -5
- data/lib/spree_affirm/factories/affirm_checkout_factory.rb +0 -211
- data/lib/spree_affirm/factories/affirm_payment_method_factory.rb +0 -8
- data/lib/spree_affirm/factories/payment_factory.rb +0 -10
- data/lib/spree_affirm/version.rb +0 -3
- data/spec/controllers/affirm_controller_spec.rb +0 -138
- data/spec/lib/active_merchant/billing/affirm_spec.rb +0 -294
- data/spec/models/affirm_address_validator_spec.rb +0 -13
- data/spec/models/spree_affirm_checkout_spec.rb +0 -328
- data/spec/models/spree_gateway_affirm_spec.rb +0 -134
- data/spec/spec_helper.rb +0 -98
- data/spree_affirm.gemspec +0 -30
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Affirm::AddressValidator do
|
4
|
-
it 'detects when region1_code is missing' do
|
5
|
-
input_addr = {
|
6
|
-
state: 'California for example'
|
7
|
-
}
|
8
|
-
output = Affirm::AddressValidator.normalize_affirm_address(
|
9
|
-
input_addr)
|
10
|
-
expect(output['region1_code']).to eq(input_addr['state'])
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
@@ -1,328 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
|
4
|
-
describe Spree::AffirmCheckout do
|
5
|
-
let(:valid_checkout) { FactoryGirl.create(:affirm_checkout) }
|
6
|
-
let(:affirm_payment) { FactoryGirl.create(:affirm_payment) }
|
7
|
-
|
8
|
-
|
9
|
-
describe "scopes" do
|
10
|
-
describe "with_payment_profile" do
|
11
|
-
it "returns all" do
|
12
|
-
expect(Spree::AffirmCheckout.all).to eq(Spree::AffirmCheckout.with_payment_profile)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
|
20
|
-
describe '#details' do
|
21
|
-
it "calls get_checkout from the payment provider exactly once" do
|
22
|
-
_checkout = FactoryGirl.build(:affirm_checkout, stub_details: false)
|
23
|
-
_checkout.payment_method.provider.stub(:get_checkout) do
|
24
|
-
{"hello" => "there"}
|
25
|
-
end
|
26
|
-
expect(_checkout.payment_method.provider).to receive(:get_checkout).exactly(1).times
|
27
|
-
_checkout.details
|
28
|
-
_checkout.details
|
29
|
-
_checkout.details
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
|
34
|
-
describe "#valid?" do
|
35
|
-
context "with all valid checkout details" do
|
36
|
-
it "should return true" do
|
37
|
-
expect(valid_checkout.valid?).to be(true)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe "#check_valid_products" do
|
43
|
-
context "with all matching fields" do
|
44
|
-
it "does not set an error" do
|
45
|
-
valid_checkout.check_valid_products
|
46
|
-
expect(valid_checkout.errors.size).to be(0)
|
47
|
-
end
|
48
|
-
|
49
|
-
it "does not throw an error for case senstive name mismatches" do
|
50
|
-
_checkout = FactoryGirl.build(:affirm_checkout, full_name_case_mismatch: true)
|
51
|
-
_checkout.check_matching_billing_address
|
52
|
-
expect(_checkout.errors.size).to be(0)
|
53
|
-
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context "with an extra product is in the checkout details" do
|
58
|
-
it "sets an error on line_items" do
|
59
|
-
_checkout = FactoryGirl.build(:affirm_checkout, extra_line_item: true )
|
60
|
-
_checkout.check_valid_products
|
61
|
-
expect(_checkout.errors[:line_items]).to_not be_empty
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
|
66
|
-
context "with the checkout details are missing a product" do
|
67
|
-
it "sets an error on line_items" do
|
68
|
-
_checkout = FactoryGirl.build(:affirm_checkout, missing_line_item: true )
|
69
|
-
_checkout.check_valid_products
|
70
|
-
expect(_checkout.errors[:line_items]).to_not be_empty
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
context "with a line item has mismatched quantity" do
|
75
|
-
it "sets an error for the item" do
|
76
|
-
_checkout = FactoryGirl.build(:affirm_checkout, quantity_mismatch: true )
|
77
|
-
_checkout.check_valid_products
|
78
|
-
expect(_checkout.errors.size).to be(1)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
context "with a line item has mismatched price" do
|
83
|
-
it "sets an error for the item" do
|
84
|
-
_checkout = FactoryGirl.build(:affirm_checkout, price_mismatch: true )
|
85
|
-
_checkout.check_valid_products
|
86
|
-
expect(_checkout.errors.size).to be(1)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
end
|
91
|
-
|
92
|
-
describe "#check_matching_billing_address" do
|
93
|
-
context "with a matching billing address" do
|
94
|
-
it "does not set any errors for the billing_address" do
|
95
|
-
valid_checkout.check_matching_billing_address
|
96
|
-
expect(valid_checkout.errors.size).to be(0)
|
97
|
-
expect(valid_checkout.errors[:billing_address]).to be_empty
|
98
|
-
end
|
99
|
-
|
100
|
-
context "with alternate address format" do
|
101
|
-
it "does not set any errors for the billing_address" do
|
102
|
-
_checkout = FactoryGirl.build(:affirm_checkout, alternate_billing_address_format: true)
|
103
|
-
valid_checkout.check_matching_billing_address
|
104
|
-
expect(valid_checkout.errors.size).to be(0)
|
105
|
-
expect(valid_checkout.errors[:billing_address]).to be_empty
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
context "with a name.full instead of first/last" do
|
110
|
-
it "does not set any error for the billing_address" do
|
111
|
-
_checkout = FactoryGirl.build(:affirm_checkout, billing_address_full_name: true)
|
112
|
-
_checkout.check_matching_billing_address
|
113
|
-
expect(_checkout.errors[:billing_address]).to be_empty
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
context "with a mismtached billing address" do
|
119
|
-
it "sets an error for the billing_address" do
|
120
|
-
_checkout = FactoryGirl.build(:affirm_checkout, billing_address_mismatch: true)
|
121
|
-
_checkout.check_matching_billing_address
|
122
|
-
expect(_checkout.errors[:billing_address]).not_to be_empty
|
123
|
-
end
|
124
|
-
|
125
|
-
context "with alternate address format" do
|
126
|
-
it "sets an error for the billing_address" do
|
127
|
-
_checkout = FactoryGirl.build(:affirm_checkout, billing_address_mismatch: true, alternate_billing_address_format: true)
|
128
|
-
_checkout.check_matching_billing_address
|
129
|
-
expect(_checkout.errors[:billing_address]).not_to be_empty
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
|
134
|
-
context "with a name.full instead of first/last" do
|
135
|
-
it "sets an error for the billing_address" do
|
136
|
-
_checkout = FactoryGirl.build(:affirm_checkout, billing_address_mismatch: true, billing_address_full_name: true)
|
137
|
-
_checkout.check_matching_billing_address
|
138
|
-
expect(_checkout.errors[:billing_address]).not_to be_empty
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
describe "#check_matching_shipping_address" do
|
147
|
-
context "with a matching shipping address" do
|
148
|
-
it "does not set an error for the shipping_address" do
|
149
|
-
valid_checkout.check_matching_shipping_address
|
150
|
-
expect(valid_checkout.errors[:shipping_address]).to be_empty
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
|
155
|
-
context "with a mismatched shipping address" do
|
156
|
-
it "adds an error for the shipping_address" do
|
157
|
-
_checkout = FactoryGirl.build(:affirm_checkout, shipping_address_mismatch: true)
|
158
|
-
_checkout.check_matching_shipping_address
|
159
|
-
expect(_checkout.errors[:shipping_address]).not_to be_empty
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
|
165
|
-
describe "#check_matching_billing_email" do
|
166
|
-
context "with a matching billing email" do
|
167
|
-
it "does not set an error for the billing_email" do
|
168
|
-
valid_checkout.check_matching_billing_email
|
169
|
-
expect(valid_checkout.errors[:billing_email]).to be_empty
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
|
174
|
-
context "with a mismatched billing email" do
|
175
|
-
it "adds an error for billing_email" do
|
176
|
-
_checkout = FactoryGirl.build(:affirm_checkout, billing_email_mismatch: true)
|
177
|
-
_checkout.check_matching_billing_email
|
178
|
-
expect(_checkout.errors[:billing_email]).not_to be_empty
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
describe "actions" do
|
184
|
-
|
185
|
-
describe "#actions" do
|
186
|
-
it "returns capture, void, and credit" do
|
187
|
-
expect(valid_checkout.actions).to eq(['capture', 'void', 'credit'])
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
|
192
|
-
describe "can_capture?" do
|
193
|
-
context "with a payment response code set" do
|
194
|
-
before(:each) { affirm_payment.response_code = "1234-1234" }
|
195
|
-
|
196
|
-
context "with a payment in pending state" do
|
197
|
-
before(:each) { affirm_payment.state = 'pending' }
|
198
|
-
|
199
|
-
it "returns true" do
|
200
|
-
expect(valid_checkout.can_capture?(affirm_payment)).to be(true)
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
|
205
|
-
context "with a payment in checkout state" do
|
206
|
-
before(:each) { affirm_payment.state = 'checkout' }
|
207
|
-
|
208
|
-
it "returns true" do
|
209
|
-
expect(valid_checkout.can_capture?(affirm_payment)).to be(true)
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
|
214
|
-
context "with a payment in complete state" do
|
215
|
-
before(:each) { affirm_payment.state = 'complete' }
|
216
|
-
|
217
|
-
it "returns false" do
|
218
|
-
expect(valid_checkout.can_capture?(affirm_payment)).to be(false)
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
end
|
223
|
-
|
224
|
-
|
225
|
-
context "with no response code set on the payment" do
|
226
|
-
before(:each) { affirm_payment.response_code = nil }
|
227
|
-
|
228
|
-
it "returns false" do
|
229
|
-
expect(valid_checkout.can_capture?(affirm_payment)).to be(false)
|
230
|
-
end
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
|
235
|
-
describe "can_void?" do
|
236
|
-
context "with a payment response code set" do
|
237
|
-
before(:each) { affirm_payment.response_code = "1234-1234" }
|
238
|
-
|
239
|
-
context "with a payment in pending state" do
|
240
|
-
before(:each) { affirm_payment.state = 'pending' }
|
241
|
-
|
242
|
-
it "returns true" do
|
243
|
-
expect(valid_checkout.can_void?(affirm_payment)).to be(true)
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
context "with a payment in checkout state" do
|
248
|
-
before(:each) { affirm_payment.state = 'checkout' }
|
249
|
-
|
250
|
-
it "returns false" do
|
251
|
-
expect(valid_checkout.can_void?(affirm_payment)).to be(false)
|
252
|
-
end
|
253
|
-
end
|
254
|
-
|
255
|
-
|
256
|
-
context "with a payment in complete state" do
|
257
|
-
before(:each) { affirm_payment.state = 'complete' }
|
258
|
-
|
259
|
-
it "returns false" do
|
260
|
-
expect(valid_checkout.can_void?(affirm_payment)).to be(false)
|
261
|
-
end
|
262
|
-
end
|
263
|
-
end
|
264
|
-
|
265
|
-
|
266
|
-
context "with no response code set on the payment" do
|
267
|
-
before(:each) { affirm_payment.response_code = nil }
|
268
|
-
|
269
|
-
it "returns false" do
|
270
|
-
expect(valid_checkout.can_void?(affirm_payment)).to be(false)
|
271
|
-
end
|
272
|
-
end
|
273
|
-
end
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
describe "can_credit?" do
|
278
|
-
context "when the payment has not been completed" do
|
279
|
-
before(:each) { affirm_payment.state = 'pending' }
|
280
|
-
|
281
|
-
it "returns false" do
|
282
|
-
expect(valid_checkout.can_credit?(affirm_payment)).to be(false)
|
283
|
-
end
|
284
|
-
end
|
285
|
-
|
286
|
-
context "when the payment's order state is not 'credit_owed'" do
|
287
|
-
before(:each) do
|
288
|
-
affirm_payment.state = 'completed'
|
289
|
-
affirm_payment.order.payment_state = 'completed'
|
290
|
-
end
|
291
|
-
|
292
|
-
it "returns false" do
|
293
|
-
expect(valid_checkout.can_credit?(affirm_payment)).to be(false)
|
294
|
-
end
|
295
|
-
end
|
296
|
-
|
297
|
-
context "when the payement's order state is 'credit_owed'" do
|
298
|
-
before(:each) { affirm_payment.order.payment_state = 'credit_owed' }
|
299
|
-
|
300
|
-
context "when the payment has been completed" do
|
301
|
-
before(:each) { affirm_payment.state = 'completed'}
|
302
|
-
|
303
|
-
context "when the payment credit_allowed is greater than 0" do
|
304
|
-
before(:each) do
|
305
|
-
affirm_payment.stub(:credit_allowed).and_return 100
|
306
|
-
end
|
307
|
-
|
308
|
-
it "returns true" do
|
309
|
-
expect(valid_checkout.can_credit?(affirm_payment)).to be(true)
|
310
|
-
end
|
311
|
-
end
|
312
|
-
|
313
|
-
|
314
|
-
context "when the payment credit_allowed is equal to 0" do
|
315
|
-
before(:each) do
|
316
|
-
affirm_payment.stub(:credit_allowed).and_return 0
|
317
|
-
end
|
318
|
-
|
319
|
-
it "returns false" do
|
320
|
-
expect(valid_checkout.can_credit?(affirm_payment)).to be(false)
|
321
|
-
end
|
322
|
-
end
|
323
|
-
end
|
324
|
-
end
|
325
|
-
|
326
|
-
end
|
327
|
-
end
|
328
|
-
end
|
@@ -1,134 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Spree::Gateway::Affirm do
|
4
|
-
let(:affirm_payment) { FactoryGirl.create(:affirm_payment) }
|
5
|
-
let(:affirm_checkout) { FactoryGirl.create(:affirm_checkout) }
|
6
|
-
|
7
|
-
describe '#provider_class' do
|
8
|
-
it "returns the Affirm ActiveMerchant class" do
|
9
|
-
expect(affirm_payment.payment_method.provider_class).to be(ActiveMerchant::Billing::Affirm)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
describe '#payment_source_class' do
|
14
|
-
it "returns the affirm_checkout class" do
|
15
|
-
expect(affirm_payment.payment_method.payment_source_class).to be(Spree::AffirmCheckout)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe '#source_required?' do
|
20
|
-
it "returns true" do
|
21
|
-
expect(affirm_payment.payment_method.source_required?).to be(true)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe '#method_type?' do
|
26
|
-
it 'returns "affirm"' do
|
27
|
-
expect(affirm_payment.payment_method.method_type).to eq("affirm")
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe '#actions?' do
|
32
|
-
it "retuns capture, void and credit" do
|
33
|
-
expect(affirm_payment.payment_method.actions).to eq(['capture', 'void', 'credit'])
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe '#supports?' do
|
38
|
-
it "returns true if the source is an AffirmCheckout" do
|
39
|
-
expect(affirm_payment.payment_method.supports?(affirm_checkout)).to be(true)
|
40
|
-
end
|
41
|
-
|
42
|
-
it "returns false when the source is not an affirm" do
|
43
|
-
expect(affirm_payment.payment_method.supports?(6)).to be(false)
|
44
|
-
expect(affirm_payment.payment_method.supports?(affirm_payment)).to be(false)
|
45
|
-
expect(affirm_payment.payment_method.supports?(Spree::Order.new)).to be(false)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
|
50
|
-
describe "#cancel" do
|
51
|
-
context "when there is no payment with the given charge_ari" do
|
52
|
-
it "returns nil" do
|
53
|
-
expect(affirm_payment.payment_method.cancel("xxxx-xxxx")).to be(nil)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context "when the payment is in a completed state" do
|
58
|
-
before(:each) do
|
59
|
-
affirm_payment.stub(:completed?).and_return true
|
60
|
-
affirm_payment.state = "completed"
|
61
|
-
affirm_payment.save
|
62
|
-
end
|
63
|
-
|
64
|
-
context "when credit_allowed amount is > 0" do
|
65
|
-
it "calls credit! on the payment with the credit_allowed amount" do
|
66
|
-
Spree::Payment.stub_chain(:valid, :where, :first).and_return(affirm_payment)
|
67
|
-
affirm_payment.stub(:can_credit?).and_return(true)
|
68
|
-
expect(affirm_payment).to receive(:credit!).and_return false
|
69
|
-
affirm_payment.payment_method.cancel affirm_payment.response_code
|
70
|
-
end
|
71
|
-
|
72
|
-
it "creates an adjustment for the -credit_allowed amount" do
|
73
|
-
Spree::Payment.stub_chain(:valid, :where, :first).and_return(affirm_payment)
|
74
|
-
affirm_payment.stub(:can_credit?).and_return(true)
|
75
|
-
expect(affirm_payment).to receive(:credit!).and_return false
|
76
|
-
_payment_amount = affirm_payment.credit_allowed
|
77
|
-
affirm_payment.payment_method.cancel affirm_payment.response_code
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
context "when credit_allowed amount is 0" do
|
82
|
-
it "does not credit the payment" do
|
83
|
-
Spree::Payment.stub_chain(:valid, :where, :first).and_return(affirm_payment)
|
84
|
-
affirm_payment.stub(:can_credit?).and_return(false)
|
85
|
-
expect(affirm_payment).not_to receive(:credit!)
|
86
|
-
affirm_payment.payment_method.cancel affirm_payment.response_code
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
context "when the payment is in a failed state" do
|
92
|
-
before do
|
93
|
-
affirm_payment.state = "failed"
|
94
|
-
affirm_payment.save
|
95
|
-
end
|
96
|
-
|
97
|
-
it "does nothing" do
|
98
|
-
expect(affirm_payment).not_to receive(:credit!)
|
99
|
-
expect(affirm_payment).not_to receive(:void_transaction!)
|
100
|
-
affirm_payment.payment_method.cancel affirm_payment.response_code
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
context "when the payment is in an invalid state" do
|
105
|
-
before do
|
106
|
-
affirm_payment.state = "invalid"
|
107
|
-
affirm_payment.save
|
108
|
-
end
|
109
|
-
|
110
|
-
it "does nothing" do
|
111
|
-
expect(affirm_payment).not_to receive(:credit!)
|
112
|
-
expect(affirm_payment).not_to receive(:void_transaction!)
|
113
|
-
affirm_payment.payment_method.cancel affirm_payment.response_code
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
|
118
|
-
context "when the payment is in a pending state" do
|
119
|
-
before do
|
120
|
-
affirm_payment.stub(:pending?).and_return true
|
121
|
-
affirm_payment.state = "pending"
|
122
|
-
affirm_payment.save
|
123
|
-
end
|
124
|
-
|
125
|
-
it "voids the transaction" do
|
126
|
-
Spree::Payment.stub_chain(:valid, :where, :first).and_return(affirm_payment)
|
127
|
-
expect(affirm_payment).not_to receive(:credit!)
|
128
|
-
expect(affirm_payment).to receive(:void_transaction!).and_return false
|
129
|
-
affirm_payment.payment_method.cancel affirm_payment.response_code
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
end
|
134
|
-
end
|