spree_braintree_vzero 3.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.codeclimate.yml +15 -0
- data/.gitignore +19 -0
- data/.rspec +1 -0
- data/.travis.yml +63 -0
- data/Appraisals +45 -0
- data/CONTRIBUTING.md +28 -0
- data/Gemfile +14 -0
- data/LICENSE +26 -0
- data/README.md +83 -0
- data/Rakefile +21 -0
- data/app/assets/images/credit_cards/icons/jcb.png +0 -0
- data/app/assets/javascripts/spree/backend/payments.js +19 -0
- data/app/assets/javascripts/spree/backend/spree_braintree_vzero.js +81 -0
- data/app/assets/javascripts/spree/frontend/spree_braintree_vzero.js +68 -0
- data/app/assets/stylesheets/spree/backend/spree_braintree_vzero.css +5 -0
- data/app/controllers/spree/admin/payments_controller_decorator.rb +43 -0
- data/app/controllers/spree/api/v1/braintree_client_token_controller.rb +31 -0
- data/app/controllers/spree/checkout_controller_decorator.rb +38 -0
- data/app/controllers/spree/orders_controller_decorator.rb +62 -0
- data/app/controllers/spree/user_sessions_controller_decorator.rb +15 -0
- data/app/helpers/spree/admin/decorated_navigation_helper.rb +10 -0
- data/app/helpers/spree/admin/payment_methods_helper.rb +101 -0
- data/app/helpers/spree/braintree_helper.rb +27 -0
- data/app/models/braintree/successful_result_decorator.rb +21 -0
- data/app/models/spree/address_decorator.rb +18 -0
- data/app/models/spree/braintree_checkout.rb +105 -0
- data/app/models/spree/gateway/braintree_vzero_base.rb +168 -0
- data/app/models/spree/gateway/braintree_vzero_base/address.rb +33 -0
- data/app/models/spree/gateway/braintree_vzero_base/braintree_user.rb +25 -0
- data/app/models/spree/gateway/braintree_vzero_base/purchase_data.rb +48 -0
- data/app/models/spree/gateway/braintree_vzero_base/transaction.rb +39 -0
- data/app/models/spree/gateway/braintree_vzero_base/utils.rb +108 -0
- data/app/models/spree/gateway/braintree_vzero_drop_in_ui.rb +24 -0
- data/app/models/spree/gateway/braintree_vzero_hosted_fields.rb +28 -0
- data/app/models/spree/gateway/braintree_vzero_paypal_express.rb +36 -0
- data/app/models/spree/order_decorator.rb +153 -0
- data/app/models/spree/payment_decorator.rb +10 -0
- data/app/models/spree/payment_processing_decorator.rb +61 -0
- data/app/models/spree/preferences/preferable_decorator.rb +54 -0
- data/app/overrides/spree/admin/orders/customer_details/_form.rb +8 -0
- data/app/overrides/spree/admin/payment_methods/_form.rb +10 -0
- data/app/overrides/spree/admin/shared/_order_summary.rb +23 -0
- data/app/overrides/spree/admin/shared/_refunds.rb +13 -0
- data/app/overrides/spree/checkout/_new_user.rb +6 -0
- data/app/overrides/spree/checkout/_payment.rb +20 -0
- data/app/overrides/spree/checkout/registration.rb +6 -0
- data/app/overrides/spree/orders/edit.rb +6 -0
- data/app/overrides/spree/shared/_order_details.rb +13 -0
- data/app/overrides/spree/shared/_payment.rb +28 -0
- data/app/views/spree/admin/payment_methods/_braintree_vzero_form.html.erb +83 -0
- data/app/views/spree/admin/payments/source_forms/_braintree_vzero_dropin_ui.html.erb +1 -0
- data/app/views/spree/admin/payments/source_forms/_braintree_vzero_hosted_fields.html.erb +1 -0
- data/app/views/spree/admin/payments/source_forms/_braintree_vzero_paypal_express.html.erb +1 -0
- data/app/views/spree/admin/payments/source_forms/braintree_vzero/_payments.html.erb +87 -0
- data/app/views/spree/admin/payments/source_views/_braintree_vzero_dropin_ui.html.erb +1 -0
- data/app/views/spree/admin/payments/source_views/_braintree_vzero_hosted_fields.html.erb +1 -0
- data/app/views/spree/admin/payments/source_views/_braintree_vzero_paypal_express.html.erb +1 -0
- data/app/views/spree/admin/payments/source_views/braintree_vzero/_payment.html.erb +17 -0
- data/app/views/spree/braintree_vzero/_paypal_checkout.html.erb +87 -0
- data/app/views/spree/checkout/payment/_braintree_vzero_dropin_ui.html.erb +4 -0
- data/app/views/spree/checkout/payment/_braintree_vzero_hosted_fields.html.erb +4 -0
- data/app/views/spree/checkout/payment/_braintree_vzero_paypal_express.html.erb +4 -0
- data/app/views/spree/checkout/payment/braintree_vzero/_buttons.html.erb +11 -0
- data/app/views/spree/checkout/payment/braintree_vzero/_dropin_on_error_callback.js.erb +3 -0
- data/app/views/spree/checkout/payment/braintree_vzero/_dropin_on_ready_callback.js.erb +1 -0
- data/app/views/spree/checkout/payment/braintree_vzero/_hosted_fields_on_field_event_callback.js.erb +12 -0
- data/app/views/spree/checkout/payment/braintree_vzero/_hosted_fields_styles.js.erb +29 -0
- data/app/views/spree/checkout/payment/braintree_vzero/_payment.html.erb +84 -0
- data/app/views/spree/checkout/payment/braintree_vzero/_three_d_secure.html.erb +218 -0
- data/app/views/spree/shared/braintree_vzero/_dropin.js.erb +70 -0
- data/app/views/spree/shared/braintree_vzero/_hosted.js.erb +66 -0
- data/app/views/spree/shared/braintree_vzero/_paypal.js.erb +39 -0
- data/bin/rails +7 -0
- data/config/initializers/extend_spree_permitted_checkout_attributes.rb +5 -0
- data/config/initializers/prepend_helpers.rb +1 -0
- data/config/locales/en.yml +79 -0
- data/config/routes.rb +7 -0
- data/db/migrate/20150904143013_create_spree_braintree_checkouts.rb +9 -0
- data/db/migrate/20151002094655_add_braintree_id_to_spree_addresses.rb +5 -0
- data/db/migrate/20151018123907_add_braintree_token_and_nonce_to_spree_payments.rb +6 -0
- data/db/migrate/20151027135109_add_paypal_email_to_spree_braintree_checkout.rb +5 -0
- data/db/migrate/20151028095515_add_advanced_fraud_data_to_spree_braintree_checkout.rb +5 -0
- data/db/migrate/20151202095956_add_risk_id_and_risk_decision_to_spree_braintree_checkouts.rb +6 -0
- data/db/migrate/20151211100203_add_braintree_last_digits_and_braintree_card_type_to_spree_braintree_checkouts.rb +6 -0
- data/db/migrate/20160112153422_add_admin_payment_to_spree_braintree_checkout.rb +5 -0
- data/gemfiles/spree_3_5.gemfile +12 -0
- data/gemfiles/spree_3_5_spree_auth_devise.gemfile +13 -0
- data/gemfiles/spree_3_7.gemfile +12 -0
- data/gemfiles/spree_3_7_spree_auth_devise.gemfile +13 -0
- data/gemfiles/spree_4_0.gemfile +11 -0
- data/gemfiles/spree_4_0_spree_auth_devise.gemfile +12 -0
- data/gemfiles/spree_master.gemfile +11 -0
- data/gemfiles/spree_master_spree_auth_devise.gemfile +12 -0
- data/lib/generators/spree_braintree_vzero/install/install_generator.rb +34 -0
- data/lib/spree_braintree_vzero.rb +6 -0
- data/lib/spree_braintree_vzero/engine.rb +28 -0
- data/lib/spree_braintree_vzero/factories.rb +10 -0
- data/lib/spree_braintree_vzero/railtie.rb +8 -0
- data/lib/spree_braintree_vzero/version.rb +17 -0
- data/lib/tasks/spree_braintree_vzero.rake +6 -0
- data/spec/controllers/spree/api/v1/braintree_client_token_controller_spec.rb +49 -0
- data/spec/controllers/spree/checkout_controller_spec.rb +85 -0
- data/spec/controllers/spree/orders_controller_spec.rb +97 -0
- data/spec/factories/braintree_checkout_factory.rb +7 -0
- data/spec/factories/braintree_gateway_factory.rb +35 -0
- data/spec/factories/payment_factory_decorator.rb +28 -0
- data/spec/features/spree/admin/log_entries_spec.rb +63 -0
- data/spec/models/gateway/braintree_vzero_base/address_spec.rb +28 -0
- data/spec/models/gateway/braintree_vzero_base/purchase_data_spec.rb +57 -0
- data/spec/models/gateway/braintree_vzero_base_spec.rb +346 -0
- data/spec/models/gateway/braintree_vzero_dropin_ui_spec.rb +35 -0
- data/spec/models/gateway/braintree_vzero_hosted_fields_spec.rb +35 -0
- data/spec/models/spree/order_spec.rb +186 -0
- data/spec/spec_helper.rb +100 -0
- data/spec/support/vcr.rb +10 -0
- data/spec/vcr/Log_entries/with_a_failed_log_entry/shows_a_failed_attempt.yml +91 -0
- data/spec/vcr/Log_entries/with_a_successful_log_entry/shows_a_successful_attempt.yml +113 -0
- data/spec/vcr/Spree_Api_V1_BraintreeClientTokenController/POST_create/guest_checkout/returns_proper_json_data_when_gateway_not_specified.yml +90 -0
- data/spec/vcr/Spree_Api_V1_BraintreeClientTokenController/POST_create/guest_checkout/returns_proper_json_data_when_gateway_specified.yml +90 -0
- data/spec/vcr/Spree_Api_V1_BraintreeClientTokenController/POST_create/user_checkout/returns_proper_json_data_when_gateway_not_specified.yml +191 -0
- data/spec/vcr/Spree_Api_V1_BraintreeClientTokenController/POST_create/user_checkout/returns_proper_json_data_when_gateway_specified.yml +191 -0
- data/spec/vcr/Spree_CheckoutController/_update/braintree_payment/advanced_fraud_data_in_source_should_be_updated.yml +71 -0
- data/spec/vcr/Spree_CheckoutController/_update/braintree_payment/when_token_credit_card_data_in_source_should_be_updated_from_Braintree_Vault.yml +139 -0
- data/spec/vcr/Spree_CheckoutController/_update/braintree_paypal_express_payment/amount_in_payment_should_be_updated.yml +280 -0
- data/spec/vcr/Spree_Gateway_BraintreeVzeroBase/valid_credentials/_capture/captures_authorized_amount/updates_Payment_state.yml +206 -0
- data/spec/vcr/Spree_Gateway_BraintreeVzeroBase/valid_credentials/_credit/with_refundable_state/should_be_a_success.yml +211 -0
- data/spec/vcr/Spree_Gateway_BraintreeVzeroBase/valid_credentials/_credit/with_unrefundable_state/should_not_be_a_success.yml +177 -0
- data/spec/vcr/Spree_Gateway_BraintreeVzeroBase/valid_credentials/_purchase/data_from_admin_panel/should_include_only_essential_data.yml +78 -0
- data/spec/vcr/Spree_Gateway_BraintreeVzeroBase/valid_credentials/_purchase/does_not_store_Transaction_in_Vault_by_default.yml +111 -0
- data/spec/vcr/Spree_Gateway_BraintreeVzeroBase/valid_credentials/_purchase/returns_false_with_invalid_nonce.yml +88 -0
- data/spec/vcr/Spree_Gateway_BraintreeVzeroBase/valid_credentials/_purchase/returns_false_with_invalid_token.yml +88 -0
- data/spec/vcr/Spree_Gateway_BraintreeVzeroBase/valid_credentials/_purchase/returns_success_with_valid_token.yml +113 -0
- data/spec/vcr/Spree_Gateway_BraintreeVzeroBase/valid_credentials/_purchase/returns_suceess_with_valid_nonce.yml +111 -0
- data/spec/vcr/Spree_Gateway_BraintreeVzeroBase/valid_credentials/_purchase/using_Vault/saves_Braintree_Address_id_to_Spree_Address_when_address_is_being_saved.yml +130 -0
- data/spec/vcr/Spree_Gateway_BraintreeVzeroBase/valid_credentials/_purchase/using_Vault/saves_unique_Braintree_Addresses_ids.yml +143 -0
- data/spec/vcr/Spree_Gateway_BraintreeVzeroBase/valid_credentials/_purchase/using_Vault/sends_empty_address_id_when_address_is_already_in_vault.yml +553 -0
- data/spec/vcr/Spree_Gateway_BraintreeVzeroBase/valid_credentials/_purchase/using_Vault/stores_Transaction.yml +181 -0
- data/spec/vcr/Spree_Gateway_BraintreeVzeroBase/valid_credentials/_purchase/with_3DSecure_option_turned_on/performs_3DSecure_check.yml +112 -0
- data/spec/vcr/Spree_Gateway_BraintreeVzeroBase/valid_credentials/_purchase/with_3DSecure_option_turned_on/returns_error.yml +112 -0
- data/spec/vcr/Spree_Gateway_BraintreeVzeroBase/valid_credentials/_purchase/with_advanced_fraud_tool_enabled/returns_fraud_data.yml +111 -0
- data/spec/vcr/Spree_Gateway_BraintreeVzeroBase/valid_credentials/_purchase/with_advanced_fraud_tool_enabled/returns_success.yml +111 -0
- data/spec/vcr/Spree_Gateway_BraintreeVzeroBase/valid_credentials/_settle/settles_authorized_amount/does_not_update_Order_payment_state.yml +204 -0
- data/spec/vcr/Spree_Gateway_BraintreeVzeroBase/valid_credentials/_settle/settles_authorized_amount/prepares_Checkout_for_status_updating.yml +204 -0
- data/spec/vcr/Spree_Gateway_BraintreeVzeroBase/valid_credentials/_settle/settles_authorized_amount/submits_Transaction_for_settlement.yml +377 -0
- data/spec/vcr/Spree_Gateway_BraintreeVzeroBase/valid_credentials/_settle/settles_authorized_amount/updates_Payment_state.yml +203 -0
- data/spec/vcr/Spree_Gateway_BraintreeVzeroBase/valid_credentials/_update_states/does_not_update_completed_Checkout_on_subsequent_runs.yml +202 -0
- data/spec/vcr/Spree_Gateway_BraintreeVzeroBase/valid_credentials/_update_states/updates_Order_payment_state_when_Checkout_is_updated.yml +202 -0
- data/spec/vcr/Spree_Gateway_BraintreeVzeroBase/valid_credentials/_update_states/updates_Payment_state_when_Checkout_is_updated.yml +202 -0
- data/spec/vcr/Spree_Gateway_BraintreeVzeroBase/valid_credentials/_update_states/updates_payment_State.yml +202 -0
- data/spec/vcr/Spree_Gateway_BraintreeVzeroBase/valid_credentials/_void/with_unvoidable_state/should_not_change_payment_source_state.yml +178 -0
- data/spec/vcr/Spree_Gateway_BraintreeVzeroBase/valid_credentials/_void/with_voidable_state/should_change_payment_source_state_to_voided.yml +199 -0
- data/spec/vcr/Spree_Gateway_BraintreeVzeroBase/valid_credentials/generates_token_for_User_registered_in_Braintree.yml +356 -0
- data/spec/vcr/Spree_Gateway_BraintreeVzeroBase/valid_credentials/generates_token_for_new_User.yml +189 -0
- data/spec/vcr/Spree_Gateway_BraintreeVzeroBase/valid_credentials/generates_token_without_User.yml +89 -0
- data/spec/vcr/Spree_Gateway_BraintreeVzeroBase/with_invalid_credentials/raises_Braintree_error.yml +62 -0
- data/spec/vcr/Spree_Gateway_BraintreeVzeroBase_Address/_create/creates_Braintree_Address.yml +84 -0
- data/spec/vcr/Spree_Gateway_BraintreeVzeroBase_Address/_create/deletes_Braintree_Address.yml +141 -0
- data/spec/vcr/Spree_Gateway_BraintreeVzeroBase_Address/_create/finds_Braintree_Address.yml +148 -0
- data/spec/vcr/Spree_Gateway_BraintreeVzeroBase_Address/_create/updates_Braintree_Address.yml +154 -0
- data/spec/vcr/Spree_Order/complete_with_braintree_vzero_standard_payment/with_auto_capture/should_complete_payment.yml +116 -0
- data/spec/vcr/Spree_Order/complete_with_braintree_vzero_standard_payment/with_auto_capture/should_update_payment_s_response_code.yml +111 -0
- data/spec/vcr/Spree_Order/complete_with_braintree_vzero_standard_payment/with_auto_capture/should_update_payment_s_source_state_and_transaction_id.yml +111 -0
- data/spec/vcr/Spree_Order/complete_with_braintree_vzero_standard_payment/without_auto_capture/should_pend_payment.yml +111 -0
- data/spec/vcr/Spree_Order/complete_with_braintree_vzero_standard_payment/without_auto_capture/should_update_payment_s_response_code.yml +111 -0
- data/spec/vcr/Spree_Order/complete_with_braintree_vzero_standard_payment/without_auto_capture/should_update_payment_s_source_state_and_transaction_id.yml +110 -0
- data/spree_braintree_vzero.gemspec +52 -0
- data/vendor/assets/javascripts/maskedinput/jquery.maskedinput.min.js +7 -0
- metadata +643 -0
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::Gateway::BraintreeVzeroDropInUi, :vcr do
|
4
|
+
subject { create(:vzero_dropin_ui_gateway) }
|
5
|
+
|
6
|
+
describe 'after_save' do
|
7
|
+
let(:hosted_fields_gateway) { create(:vzero_hosted_fields_gateway) }
|
8
|
+
|
9
|
+
it 'activation should disable Hosted Fields Gateways' do
|
10
|
+
subject.update_column(:active, false)
|
11
|
+
expect(hosted_fields_gateway.active?).to be true
|
12
|
+
subject.update(active: true)
|
13
|
+
expect(hosted_fields_gateway.reload.active?).to be false
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'deactivation should not disable Hosted Fields Gateways' do
|
17
|
+
subject
|
18
|
+
expect(hosted_fields_gateway.active?).to be true
|
19
|
+
subject.update(active: false)
|
20
|
+
expect(hosted_fields_gateway.reload.active?).to be true
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'creation of activated should disable Hosted Fields Gateways' do
|
24
|
+
expect(hosted_fields_gateway.active?).to be true
|
25
|
+
subject
|
26
|
+
expect(hosted_fields_gateway.reload.active?).to be false
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'creation of deactivated should not disable Hosted Fields Gateways' do
|
30
|
+
expect(hosted_fields_gateway.active?).to be true
|
31
|
+
create(:vzero_dropin_ui_gateway, active: false)
|
32
|
+
expect(hosted_fields_gateway.reload.active?).to be true
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::Gateway::BraintreeVzeroHostedFields, :vcr do
|
4
|
+
subject { create(:vzero_hosted_fields_gateway) }
|
5
|
+
|
6
|
+
describe 'after_save' do
|
7
|
+
let(:dropin_ui_gateway) { create(:vzero_dropin_ui_gateway) }
|
8
|
+
|
9
|
+
it 'activation should disable DropIn UI Gateways' do
|
10
|
+
subject.update_column(:active, false)
|
11
|
+
expect(dropin_ui_gateway.active?).to be true
|
12
|
+
subject.update(active: true)
|
13
|
+
expect(dropin_ui_gateway.reload.active?).to be false
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'deactivation should not disable DropIn UI Gateways' do
|
17
|
+
subject
|
18
|
+
expect(dropin_ui_gateway.active?).to be true
|
19
|
+
subject.update(active: false)
|
20
|
+
expect(dropin_ui_gateway.reload.active?).to be true
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'creation of activated should disable DropIn UI Gateways' do
|
24
|
+
expect(dropin_ui_gateway.active?).to be true
|
25
|
+
subject
|
26
|
+
expect(dropin_ui_gateway.reload.active?).to be false
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'creation of deactivated should not disable DropIn UI Gateways' do
|
30
|
+
expect(dropin_ui_gateway.active?).to be true
|
31
|
+
create(:vzero_dropin_ui_gateway, active: false)
|
32
|
+
expect(dropin_ui_gateway.reload.active?).to be true
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,186 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::Order, :vcr do
|
4
|
+
let(:gateway) { create(:vzero_gateway, auto_capture: true) }
|
5
|
+
let(:payment) { create(:braintree_vzero_payment, payment_method: gateway) }
|
6
|
+
let(:payment_source) { payment.payment_source }
|
7
|
+
let(:order) { OrderWalkthrough.up_to(:payment) }
|
8
|
+
let(:add_payment_to_order!) { order.payments << payment }
|
9
|
+
|
10
|
+
describe 'complete with braintree vzero standard payment' do
|
11
|
+
let!(:complete_order!) do
|
12
|
+
add_payment_to_order!
|
13
|
+
2.times { order.next! }
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'with auto_capture' do
|
17
|
+
it 'should complete payment' do
|
18
|
+
expect(payment.reload.state).to eq 'completed'
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should update payment's response_code" do
|
22
|
+
expect(payment.reload.response_code).not_to be_blank
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should update payment's source state and transaction_id" do
|
26
|
+
expect(payment.reload.source.state).to eq 'submitted_for_settlement'
|
27
|
+
expect(payment.reload.source.transaction_id).not_to be_blank
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'without auto_capture' do
|
32
|
+
let(:gateway) { create(:vzero_gateway, auto_capture: false) }
|
33
|
+
|
34
|
+
it 'should pend payment' do
|
35
|
+
expect(payment.reload.state).to eq 'pending'
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should update payment's response_code" do
|
39
|
+
expect(payment.reload.response_code).not_to be_blank
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should update payment's source state and transaction_id" do
|
43
|
+
expect(payment.reload.source.state).to eq 'authorized'
|
44
|
+
expect(payment.reload.source.transaction_id).not_to be_blank
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe 'checkout steps' do
|
50
|
+
it 'should not include confirmation step by default' do
|
51
|
+
expect(order.checkout_steps).not_to include 'confirm'
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should include payment step by default' do
|
55
|
+
expect(order.checkout_steps).to include 'payment'
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'with braintree dropin payment' do
|
59
|
+
before { add_payment_to_order! }
|
60
|
+
|
61
|
+
it 'should include confirmation step' do
|
62
|
+
order.update(state: 'payment')
|
63
|
+
expect(order.confirmation_required?).to be true
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should include payment step' do
|
67
|
+
expect(order.checkout_steps).to include 'payment'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'with braintree paypal express payment' do
|
72
|
+
let(:order) { OrderWalkthrough.up_to(:delivery) }
|
73
|
+
let(:gateway) { create(:vzero_paypal_gateway, auto_capture: true) }
|
74
|
+
before { add_payment_to_order! }
|
75
|
+
|
76
|
+
it 'should not include confirmation step when payed by paypal express from cart' do
|
77
|
+
order.update(state: 'delivery')
|
78
|
+
expect(order.confirmation_required?).to be false
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'should include confirmation step when payed by paypal express from payment step' do
|
82
|
+
order.update(state: 'payment')
|
83
|
+
expect(order.confirmation_required?).to be true
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'should not include payment step' do
|
87
|
+
expect(order.checkout_steps).not_to include 'payment'
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe 'addresses managment' do
|
93
|
+
let(:country) { create(:country, name: 'Poland', iso: 'PL') }
|
94
|
+
let(:state) { create(:state, name: 'Mazowieckie', abbr: 'MZ', country: country) }
|
95
|
+
|
96
|
+
context 'paypal addresses' do
|
97
|
+
let(:type) { 'ship_address' }
|
98
|
+
let(:attr) { address_hash.except(:full_name, :country, :state).keys.map(&:to_s) }
|
99
|
+
let(:address_hash) do
|
100
|
+
{
|
101
|
+
zipcode: '02-796',
|
102
|
+
city: 'Warsaw',
|
103
|
+
address1: 'gder 1/7',
|
104
|
+
address2: '13b',
|
105
|
+
phone: '408-391-8922',
|
106
|
+
full_name: 'Test ree ree Acd',
|
107
|
+
country: 'PL',
|
108
|
+
state: 'MZ'
|
109
|
+
}.with_indifferent_access
|
110
|
+
end
|
111
|
+
|
112
|
+
let(:prepare_data) do
|
113
|
+
order
|
114
|
+
state
|
115
|
+
end
|
116
|
+
|
117
|
+
let(:save_paypal_address!) do
|
118
|
+
prepare_data
|
119
|
+
expect(order.ship_address.attributes.slice(*attr)).not_to match address_hash.slice(*attr)
|
120
|
+
order.save_paypal_address(type, address_hash.dup)
|
121
|
+
end
|
122
|
+
|
123
|
+
shared_examples 'comparable' do
|
124
|
+
it 'should save basic address data without changes' do
|
125
|
+
expect(order.reload.ship_address.attributes.slice(*attr)).to match address_hash.slice(*attr)
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'should find and set proper country' do
|
129
|
+
expect(order.reload.ship_address.country.iso).to eq address_hash[:country]
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'should split name in proper way' do
|
133
|
+
name_array = address_hash[:full_name].split(' ')
|
134
|
+
last = name_array.slice!(-1)
|
135
|
+
first = name_array.join(' ')
|
136
|
+
expect(order.reload.ship_address.firstname).to eq first
|
137
|
+
expect(order.reload.ship_address.lastname).to eq last
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
context 'with state as abbreviation' do
|
142
|
+
before do
|
143
|
+
save_paypal_address!
|
144
|
+
end
|
145
|
+
|
146
|
+
include_examples 'comparable'
|
147
|
+
|
148
|
+
it 'should find and set proper state' do
|
149
|
+
expect(order.reload.ship_address.state.abbr).to eq address_hash[:state]
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context 'with state as name' do
|
154
|
+
before do
|
155
|
+
address_hash[:state] = 'MAZOWIECKIE'
|
156
|
+
save_paypal_address!
|
157
|
+
end
|
158
|
+
|
159
|
+
include_examples 'comparable'
|
160
|
+
|
161
|
+
it 'should find and set proper state' do
|
162
|
+
expect(order.reload.ship_address.state.name).to eq address_hash[:state].capitalize
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'should not include fields with text "undefined"' do
|
167
|
+
address_hash[:address2] = 'undefined'
|
168
|
+
save_paypal_address!
|
169
|
+
expect(order.reload.ship_address.address2).to eq nil
|
170
|
+
end
|
171
|
+
|
172
|
+
context 'billing address from shipping_address' do
|
173
|
+
it 'should be set when empty' do
|
174
|
+
order.update_column(:bill_address_id, nil)
|
175
|
+
order.set_billing_address
|
176
|
+
expect(order.reload.bill_address.attributes.slice(*attr)).to match order.ship_address.attributes.slice(*attr)
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'should not be set when exists' do
|
180
|
+
order.set_billing_address
|
181
|
+
expect(order.reload.bill_address.attributes.slice(*attr)).not_to match address_hash.slice(*attr)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# Run Coverage report
|
2
|
+
require 'simplecov'
|
3
|
+
SimpleCov.start do
|
4
|
+
add_filter 'spec/dummy'
|
5
|
+
add_group 'Controllers', 'app/controllers'
|
6
|
+
add_group 'Helpers', 'app/helpers'
|
7
|
+
add_group 'Mailers', 'app/mailers'
|
8
|
+
add_group 'Models', 'app/models'
|
9
|
+
add_group 'Views', 'app/views'
|
10
|
+
add_group 'Libraries', 'lib'
|
11
|
+
end
|
12
|
+
|
13
|
+
# CodeClimate coverage
|
14
|
+
require "simplecov"
|
15
|
+
SimpleCov.start
|
16
|
+
|
17
|
+
# Configure Rails Environment
|
18
|
+
ENV['RAILS_ENV'] = 'test'
|
19
|
+
|
20
|
+
require File.expand_path('../dummy/config/environment.rb', __FILE__)
|
21
|
+
|
22
|
+
require 'rspec/rails'
|
23
|
+
require 'database_cleaner'
|
24
|
+
require 'ffaker'
|
25
|
+
|
26
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
27
|
+
# in spec/support/ and its subdirectories.
|
28
|
+
Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
|
29
|
+
|
30
|
+
# Requires factories and other useful helpers defined in spree_core.
|
31
|
+
require 'spree/testing_support/authorization_helpers'
|
32
|
+
require 'spree/testing_support/capybara_ext'
|
33
|
+
require 'spree/testing_support/controller_requests'
|
34
|
+
require 'spree/testing_support/factories'
|
35
|
+
require 'spree/testing_support/url_helpers'
|
36
|
+
require 'spree/testing_support/order_walkthrough'
|
37
|
+
|
38
|
+
# Requires factories defined in lib/spree_braintree_vzero/factories.rb
|
39
|
+
require 'spree_braintree_vzero/factories'
|
40
|
+
|
41
|
+
require 'pry'
|
42
|
+
|
43
|
+
RSpec.configure do |config|
|
44
|
+
config.include FactoryBot::Syntax::Methods
|
45
|
+
|
46
|
+
# Infer an example group's spec type from the file location.
|
47
|
+
config.infer_spec_type_from_file_location!
|
48
|
+
|
49
|
+
# == URL Helpers
|
50
|
+
#
|
51
|
+
# Allows access to Spree's routes in specs:
|
52
|
+
#
|
53
|
+
# visit spree.admin_path
|
54
|
+
# current_path.should eql(spree.products_path)
|
55
|
+
config.include Spree::TestingSupport::UrlHelpers
|
56
|
+
|
57
|
+
# == Requests support
|
58
|
+
#
|
59
|
+
# Adds convenient methods to request Spree's controllers
|
60
|
+
# spree_get :index
|
61
|
+
config.include Spree::TestingSupport::ControllerRequests, type: :controller
|
62
|
+
|
63
|
+
# == Mock Framework
|
64
|
+
#
|
65
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
66
|
+
#
|
67
|
+
# config.mock_with :mocha
|
68
|
+
# config.mock_with :flexmock
|
69
|
+
# config.mock_with :rr
|
70
|
+
config.mock_with :rspec
|
71
|
+
config.color = true
|
72
|
+
|
73
|
+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
74
|
+
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
75
|
+
|
76
|
+
# Capybara javascript drivers require transactional fixtures set to false, and we use DatabaseCleaner
|
77
|
+
# to cleanup after each test instead. Without transactional fixtures set to false the records created
|
78
|
+
# to setup a test will be unavailable to the browser, which runs under a separate server instance.
|
79
|
+
config.use_transactional_fixtures = false
|
80
|
+
|
81
|
+
# Ensure Suite is set to use transactions for speed.
|
82
|
+
config.before :suite do
|
83
|
+
DatabaseCleaner.strategy = :transaction
|
84
|
+
DatabaseCleaner.clean_with :truncation
|
85
|
+
end
|
86
|
+
|
87
|
+
# Before each spec check if it is a Javascript test and switch between using database transactions or not where necessary.
|
88
|
+
config.before :each do
|
89
|
+
DatabaseCleaner.strategy = RSpec.current_example.metadata[:js] ? :truncation : :transaction
|
90
|
+
DatabaseCleaner.start
|
91
|
+
end
|
92
|
+
|
93
|
+
# After each spec clean the database.
|
94
|
+
config.after :each do
|
95
|
+
DatabaseCleaner.clean
|
96
|
+
end
|
97
|
+
|
98
|
+
config.fail_fast = ENV['FAIL_FAST'] || false
|
99
|
+
config.order = 'random'
|
100
|
+
end
|
data/spec/support/vcr.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'vcr'
|
2
|
+
|
3
|
+
VCR.configure do |config|
|
4
|
+
config.cassette_library_dir = 'spec/vcr'
|
5
|
+
config.hook_into :webmock
|
6
|
+
config.ignore_localhost = true
|
7
|
+
config.configure_rspec_metadata!
|
8
|
+
config.default_cassette_options = { match_requests_on: [:method, :host], record: :new_episodes }
|
9
|
+
config.ignore_hosts 'codeclimate.com'
|
10
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://5ffsvj9qxt38xptf:50ea069d312d35fbf779a66b6c86b897@api.sandbox.braintreegateway.com/merchants/zt9ssvxzppgzdjmn/transactions
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: |
|
9
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
10
|
+
<transaction>
|
11
|
+
<channel>SpreeCommerceInc_Cart_Braintree</channel>
|
12
|
+
<customer>
|
13
|
+
</customer>
|
14
|
+
<payment-method-nonce>fake-invalid-nonce</payment-method-nonce>
|
15
|
+
<amount>29.99</amount>
|
16
|
+
<order-id>R774803962</order-id>
|
17
|
+
<descriptor>
|
18
|
+
<name></name>
|
19
|
+
</descriptor>
|
20
|
+
<options>
|
21
|
+
<submit-for-settlement type="boolean">false</submit-for-settlement>
|
22
|
+
<add-billing-address-to-payment-method type="boolean">false</add-billing-address-to-payment-method>
|
23
|
+
<three-d-secure>
|
24
|
+
<required nil="true"/>
|
25
|
+
</three-d-secure>
|
26
|
+
<store-in-vault type="boolean">false</store-in-vault>
|
27
|
+
</options>
|
28
|
+
<type>sale</type>
|
29
|
+
</transaction>
|
30
|
+
headers:
|
31
|
+
Accept-Encoding:
|
32
|
+
- gzip
|
33
|
+
Accept:
|
34
|
+
- application/xml
|
35
|
+
User-Agent:
|
36
|
+
- Braintree Ruby Gem 2.73.0
|
37
|
+
X-Apiversion:
|
38
|
+
- '4'
|
39
|
+
Content-Type:
|
40
|
+
- application/xml
|
41
|
+
response:
|
42
|
+
status:
|
43
|
+
code: 422
|
44
|
+
message: Unprocessable Entity
|
45
|
+
headers:
|
46
|
+
Date:
|
47
|
+
- Sun, 09 Apr 2017 10:52:22 GMT
|
48
|
+
Content-Type:
|
49
|
+
- application/xml; charset=utf-8
|
50
|
+
Transfer-Encoding:
|
51
|
+
- chunked
|
52
|
+
X-Frame-Options:
|
53
|
+
- SAMEORIGIN
|
54
|
+
- SAMEORIGIN
|
55
|
+
X-Xss-Protection:
|
56
|
+
- 1; mode=block
|
57
|
+
X-Content-Type-Options:
|
58
|
+
- nosniff
|
59
|
+
X-Authentication:
|
60
|
+
- basic_auth
|
61
|
+
X-User:
|
62
|
+
- vzw4dwqpkk82wnfg
|
63
|
+
Vary:
|
64
|
+
- Accept-Encoding
|
65
|
+
Content-Encoding:
|
66
|
+
- gzip
|
67
|
+
Cache-Control:
|
68
|
+
- no-cache
|
69
|
+
X-Request-Id:
|
70
|
+
- 680372b6-1653-4628-ba65-446bbcb07235
|
71
|
+
X-Runtime:
|
72
|
+
- '0.157729'
|
73
|
+
Strict-Transport-Security:
|
74
|
+
- max-age=31536000; includeSubDomains
|
75
|
+
body:
|
76
|
+
encoding: ASCII-8BIT
|
77
|
+
string: !binary |-
|
78
|
+
H4sIAGYS6lgAA6RUTW/bMAy991cYvituu/XDgKICLTBg1209B4zNNkIlSqPk
|
79
|
+
rPn3kx1/xK07DOhN5CMpvkdK8u7VmmyPHLSjdX6xOs8zpMrVmp7X+eOvb+I2
|
80
|
+
v1NnErwWyOxYMAbvKKA6yzLZuUJ7HI0sHjyuc2CGQ170UGSgAFVMlxw9y+ED
|
81
|
+
NqCTnTypKVTlxdX1lSy68ykIMbLeNhH7euFgt87kysPBIsWNxbhz9YYcVSiL
|
82
|
+
MXpWw2II8IzqkV7I/aHMcYavXjPW2VKZlSyGjKntYtZ3bw4CFW9kOIWlBwYb
|
83
|
+
/qFXtQMiNOqnZ8QHZy1yhd+p2jwAx809g6aYkCROHzgmNiG6FJ2RNus8coPD
|
84
|
+
XLprO2biyEx0zNQTvKDQtAeje5csFgOHKmBdQ1FdlquyTPIerQF0XCMLXasf
|
85
|
+
Nzdfb8+/lNeXshidQ1SNoWLt4+nUJYHFxbaL9+HS+VavcJIemq3VUTyltQ0Y
|
86
|
+
o8GWQWJnQiK0DE7JUNdiq41JL0Gkc9r7IKITcx2GYv8XPBWPuzQqUaebq4bn
|
87
|
+
a8j4u+mWboF3t0QfpMo0ZW7HJvbQmInm3DsK+EYt2b4bFcCklO740cpOe/qZ
|
88
|
+
B5MUW/hR/gIAAP//AwBjnbFpjgQAAA==
|
89
|
+
http_version:
|
90
|
+
recorded_at: Sun, 09 Apr 2017 10:52:22 GMT
|
91
|
+
recorded_with: VCR 3.0.3
|