solidus_gateway 0.9.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.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +1 -0
- data/.travis.yml +23 -0
- data/Gemfile +9 -0
- data/LICENSE.md +26 -0
- data/README.md +38 -0
- data/Rakefile +21 -0
- data/app/models/spree/billing_integration/skrill/quick_checkout.rb +48 -0
- data/app/models/spree/gateway/authorize_net.rb +31 -0
- data/app/models/spree/gateway/authorize_net_cim.rb +201 -0
- data/app/models/spree/gateway/balanced_gateway.rb +65 -0
- data/app/models/spree/gateway/banwire.rb +15 -0
- data/app/models/spree/gateway/beanstream.rb +193 -0
- data/app/models/spree/gateway/braintree_gateway.rb +184 -0
- data/app/models/spree/gateway/card_save.rb +10 -0
- data/app/models/spree/gateway/data_cash.rb +10 -0
- data/app/models/spree/gateway/eway.rb +20 -0
- data/app/models/spree/gateway/linkpoint.rb +28 -0
- data/app/models/spree/gateway/maxipago.rb +14 -0
- data/app/models/spree/gateway/migs.rb +11 -0
- data/app/models/spree/gateway/moneris.rb +10 -0
- data/app/models/spree/gateway/pay_junction.rb +16 -0
- data/app/models/spree/gateway/pay_pal_gateway.rb +12 -0
- data/app/models/spree/gateway/payflow_pro.rb +18 -0
- data/app/models/spree/gateway/paymill.rb +12 -0
- data/app/models/spree/gateway/pin_gateway.rb +60 -0
- data/app/models/spree/gateway/sage_pay.rb +11 -0
- data/app/models/spree/gateway/secure_pay_au.rb +10 -0
- data/app/models/spree/gateway/spreedly_core_gateway.rb +10 -0
- data/app/models/spree/gateway/stripe_gateway.rb +126 -0
- data/app/models/spree/gateway/usa_epay.rb +9 -0
- data/app/models/spree/gateway/worldpay.rb +91 -0
- data/app/models/spree/skrill_transaction.rb +19 -0
- data/bin/rails +7 -0
- data/circle.yml +6 -0
- data/config/locales/bg.yml +11 -0
- data/config/locales/de.yml +11 -0
- data/config/locales/en.yml +30 -0
- data/config/locales/sv.yml +11 -0
- data/config/routes.rb +12 -0
- data/db/migrate/20111118164631_create_skrill_transactions.rb +14 -0
- data/db/migrate/20121017004102_update_braintree_payment_method_type.rb +9 -0
- data/db/migrate/20130213222555_update_stripe_payment_method_type.rb +9 -0
- data/db/migrate/20130415222802_update_balanced_payment_method_type.rb +9 -0
- data/db/migrate/20131008221012_update_paypal_payment_method_type.rb +9 -0
- data/db/migrate/20131112133401_migrate_stripe_preferences.rb +8 -0
- data/lib/active_merchant/billing/skrill.rb +18 -0
- data/lib/assets/javascripts/spree/frontend/solidus_gateway.js +1 -0
- data/lib/assets/stylesheets/spree/frontend/solidus_gateway.css +3 -0
- data/lib/controllers/frontend/spree/checkout_controller_decorator.rb +51 -0
- data/lib/controllers/frontend/spree/skrill_status_controller.rb +39 -0
- data/lib/generators/solidus_gateway/install/install_generator.rb +28 -0
- data/lib/solidus_gateway.rb +4 -0
- data/lib/spree_gateway/engine.rb +67 -0
- data/lib/views/backend/spree/admin/log_entries/_braintree.html.erb +31 -0
- data/lib/views/backend/spree/admin/log_entries/_stripe.html.erb +28 -0
- data/lib/views/backend/spree/admin/payments/source_forms/_quickcheckout.html.erb +8 -0
- data/lib/views/backend/spree/admin/payments/source_forms/_stripe.html.erb +1 -0
- data/lib/views/backend/spree/admin/payments/source_views/_quickcheckout.html.erb +39 -0
- data/lib/views/backend/spree/admin/payments/source_views/_stripe.html.erb +1 -0
- data/lib/views/frontend/spree/checkout/payment/_quickcheckout.html.erb +26 -0
- data/lib/views/frontend/spree/checkout/payment/_stripe.html.erb +80 -0
- data/solidus_gateway.gemspec +33 -0
- data/spec/factories/skrill_factory.rb +6 -0
- data/spec/features/stripe_checkout_spec.rb +78 -0
- data/spec/lib/active_merchant/billing_skrill_spec.rb +18 -0
- data/spec/models/billing_integration/skrill_quick_checkout_spec.rb +11 -0
- data/spec/models/gateway/authorize_net_cim_spec.rb +29 -0
- data/spec/models/gateway/authorize_net_spec.rb +23 -0
- data/spec/models/gateway/balanced_gateway_spec.rb +17 -0
- data/spec/models/gateway/banwire_spec.rb +11 -0
- data/spec/models/gateway/beanstream_spec.rb +17 -0
- data/spec/models/gateway/braintree_gateway_spec.rb +437 -0
- data/spec/models/gateway/card_save_spec.rb +11 -0
- data/spec/models/gateway/data_cache_spec.rb +11 -0
- data/spec/models/gateway/eway_spec.rb +29 -0
- data/spec/models/gateway/linkpoint_spec.rb +62 -0
- data/spec/models/gateway/maxipago_spec.rb +17 -0
- data/spec/models/gateway/moneris_spec.rb +11 -0
- data/spec/models/gateway/pay_junction_spec.rb +23 -0
- data/spec/models/gateway/pay_pal_spec.rb +11 -0
- data/spec/models/gateway/payflow_pro_spec.rb +23 -0
- data/spec/models/gateway/paymill_spec.rb +11 -0
- data/spec/models/gateway/pin_gateway_spec.rb +55 -0
- data/spec/models/gateway/sage_pay_spec.rb +11 -0
- data/spec/models/gateway/secure_pay_au_spec.rb +11 -0
- data/spec/models/gateway/stripe_gateway_spec.rb +200 -0
- data/spec/models/gateway/usa_epay_spec.rb +49 -0
- data/spec/models/gateway/worldpay_spec.rb +11 -0
- data/spec/models/skrill_transaction_spec.rb +9 -0
- data/spec/spec_helper.rb +50 -0
- metadata +317 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Spree::Gateway::CardSave do
|
|
4
|
+
let(:gateway) { described_class.create!(name: 'CardSave') }
|
|
5
|
+
|
|
6
|
+
context '.provider_class' do
|
|
7
|
+
it 'is a CardSave gateway' do
|
|
8
|
+
expect(gateway.provider_class).to eq ::ActiveMerchant::Billing::CardSaveGateway
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Spree::Gateway::DataCash do
|
|
4
|
+
let(:gateway) { described_class.create!(name: 'DataCash') }
|
|
5
|
+
|
|
6
|
+
context '.provider_class' do
|
|
7
|
+
it 'is a DataCash gateway' do
|
|
8
|
+
expect(gateway.provider_class).to eq ::ActiveMerchant::Billing::DataCashGateway
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Spree::Gateway::Eway do
|
|
4
|
+
let(:gateway) { described_class.create!(name: 'Eway') }
|
|
5
|
+
|
|
6
|
+
context '.provider_class' do
|
|
7
|
+
it 'is a Eway gateway' do
|
|
8
|
+
expect(gateway.provider_class).to eq ::ActiveMerchant::Billing::EwayGateway
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
context '.auto_capture?' do
|
|
13
|
+
it 'supports purchase method only' do
|
|
14
|
+
expect(gateway.auto_capture?).to be true
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
describe 'options' do
|
|
19
|
+
it 'include :test => true in when :test_mode is true' do
|
|
20
|
+
gateway.preferred_test_mode = true
|
|
21
|
+
expect(gateway.options[:test]).to be true
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'does not include :test when test_mode is false' do
|
|
25
|
+
gateway.preferred_test_mode = false
|
|
26
|
+
expect(gateway.options[:test]).to be false
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Spree::Gateway::Linkpoint do
|
|
4
|
+
let(:gateway) { described_class.create!(name: 'Linkpoint') }
|
|
5
|
+
let(:provider) { double('provider') }
|
|
6
|
+
let(:money) { double('money') }
|
|
7
|
+
let(:credit_card) { double('credit_card') }
|
|
8
|
+
let(:identification) { double('identification') }
|
|
9
|
+
let(:options) { { subtotal: 3, discount: -1 } }
|
|
10
|
+
|
|
11
|
+
before do
|
|
12
|
+
allow(gateway.provider_class).to receive_messages(new: provider)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
context '.provider_class' do
|
|
16
|
+
it 'is a Linkpoint gateway' do
|
|
17
|
+
expect(gateway.provider_class).to eq ::ActiveMerchant::Billing::LinkpointGateway
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
context '#authorize' do
|
|
22
|
+
it 'adds the discount to the subtotal' do
|
|
23
|
+
expect(provider).to receive(:authorize)
|
|
24
|
+
.with(money, credit_card, subtotal: 2, discount: 0)
|
|
25
|
+
gateway.authorize(money, credit_card, options)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
context '#purchase' do
|
|
30
|
+
it 'adds the discount to the subtotal' do
|
|
31
|
+
expect(provider).to receive(:purchase)
|
|
32
|
+
.with(money, credit_card, subtotal: 2, discount: 0)
|
|
33
|
+
gateway.purchase(money, credit_card, options)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
context '#capture' do
|
|
38
|
+
let(:authorization) { double('authorization') }
|
|
39
|
+
|
|
40
|
+
it 'adds the discount to the subtotal' do
|
|
41
|
+
expect(provider).to receive(:capture)
|
|
42
|
+
.with(money, authorization, subtotal: 2, discount: 0)
|
|
43
|
+
gateway.capture(money, authorization, options)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
context '#void' do
|
|
48
|
+
it 'adds the discount to the subtotal' do
|
|
49
|
+
expect(provider).to receive(:void)
|
|
50
|
+
.with(identification, subtotal: 2, discount: 0)
|
|
51
|
+
gateway.void(identification, options)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
context '#credit' do
|
|
56
|
+
it 'adds the discount to the subtotal' do
|
|
57
|
+
expect(provider).to receive(:credit)
|
|
58
|
+
.with(money, identification, subtotal: 2, discount: 0)
|
|
59
|
+
gateway.credit(money, identification, options)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Spree::Gateway::Maxipago do
|
|
4
|
+
let(:gateway) { described_class.create!(name: 'Maxipago') }
|
|
5
|
+
|
|
6
|
+
context '.provider_class' do
|
|
7
|
+
it 'is a Maxipago gateway' do
|
|
8
|
+
expect(subject.provider_class).to eq ::ActiveMerchant::Billing::MaxipagoGateway
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
context '.auto_capture?' do
|
|
13
|
+
it 'return true' do
|
|
14
|
+
expect(subject.auto_capture?).to be true
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Spree::Gateway::Moneris do
|
|
4
|
+
let(:gateway) { described_class.create!(name: 'Moneris') }
|
|
5
|
+
|
|
6
|
+
context '.provider_class' do
|
|
7
|
+
it 'is a Moneris gateway' do
|
|
8
|
+
expect(gateway.provider_class).to eq ::ActiveMerchant::Billing::MonerisGateway
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Spree::Gateway::PayJunction do
|
|
4
|
+
let(:gateway) { described_class.create!(name: 'PayJunction') }
|
|
5
|
+
|
|
6
|
+
context '.provider_class' do
|
|
7
|
+
it 'is a PayJunction gateway' do
|
|
8
|
+
expect(gateway.provider_class).to eq ::ActiveMerchant::Billing::PayJunctionGateway
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe 'options' do
|
|
13
|
+
it 'include :test => true in when :test_mode is true' do
|
|
14
|
+
gateway.preferred_test_mode = true
|
|
15
|
+
expect(gateway.options[:test]).to be true
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'does not include :test when test_mode is false' do
|
|
19
|
+
gateway.preferred_test_mode = false
|
|
20
|
+
expect(gateway.options[:test]).to be false
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Spree::Gateway::PayPalGateway do
|
|
4
|
+
let(:gateway) { described_class.create!(name: 'PayPal') }
|
|
5
|
+
|
|
6
|
+
context '.provider_class' do
|
|
7
|
+
it 'is a PayPal gateway' do
|
|
8
|
+
expect(gateway.provider_class).to eq ::ActiveMerchant::Billing::PaypalGateway
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Spree::Gateway::PayflowPro do
|
|
4
|
+
let(:gateway) { described_class.create!(name: 'PayflowPro') }
|
|
5
|
+
|
|
6
|
+
context '.provider_class' do
|
|
7
|
+
it 'is a Payflow gateway' do
|
|
8
|
+
expect(gateway.provider_class).to eq ::ActiveMerchant::Billing::PayflowGateway
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe 'options' do
|
|
13
|
+
it 'include :test => true when :test_mode is true' do
|
|
14
|
+
gateway.preferred_test_mode = true
|
|
15
|
+
expect(gateway.options[:test]).to be true
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'does not include :test when test_mode is false' do
|
|
19
|
+
gateway.preferred_test_mode = false
|
|
20
|
+
expect(gateway.options[:test]).to be false
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Spree::Gateway::Paymill do
|
|
4
|
+
let(:gateway) { described_class.create!(name: 'Paymill') }
|
|
5
|
+
|
|
6
|
+
context '.provider_class' do
|
|
7
|
+
it 'is a Paymill gateway' do
|
|
8
|
+
expect(gateway.provider_class).to eq ::ActiveMerchant::Billing::PaymillGateway
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Spree::Gateway::PinGateway do
|
|
4
|
+
|
|
5
|
+
before do
|
|
6
|
+
Spree::Gateway.update_all(active: false)
|
|
7
|
+
@gateway = described_class.create!(name: 'Pin Gateway', environment: 'sandbox', active: true)
|
|
8
|
+
@gateway.set_preference(:api_key, 'W_VzkRCZSILiKWUS-dndUg')
|
|
9
|
+
@gateway.save!
|
|
10
|
+
|
|
11
|
+
country = create(:country, name: 'Australia', iso_name: 'Australia', iso3: 'AUS', iso: 'AU', numcode: 61)
|
|
12
|
+
state = create(:state, name: 'Victoria', abbr: 'VIC', country: country)
|
|
13
|
+
address = create(:address,
|
|
14
|
+
firstname: 'Ronald C',
|
|
15
|
+
lastname: 'Robot',
|
|
16
|
+
address1: '1234 My Street',
|
|
17
|
+
address2: 'Apt 1',
|
|
18
|
+
city: 'Melbourne',
|
|
19
|
+
zipcode: '3000',
|
|
20
|
+
phone: '88888888',
|
|
21
|
+
state: state,
|
|
22
|
+
country: country
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
order = create(:order_with_totals, bill_address: address, ship_address: address)
|
|
26
|
+
order.update!
|
|
27
|
+
|
|
28
|
+
credit_card = create(:credit_card,
|
|
29
|
+
verification_value: '123',
|
|
30
|
+
number: '5520000000000000',
|
|
31
|
+
month: 5,
|
|
32
|
+
year: Time.now.year + 1,
|
|
33
|
+
name: 'Ronald C Robot',
|
|
34
|
+
cc_type: 'mastercard'
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
@payment = create(:payment, source: credit_card, order: order, payment_method: @gateway, amount: 10.00)
|
|
38
|
+
@payment.payment_method.environment = 'test'
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it 'can purchase' do
|
|
42
|
+
@payment.purchase!
|
|
43
|
+
expect(@payment.state).to eq 'completed'
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Regression test for #106
|
|
47
|
+
it 'uses auto capturing' do
|
|
48
|
+
expect(@gateway.auto_capture?).to be true
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it 'always uses purchase' do
|
|
52
|
+
expect(@payment).to receive(:purchase!)
|
|
53
|
+
@payment.process!
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Spree::Gateway::SagePay do
|
|
4
|
+
let(:gateway) { described_class.create!(name: 'SagePay') }
|
|
5
|
+
|
|
6
|
+
context '.provider_class' do
|
|
7
|
+
it 'is a SagePay gateway' do
|
|
8
|
+
expect(gateway.provider_class).to eq ::ActiveMerchant::Billing::SagePayGateway
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Spree::Gateway::SecurePayAU do
|
|
4
|
+
let(:gateway) { described_class.create!(name: 'SecurePayAU') }
|
|
5
|
+
|
|
6
|
+
context '.provider_class' do
|
|
7
|
+
it 'is a SecurePayAU gateway' do
|
|
8
|
+
expect(gateway.provider_class).to eq ::ActiveMerchant::Billing::SecurePayAuGateway
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Spree::Gateway::StripeGateway do
|
|
4
|
+
let(:secret_key) { 'key' }
|
|
5
|
+
let(:email) { 'customer@example.com' }
|
|
6
|
+
let(:source) { Spree::CreditCard.new }
|
|
7
|
+
|
|
8
|
+
let(:payment) {
|
|
9
|
+
double('Spree::Payment',
|
|
10
|
+
source: source,
|
|
11
|
+
order: double('Spree::Order',
|
|
12
|
+
email: email,
|
|
13
|
+
bill_address: bill_address
|
|
14
|
+
)
|
|
15
|
+
)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let(:provider) do
|
|
19
|
+
double('provider').tap do |p|
|
|
20
|
+
allow(p).to receive(:purchase)
|
|
21
|
+
allow(p).to receive(:authorize)
|
|
22
|
+
allow(p).to receive(:capture)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
before do
|
|
27
|
+
subject.preferences = { secret_key: secret_key }
|
|
28
|
+
allow(subject).to receive(:options_for_purchase_or_auth).and_return(['money','cc','opts'])
|
|
29
|
+
allow(subject).to receive(:provider).and_return provider
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
describe '#create_profile' do
|
|
33
|
+
before do
|
|
34
|
+
allow(payment.source).to receive(:update_attributes!)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
context 'with an order that has a bill address' do
|
|
38
|
+
let(:bill_address) {
|
|
39
|
+
double('Spree::Address',
|
|
40
|
+
address1: '123 Happy Road',
|
|
41
|
+
address2: 'Apt 303',
|
|
42
|
+
city: 'Suzarac',
|
|
43
|
+
zipcode: '95671',
|
|
44
|
+
state: double('Spree::State', name: 'Oregon'),
|
|
45
|
+
country: double('Spree::Country', name: 'United States')
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
it 'stores the bill address with the provider' do
|
|
50
|
+
expect(subject.provider).to receive(:store).with(payment.source, {
|
|
51
|
+
email: email,
|
|
52
|
+
login: secret_key,
|
|
53
|
+
|
|
54
|
+
address: {
|
|
55
|
+
address1: '123 Happy Road',
|
|
56
|
+
address2: 'Apt 303',
|
|
57
|
+
city: 'Suzarac',
|
|
58
|
+
zip: '95671',
|
|
59
|
+
state: 'Oregon',
|
|
60
|
+
country: 'United States'
|
|
61
|
+
}
|
|
62
|
+
}).and_return double.as_null_object
|
|
63
|
+
|
|
64
|
+
subject.create_profile payment
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
context 'with an order that does not have a bill address' do
|
|
69
|
+
let(:bill_address) { nil }
|
|
70
|
+
|
|
71
|
+
it 'does not store a bill address with the provider' do
|
|
72
|
+
expect(subject.provider).to receive(:store).with(payment.source, {
|
|
73
|
+
email: email,
|
|
74
|
+
login: secret_key,
|
|
75
|
+
}).and_return double.as_null_object
|
|
76
|
+
|
|
77
|
+
subject.create_profile payment
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Regression test for #141
|
|
81
|
+
context "correcting the card type" do
|
|
82
|
+
before do
|
|
83
|
+
# We don't care about this method for these tests
|
|
84
|
+
allow(subject.provider).to receive(:store).and_return(double.as_null_object)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it "converts 'American Express' to 'american_express'" do
|
|
88
|
+
payment.source.cc_type = 'American Express'
|
|
89
|
+
subject.create_profile(payment)
|
|
90
|
+
expect(payment.source.cc_type).to eq('american_express')
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
it "converts 'Diners Club' to 'diners_club'" do
|
|
94
|
+
payment.source.cc_type = 'Diners Club'
|
|
95
|
+
subject.create_profile(payment)
|
|
96
|
+
expect(payment.source.cc_type).to eq('diners_club')
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it "converts 'Visa' to 'visa'" do
|
|
100
|
+
payment.source.cc_type = 'Visa'
|
|
101
|
+
subject.create_profile(payment)
|
|
102
|
+
expect(payment.source.cc_type).to eq('visa')
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
context 'with a card represents payment_profile' do
|
|
108
|
+
let(:source) { Spree::CreditCard.new(gateway_payment_profile_id: 'tok_profileid') }
|
|
109
|
+
let(:bill_address) { nil }
|
|
110
|
+
|
|
111
|
+
it 'stores the profile_id as a card' do
|
|
112
|
+
expect(subject.provider).to receive(:store).with(source.gateway_payment_profile_id, anything).and_return double.as_null_object
|
|
113
|
+
|
|
114
|
+
subject.create_profile payment
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
context 'purchasing' do
|
|
120
|
+
after do
|
|
121
|
+
subject.purchase(19.99, 'credit card', {})
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
it 'send the payment to the provider' do
|
|
125
|
+
expect(provider).to receive(:purchase).with('money','cc','opts')
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
context 'authorizing' do
|
|
130
|
+
after do
|
|
131
|
+
subject.authorize(19.99, 'credit card', {})
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
it 'send the authorization to the provider' do
|
|
135
|
+
expect(provider).to receive(:authorize).with('money','cc','opts')
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
context 'capturing' do
|
|
140
|
+
|
|
141
|
+
after do
|
|
142
|
+
subject.capture(1234, 'response_code', {})
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
it 'convert the amount to cents' do
|
|
146
|
+
expect(provider).to receive(:capture).with(1234,anything,anything)
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
it 'use the response code as the authorization' do
|
|
150
|
+
expect(provider).to receive(:capture).with(anything,'response_code',anything)
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
context 'capture with payment class' do
|
|
155
|
+
let(:gateway) do
|
|
156
|
+
gateway = described_class.new(:environment => 'test', :active => true)
|
|
157
|
+
gateway.set_preference :secret_key, secret_key
|
|
158
|
+
allow(gateway).to receive(:options_for_purchase_or_auth).and_return(['money','cc','opts'])
|
|
159
|
+
allow(gateway).to receive(:provider).and_return provider
|
|
160
|
+
allow(gateway).to receive_messages :source_required => true
|
|
161
|
+
gateway
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
let(:order) { Spree::Order.create }
|
|
165
|
+
|
|
166
|
+
let(:card) do
|
|
167
|
+
FactoryGirl.create(
|
|
168
|
+
:credit_card,
|
|
169
|
+
gateway_customer_profile_id: 'cus_abcde',
|
|
170
|
+
imported: false
|
|
171
|
+
)
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
let(:payment) do
|
|
175
|
+
payment = Spree::Payment.new
|
|
176
|
+
payment.source = card
|
|
177
|
+
payment.order = order
|
|
178
|
+
payment.payment_method = gateway
|
|
179
|
+
payment.amount = 98.55
|
|
180
|
+
payment.state = 'pending'
|
|
181
|
+
payment.response_code = '12345'
|
|
182
|
+
payment
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
let!(:success_response) do
|
|
186
|
+
double('success_response', :success? => true,
|
|
187
|
+
:authorization => '123',
|
|
188
|
+
:avs_result => { 'code' => 'avs-code' },
|
|
189
|
+
:cvv_result => { 'code' => 'cvv-code', 'message' => "CVV Result"})
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
after do
|
|
193
|
+
payment.capture!
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
it 'gets correct amount' do
|
|
197
|
+
expect(provider).to receive(:capture).with(9855,'12345',anything).and_return(success_response)
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
end
|