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
data/config/routes.rb
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
class AddBraintreeLastDigitsAndBraintreeCardTypeToSpreeBraintreeCheckouts < SpreeExtension::Migration[4.2]
|
2
|
+
def change
|
3
|
+
add_column :spree_braintree_checkouts, :braintree_last_digits, :string, limit: 4
|
4
|
+
add_column :spree_braintree_checkouts, :braintree_card_type, :string
|
5
|
+
end
|
6
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "spree", "~> 3.5.0"
|
6
|
+
gem "pg"
|
7
|
+
gem "mysql2"
|
8
|
+
gem "webmock", ">= 2.3.1"
|
9
|
+
gem "rails-controller-testing"
|
10
|
+
gem "spree_auth_devise", "~> 3.3.0"
|
11
|
+
gem 'sprockets', '~> 3.7'
|
12
|
+
|
13
|
+
gemspec path: "../"
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem 'sassc-rails'
|
6
|
+
gem "spree", "~> 3.7.1"
|
7
|
+
gem "pg"
|
8
|
+
gem "mysql2"
|
9
|
+
gem "webmock", ">= 2.3.1"
|
10
|
+
gem "rails-controller-testing"
|
11
|
+
gem "spree_auth_devise", "~> 3.5.2"
|
12
|
+
|
13
|
+
gemspec path: "../"
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "spree", github: "spree/spree", branch: "master"
|
6
|
+
gem "pg"
|
7
|
+
gem "mysql2"
|
8
|
+
gem "webmock", ">= 2.3.1"
|
9
|
+
gem "rails-controller-testing"
|
10
|
+
gem "spree_auth_devise", github: "spree/spree_auth_devise", branch: "master"
|
11
|
+
|
12
|
+
gemspec path: "../"
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module SpreeBraintreeVzero
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
class_option :auto_run_migrations, type: :boolean, default: false
|
5
|
+
|
6
|
+
def add_javascripts
|
7
|
+
append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/spree_braintree_vzero\n"
|
8
|
+
append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/spree_braintree_vzero\n"
|
9
|
+
end
|
10
|
+
|
11
|
+
def add_schedule
|
12
|
+
create_file 'config/schedule.rb' unless File.exist?('config/schedule.rb')
|
13
|
+
append_file 'config/schedule.rb' do
|
14
|
+
"\nevery '0 4,10,16,22 * * * *' do
|
15
|
+
rake 'spree_braintree_vzero:update_states'
|
16
|
+
end"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def add_migrations
|
21
|
+
run 'bundle exec rake railties:install:migrations FROM=spree_braintree_vzero'
|
22
|
+
end
|
23
|
+
|
24
|
+
def run_migrations
|
25
|
+
run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]'))
|
26
|
+
if run_migrations
|
27
|
+
run 'bundle exec rake db:migrate'
|
28
|
+
else
|
29
|
+
puts 'Skipping rake db:migrate, don\'t forget to run it!'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module SpreeBraintreeVzero
|
2
|
+
class Engine < Rails::Engine
|
3
|
+
require 'spree/core'
|
4
|
+
isolate_namespace Spree
|
5
|
+
engine_name 'spree_braintree_vzero'
|
6
|
+
|
7
|
+
# use rspec for tests
|
8
|
+
config.generators do |g|
|
9
|
+
g.test_framework :rspec
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.activate
|
13
|
+
Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
|
14
|
+
Rails.configuration.cache_classes ? require(c) : load(c)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
config.to_prepare &method(:activate).to_proc
|
19
|
+
|
20
|
+
initializer 'spree.braintree_vzero.payment_methods', after: 'spree.register.payment_methods' do |app|
|
21
|
+
app.config.spree.payment_methods += [
|
22
|
+
Spree::Gateway::BraintreeVzeroDropInUi,
|
23
|
+
Spree::Gateway::BraintreeVzeroPaypalExpress,
|
24
|
+
Spree::Gateway::BraintreeVzeroHostedFields
|
25
|
+
]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
FactoryBot.define do
|
2
|
+
# Define your Spree extensions Factories within this file to enable applications, and other extensions to use and override them.
|
3
|
+
#
|
4
|
+
# Example adding this to your spec_helper will load these Factories for use:
|
5
|
+
# require 'spree_braintree_vzero/factories'
|
6
|
+
|
7
|
+
Dir[Dir.pwd + '/spec/factories/**/*'].each do |factory|
|
8
|
+
require File.expand_path(factory)
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module SpreeBraintreeVzero
|
2
|
+
module_function
|
3
|
+
|
4
|
+
# Returns the version of the currently loaded SpreeBraintreeVzero as a
|
5
|
+
# <tt>Gem::Version</tt>.
|
6
|
+
def version
|
7
|
+
Gem::Version.new VERSION::STRING
|
8
|
+
end
|
9
|
+
|
10
|
+
module VERSION
|
11
|
+
MAJOR = 3
|
12
|
+
MINOR = 5
|
13
|
+
TINY = 1
|
14
|
+
|
15
|
+
STRING = [MAJOR, MINOR, TINY].compact.join('.')
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::Api::V1::BraintreeClientTokenController, :vcr, type: :controller do
|
4
|
+
let!(:gateway) { create(:vzero_gateway, auto_capture: true) }
|
5
|
+
let(:order) { create(:order) }
|
6
|
+
|
7
|
+
describe 'POST #create' do
|
8
|
+
context 'guest checkout' do
|
9
|
+
it 'returns proper json data when gateway not specified' do
|
10
|
+
post :create, params: { order_number: order.number }
|
11
|
+
expect(response).to have_http_status 200
|
12
|
+
expect(json_response['client_token']).not_to be nil
|
13
|
+
expect(json_response['payment_method_id']).not_to be nil
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'returns proper json data when gateway specified' do
|
17
|
+
post :create, params: { payment_method_id: gateway.id, order_number: order.number }
|
18
|
+
expect(response).to have_http_status 200
|
19
|
+
expect(json_response['client_token']).not_to be nil
|
20
|
+
expect(json_response['payment_method_id']).to eq gateway.id
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'user checkout' do
|
25
|
+
let!(:user) { create(:user) }
|
26
|
+
before { user.generate_spree_api_key! }
|
27
|
+
|
28
|
+
it 'returns proper json data when gateway not specified' do
|
29
|
+
post :create, params: { order_number: order.number, token: user.spree_api_key }
|
30
|
+
expect(response).to have_http_status 200
|
31
|
+
expect(json_response['client_token']).not_to be nil
|
32
|
+
expect(json_response['payment_method_id']).not_to be nil
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'returns proper json data when gateway specified' do
|
36
|
+
post :create, params: { payment_method_id: gateway.id, token: user.spree_api_key, order_number: order.number }
|
37
|
+
expect(response).to have_http_status 200
|
38
|
+
expect(json_response['client_token']).not_to be nil
|
39
|
+
expect(json_response['payment_method_id']).to eq gateway.id
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def json_response
|
47
|
+
JSON.parse(response.body)
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::CheckoutController, :vcr, type: :controller do
|
4
|
+
let(:user) { create(:user) }
|
5
|
+
let(:order) { OrderWalkthrough.up_to(:payment) }
|
6
|
+
|
7
|
+
before do
|
8
|
+
allow(controller).to receive_messages try_spree_current_user: user
|
9
|
+
allow(controller).to receive_messages spree_current_user: user
|
10
|
+
allow(controller).to receive_messages current_order: order
|
11
|
+
end
|
12
|
+
|
13
|
+
context '#update' do
|
14
|
+
context 'braintree payment' do
|
15
|
+
let(:braintree_payment_method) { create(:vzero_gateway) }
|
16
|
+
let(:params) do
|
17
|
+
{
|
18
|
+
order: {
|
19
|
+
payments_attributes: [{
|
20
|
+
'payment_method_id' => braintree_payment_method.id,
|
21
|
+
'braintree_token' => 'k5jkr6',
|
22
|
+
'braintree_nonce' => '4cdec532-b616-41cc-babf-c1d5cfbbe6c2',
|
23
|
+
'amount' => 23
|
24
|
+
}],
|
25
|
+
coupon_code: ''
|
26
|
+
},
|
27
|
+
device_data: '{\"device_session_id\":\"ce3a962b468a0c912b6cf53f72f154e3\",\"fraud_merchant_id\":\"600000\",\"correlation_id\":\"d61971aadd35b3da938a99902a299be6\"}',
|
28
|
+
state: 'payment'
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
before do
|
33
|
+
allow(order).to receive_messages state: 'payment'
|
34
|
+
allow(controller).to receive_messages check_authorization: true
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'advanced_fraud_data in source should be updated' do
|
38
|
+
expect(order.payments).to be_empty
|
39
|
+
put :update, params: params
|
40
|
+
expect(order.reload.payments.last.source.advanced_fraud_data).to eq params[:device_data]
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'when nonce, credit card data in source should be updated from params' do
|
44
|
+
params[:order][:payments_attributes].first.delete('braintree_token')
|
45
|
+
params[:braintree_last_two] = '12'
|
46
|
+
put :update, params: params
|
47
|
+
expect(order.reload.payments.last.source.braintree_last_digits).to eq params[:braintree_last_two]
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'when token, credit card data in source should be updated from Braintree Vault' do
|
51
|
+
token = params[:order][:payments_attributes].first['braintree_token']
|
52
|
+
vaulted_payment_method = braintree_payment_method.vaulted_payment_method(token)
|
53
|
+
put :update, params: params
|
54
|
+
expect(order.reload.payments.last.source.braintree_last_digits).to eq vaulted_payment_method.last_4
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'when user tries to steal other user card' do
|
58
|
+
let(:other_user) { create(:user) }
|
59
|
+
let!(:card) { create(:credit_card, number: '123456', user: other_user) }
|
60
|
+
|
61
|
+
it 'does not create payment' do
|
62
|
+
params[:order].merge!(existing_card: card.id)
|
63
|
+
|
64
|
+
expect(order.payments).to be_empty
|
65
|
+
put :update, params: params
|
66
|
+
expect(order.reload.payments).to be_empty
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'braintree paypal express payment' do
|
72
|
+
before do
|
73
|
+
order.payments << create(:braintree_vzero_paypal_payment)
|
74
|
+
order.update(state: 'confirm')
|
75
|
+
allow(controller).to receive_messages check_authorization: true
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'amount in payment should be updated' do
|
79
|
+
expect(order.reload.payments.sum(:amount)).to eq 0
|
80
|
+
put :update, params: { state: 'confirm' }
|
81
|
+
expect(order.reload.payments.last.amount).to eq order.order_total_after_store_credit
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::OrdersController, type: :controller do
|
4
|
+
let(:user) { create(:user) }
|
5
|
+
let!(:country) { create(:country, iso: 'US') }
|
6
|
+
let!(:state) { create(:state, country: country) }
|
7
|
+
|
8
|
+
context '#update' do
|
9
|
+
let(:order) { OrderWalkthrough.up_to(:payment) }
|
10
|
+
|
11
|
+
before do
|
12
|
+
allow(controller).to receive_messages(try_spree_current_user: user)
|
13
|
+
allow(controller).to receive :check_authorization
|
14
|
+
allow(controller).to receive_messages current_order: order
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'standard checkout for order with braintree paypal express payment' do
|
18
|
+
before { order.payments << create(:braintree_vzero_paypal_payment) }
|
19
|
+
|
20
|
+
it 'it should invalidate paypal express payment' do
|
21
|
+
expect(order.reload.payments.valid.count).to eq 1
|
22
|
+
put :update, params: { order_id: order.id }
|
23
|
+
expect(order.reload.payments.valid.count).to eq 0
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'paypal express checkout' do
|
28
|
+
let(:payment_method) { create(:vzero_paypal_gateway) }
|
29
|
+
let(:params) do
|
30
|
+
{
|
31
|
+
order_id: order.id,
|
32
|
+
order: {
|
33
|
+
line_items_attributes: {
|
34
|
+
'0' => {
|
35
|
+
quantity: '1',
|
36
|
+
id: '127'
|
37
|
+
}
|
38
|
+
},
|
39
|
+
ship_address: {
|
40
|
+
zipcode: '95131',
|
41
|
+
full_name: 'undefined',
|
42
|
+
firstname: 'Spree',
|
43
|
+
lastname: 'Buyer',
|
44
|
+
address1: '1 Main St',
|
45
|
+
address2: 'undefined',
|
46
|
+
city: 'San Jose',
|
47
|
+
country: 'US',
|
48
|
+
state: Spree::State.first.abbr
|
49
|
+
},
|
50
|
+
email: 'spree_buyer@spreetest.com'
|
51
|
+
},
|
52
|
+
paypal: {
|
53
|
+
payment_method_id: payment_method.id.to_s,
|
54
|
+
payment_method_nonce: '2f7126df-ceee-40a6-a7b4-ab1b799810f3'
|
55
|
+
},
|
56
|
+
device_data: '{\"device_session_id\":\"4523fd012467562ec455926850f7ce11\",\"fraud_merchant_id\":\"600000\"}',
|
57
|
+
checkout: 'true'
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'it should save address both as billing and shipping (even when phone number is not passed)' do
|
62
|
+
put :update, params: params
|
63
|
+
data = params.slice(:order)[:order].slice(:ship_address)[:ship_address]
|
64
|
+
[order.ship_address, order.bill_address].each do |address|
|
65
|
+
expect(address.zipcode).to eq data[:zipcode]
|
66
|
+
expect(address.firstname).to eq data[:firstname]
|
67
|
+
expect(address.lastname).to eq data[:lastname]
|
68
|
+
expect(address.address1).to eq data[:address1]
|
69
|
+
expect(address.address2).to be_blank
|
70
|
+
expect(address.city).to eq data[:city]
|
71
|
+
expect(address.country.iso).to eq data[:country]
|
72
|
+
expect(address.state.abbr).to eq data[:state]
|
73
|
+
expect(address.phone).to be_blank
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'it should redirect to address page when address is invalid' do
|
78
|
+
put :update, params: params
|
79
|
+
|
80
|
+
[order.ship_address, order.bill_address].each do |address|
|
81
|
+
expect(address).to be_invalid
|
82
|
+
end
|
83
|
+
expect(response).to redirect_to checkout_state_path(:address, paypal_email: params[:order][:email])
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'it should redirect to address page when address is valid' do
|
87
|
+
params[:order][:ship_address][:phone] = '123456789'
|
88
|
+
put :update, params: params
|
89
|
+
|
90
|
+
[order.ship_address, order.bill_address].each do |address|
|
91
|
+
expect(address).to be_valid
|
92
|
+
end
|
93
|
+
expect(response).to redirect_to checkout_state_path(:address, paypal_email: params[:order][:email])
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|