solidus_braintree 2.0.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +42 -9
  3. data/.gitignore +1 -0
  4. data/.rubocop.yml +8 -1
  5. data/CHANGELOG.md +1 -189
  6. data/OLD_CHANGELOG.md +199 -0
  7. data/Rakefile +7 -1
  8. data/app/assets/config/solidus_braintree_manifest.js +0 -1
  9. data/app/assets/javascripts/spree/backend/solidus_braintree.js +4 -4
  10. data/app/models/solidus_braintree/gateway.rb +5 -1
  11. data/app/models/solidus_braintree/response.rb +1 -1
  12. data/app/models/solidus_braintree/source.rb +5 -0
  13. data/app/models/solidus_braintree/transaction.rb +1 -1
  14. data/app/models/solidus_braintree/transaction_import.rb +1 -0
  15. data/bin/dummy-app +37 -0
  16. data/bin/rails-dummy-app +17 -0
  17. data/bin/rspec +11 -0
  18. data/bin/sandbox +20 -62
  19. data/db/migrate/20230210104310_add_device_data_to_braintree_sources.rb +5 -0
  20. data/lib/generators/solidus_braintree/install/install_generator.rb +134 -34
  21. data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/javascripts/spree/frontend/paypal_button.js +1 -1
  22. data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/ajax.js +13 -0
  23. data/{app/assets/javascripts → lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend}/solidus_braintree/apple_pay_button.js +2 -2
  24. data/{app/assets/javascripts → lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend}/solidus_braintree/checkout.js +10 -5
  25. data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/client.js +239 -0
  26. data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/constants.js +89 -0
  27. data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/frontend.js +15 -0
  28. data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/hosted_form.js +48 -0
  29. data/{app/assets/javascripts → lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend}/solidus_braintree/paypal_button.js +4 -3
  30. data/{app/assets/javascripts → lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend}/solidus_braintree/paypal_messaging.js +1 -1
  31. data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/promise.js +20 -0
  32. data/{app/assets/javascripts → lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend}/solidus_braintree/venmo_button.js +1 -1
  33. data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree.js +1 -0
  34. data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/stylesheets/spree/frontend/solidus_braintree.scss +11 -0
  35. data/lib/{controllers/frontend → generators/solidus_braintree/install/templates/app/controllers}/solidus_braintree/checkouts_controller.rb +1 -1
  36. data/lib/{controllers/frontend → generators/solidus_braintree/install/templates/app/controllers}/solidus_braintree/transactions_controller.rb +5 -4
  37. data/lib/generators/solidus_braintree/install/templates/app/views/checkouts/existing_payment/_braintree.html.erb +2 -0
  38. data/lib/{views/frontend/spree/checkout → generators/solidus_braintree/install/templates/app/views/checkouts}/payment/_braintree.html.erb +1 -1
  39. data/lib/{views/frontend/solidus_braintree/payments/_payment.html.erb → generators/solidus_braintree/install/templates/app/views/payments/_braintree_payment_details.html.erb} +0 -3
  40. data/{app → lib/generators/solidus_braintree/install/templates/app}/views/spree/shared/_apple_pay_button.html.erb +1 -1
  41. data/{app → lib/generators/solidus_braintree/install/templates/app}/views/spree/shared/_braintree_head_scripts.html.erb +1 -1
  42. data/{app → lib/generators/solidus_braintree/install/templates/app}/views/spree/shared/_braintree_hosted_fields.html.erb +1 -4
  43. data/lib/{views/frontend → generators/solidus_braintree/install/templates/app/views}/spree/shared/_paypal_checkout_button.html.erb +1 -0
  44. data/lib/solidus_braintree/engine.rb +15 -10
  45. data/lib/solidus_braintree/version.rb +1 -1
  46. data/solidus_braintree.gemspec +4 -8
  47. data/spec/controllers/solidus_braintree/checkouts_controller_spec.rb +2 -2
  48. data/spec/controllers/solidus_braintree/client_tokens_controller_spec.rb +2 -2
  49. data/spec/controllers/solidus_braintree/configurations_controller_spec.rb +2 -2
  50. data/spec/controllers/solidus_braintree/transactions_controller_spec.rb +3 -3
  51. data/spec/fixtures/views/carts/_cart_footer.html.erb +18 -0
  52. data/spec/helpers/solidus_braintree/braintree_admin_helper_spec.rb +1 -1
  53. data/spec/helpers/solidus_braintree/braintree_checkout_helper_spec.rb +1 -1
  54. data/spec/models/solidus_braintree/address_spec.rb +1 -1
  55. data/spec/models/solidus_braintree/avs_result_spec.rb +1 -1
  56. data/spec/models/solidus_braintree/gateway_spec.rb +35 -3
  57. data/spec/models/solidus_braintree/response_spec.rb +1 -1
  58. data/spec/models/solidus_braintree/source_spec.rb +17 -1
  59. data/spec/models/solidus_braintree/transaction_address_spec.rb +2 -2
  60. data/spec/models/solidus_braintree/transaction_import_spec.rb +2 -2
  61. data/spec/models/solidus_braintree/transaction_spec.rb +2 -2
  62. data/spec/models/spree/store_spec.rb +2 -2
  63. data/spec/requests/spree/api/orders_controller_spec.rb +2 -2
  64. data/spec/solidus_braintree_helper.rb +7 -0
  65. data/{lib/solidus_braintree/testing_support → spec/support/solidus_braintree}/factories.rb +17 -15
  66. data/spec/support/{order_ready_for_payment.rb → solidus_braintree/order_ready_for_payment.rb} +9 -2
  67. data/spec/support/solidus_braintree/order_walkthrough.rb +87 -0
  68. data/spec/support/solidus_braintree/with_prepended_view_fixtures.rb +19 -0
  69. data/spec/{features → system}/backend/configuration_spec.rb +2 -2
  70. data/spec/{features → system}/backend/new_payment_spec.rb +3 -4
  71. data/spec/{features → system}/frontend/braintree_credit_card_checkout_spec.rb +23 -15
  72. data/spec/{features → system}/frontend/paypal_checkout_spec.rb +6 -3
  73. data/spec/{features → system}/frontend/venmo_checkout_spec.rb +8 -9
  74. metadata +95 -114
  75. data/app/assets/javascripts/solidus_braintree/frontend.js +0 -14
  76. data/app/assets/javascripts/spree/frontend/solidus_braintree.js +0 -1
  77. data/app/decorators/controllers/solidus_braintree/checkout_controller_decorator.rb +0 -11
  78. data/app/decorators/controllers/solidus_braintree/orders_controller_decorator.rb +0 -11
  79. data/app/overrides/spree/payments/payment/add_paypal_funding_source_to_payment.rb +0 -9
  80. data/app/views/spree/checkout/existing_payment/_braintree.html.erb +0 -10
  81. data/spec/fixtures/views/spree/orders/edit.html.erb +0 -50
  82. data/spec/spec_helper.rb +0 -32
  83. data/spec/support/views.rb +0 -1
  84. /data/app/assets/javascripts/{solidus_braintree → spree/backend/solidus_braintree}/client.js +0 -0
  85. /data/app/assets/javascripts/{solidus_braintree → spree/backend/solidus_braintree}/constants.js +0 -0
  86. /data/app/assets/javascripts/{solidus_braintree → spree/backend/solidus_braintree}/hosted_form.js +0 -0
  87. /data/app/assets/javascripts/{solidus_braintree → spree/backend/solidus_braintree}/promise.js +0 -0
  88. /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_active_blue_button_280x48.svg +0 -0
  89. /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_active_blue_button_320x48.svg +0 -0
  90. /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_active_blue_button_375x48.svg +0 -0
  91. /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_active_white_button_280x48.svg +0 -0
  92. /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_active_white_button_320x48.svg +0 -0
  93. /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_active_white_button_375x48.svg +0 -0
  94. /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_blue_acceptance_mark.svg +0 -0
  95. /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_blue_button_280x48.svg +0 -0
  96. /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_blue_button_320x48.svg +0 -0
  97. /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_blue_button_375x48.svg +0 -0
  98. /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_blue_logo.svg +0 -0
  99. /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_white_acceptance_mark.svg +0 -0
  100. /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_white_button_280x48.svg +0 -0
  101. /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_white_button_320x48.svg +0 -0
  102. /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_white_button_375x48.svg +0 -0
  103. /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_white_logo.svg +0 -0
  104. /data/{app → lib/generators/solidus_braintree/install/templates/app}/helpers/solidus_braintree/braintree_checkout_helper.rb +0 -0
  105. /data/{app → lib/generators/solidus_braintree/install/templates/app}/views/spree/shared/_braintree_errors.html.erb +0 -0
  106. /data/{app → lib/generators/solidus_braintree/install/templates/app}/views/spree/shared/_paypal_cart_button.html.erb +0 -0
  107. /data/{app → lib/generators/solidus_braintree/install/templates/app}/views/spree/shared/_paypal_messaging.html.erb +0 -0
  108. /data/{app → lib/generators/solidus_braintree/install/templates/app}/views/spree/shared/_venmo_button.html.erb +0 -0
  109. /data/lib/generators/solidus_braintree/install/templates/{initializer.rb → config/initializers/solidus_braintree.rb} +0 -0
  110. /data/spec/support/{capybara.rb → solidus_braintree/capybara.rb} +0 -0
  111. /data/spec/support/{gateway_helpers.rb → solidus_braintree/gateway_helpers.rb} +0 -0
  112. /data/spec/support/{vcr.rb → solidus_braintree/vcr.rb} +0 -0
@@ -32,6 +32,7 @@ module SolidusBraintree
32
32
  payment_type: transaction.payment_type,
33
33
  payment_method: transaction.payment_method,
34
34
  paypal_funding_source: transaction.paypal_funding_source,
35
+ device_data: transaction.device_data,
35
36
  user: user
36
37
  )
37
38
  end
data/bin/dummy-app ADDED
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -e
4
+
5
+ extension_name="solidus_braintree"
6
+
7
+ # Stay away from the bundler env of the containing extension.
8
+ function unbundled {
9
+ ruby -rbundler -e'b = proc {system *ARGV}; Bundler.respond_to?(:with_unbundled_env) ? Bundler.with_unbundled_env(&b) : Bundler.with_clean_env(&b)' -- "$@"
10
+ }
11
+
12
+ # "sqlite" is set by the ORB extension instead of "sqlite3",
13
+ # all other options are already in the format expected by `rails new`.
14
+ test "$DB" = "sqlite" && export DB="sqlite3"
15
+
16
+ rm -rf ./dummy-app
17
+ rails new dummy-app \
18
+ --database=${DB:-sqlite3} \
19
+ --skip-git \
20
+ --skip-keeps \
21
+ --skip-rc \
22
+ --skip-bootsnap \
23
+ --skip-test
24
+
25
+ if [ ! -d "dummy-app" ]; then
26
+ echo 'dummy-app rails application failed'
27
+ exit 1
28
+ fi
29
+
30
+ cd ./dummy-app
31
+ unbundled bundle add solidus --github solidusio/solidus --branch "${BRANCH:-master}" --version '> 0.a'
32
+ unbundled bundle exec rake db:drop db:create
33
+ unbundled bundle exec rails generate solidus:install --auto-accept --payment-method=none --no-seed --no-sample "$@"
34
+ unbundled bundle add $extension_name --path ..
35
+ unbundled bundle exec rails generate $extension_name:install --migrate --specs=all
36
+
37
+
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ root = "#{__dir__}/.."
4
+ app_root = "#{root}/dummy-app"
5
+
6
+ unless File.exist? "#{app_root}/bin/rails"
7
+ warn 'Creating the dummy-app app...'
8
+ Dir.chdir root do
9
+ system "#{root}/bin/dummy-app" or begin
10
+ warn 'Automatic creation of the dummy-app app failed'
11
+ exit 1
12
+ end
13
+ end
14
+ end
15
+
16
+ Dir.chdir app_root
17
+ exec "#{app_root}/bin/rails", *ARGV
data/bin/rspec ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -e
4
+
5
+ bin/rails-dummy-app generate solidus_braintree:install --force --migrate --specs=all
6
+
7
+ cd dummy-app/
8
+ rspec "$@"
9
+ exit_status=$?
10
+ cd -
11
+ exit $exit_status
data/bin/sandbox CHANGED
@@ -1,10 +1,6 @@
1
1
  #!/usr/bin/env bash
2
2
 
3
3
  set -e
4
- if [ -n "$DEBUG" ]
5
- then
6
- set -x
7
- fi
8
4
 
9
5
  case "$DB" in
10
6
  postgres|postgresql)
@@ -13,51 +9,37 @@ postgres|postgresql)
13
9
  mysql)
14
10
  RAILSDB="mysql"
15
11
  ;;
16
- sqlite3|sqlite)
17
- RAILSDB="sqlite3"
18
- ;;
19
- '')
20
- echo "~~> Use 'export DB=[postgres|mysql|sqlite]' to control the DB adapter"
12
+ sqlite|'')
21
13
  RAILSDB="sqlite3"
22
14
  ;;
23
15
  *)
24
- echo "Invalid value specified for the Solidus sandbox: DB=\"$DB\"."
25
- echo "Please use 'postgres', 'mysql', or 'sqlite' instead."
16
+ echo "Invalid DB specified: $DB"
26
17
  exit 1
27
18
  ;;
28
19
  esac
29
- echo "~~> Using $RAILSDB as the database engine"
30
-
31
- if [ -z "$SOLIDUS_BRANCH" ]
32
- then
33
- echo "~~> Use 'export SOLIDUS_BRANCH=[master|v3.2|...]' to control the Solidus branch"
34
- SOLIDUS_BRANCH="master"
35
- fi
36
- echo "~~> Using branch $SOLIDUS_BRANCH of solidus"
37
20
 
38
- if [ -z "$SOLIDUS_FRONTEND" ]
21
+ if [ ! -z $SOLIDUS_BRANCH ]
39
22
  then
40
- echo "~~> Use 'export SOLIDUS_FRONTEND=[solidus_frontend|solidus_starter_frontend]' to control the Solidus frontend"
41
- SOLIDUS_FRONTEND="solidus_frontend"
23
+ BRANCH=$SOLIDUS_BRANCH
24
+ else
25
+ BRANCH="master"
42
26
  fi
43
- echo "~~> Using branch $SOLIDUS_FRONTEND as the solidus frontend"
44
27
 
45
28
  extension_name="solidus_braintree"
46
29
 
47
30
  # Stay away from the bundler env of the containing extension.
48
31
  function unbundled {
49
- ruby -rbundler -e'b = proc {system *ARGV}; Bundler.respond_to?(:with_unbundled_env) ? Bundler.with_unbundled_env(&b) : Bundler.with_clean_env(&b)' -- $@
32
+ ruby -rbundler -e'b = proc {system *ARGV}; Bundler.respond_to?(:with_unbundled_env) ? Bundler.with_unbundled_env(&b) : Bundler.with_clean_env(&b)' -- "$@"
50
33
  }
51
34
 
52
35
  rm -rf ./sandbox
53
- unbundled bundle exec rails new sandbox --database="$RAILSDB" \
54
- --skip-bundle \
36
+ rails new sandbox \
37
+ --database="$RAILSDB" \
55
38
  --skip-git \
56
39
  --skip-keeps \
57
40
  --skip-rc \
58
- --skip-spring \
59
- --skip-test \
60
- --skip-javascript
41
+ --skip-bootsnap \
42
+ --skip-test
61
43
 
62
44
  if [ ! -d "sandbox" ]; then
63
45
  echo 'sandbox rails application failed'
@@ -65,39 +47,15 @@ if [ ! -d "sandbox" ]; then
65
47
  fi
66
48
 
67
49
  cd ./sandbox
68
- cat <<RUBY >> Gemfile
69
- gem 'solidus', github: 'solidusio/solidus', branch: '$SOLIDUS_BRANCH'
70
- gem 'rails-i18n'
71
- gem 'solidus_i18n'
72
-
73
- # This Braintree extension contains a user decorator, so the user class must be loaded first.
74
- gem "solidus_auth_devise", "~> 2.5"
75
- gem '$extension_name', path: '..'
76
-
77
- group :test, :development do
78
- platforms :mri do
79
- gem 'pry-byebug'
80
- end
81
- end
82
- RUBY
83
-
84
- unbundled bundle install --gemfile Gemfile
85
-
50
+ unbundled bundle add solidus --github solidusio/solidus --branch "${BRANCH:-master}" --version '> 0.a'
86
51
  unbundled bundle exec rake db:drop db:create
87
-
88
- # Still request "devise". Solidus will skip installing it again but will include its seeds.
89
- unbundled bundle exec rails generate solidus:install \
90
- --auto-accept \
91
- --user_class=Spree::User \
92
- --enforce_available_locales=true \
93
- --authentication="devise" \
94
- --payment-method=none \
95
- --frontend=${SOLIDUS_FRONTEND} \
96
- $@
97
-
98
- unbundled bundle exec rails generate solidus:auth:install --auto-run-migrations
99
- unbundled bundle exec rails generate ${extension_name}:install --auto-run-migrations
52
+ unbundled bundle exec rails generate solidus:install --payment-method=none --auto-accept "$@"
53
+ unbundled bundle add ${extension_name} --path '../'
54
+ unbundled bundle exec rails generate ${extension_name}:install --frontend=starter --migrate=true
100
55
 
101
56
  echo
102
- echo "🚀 Sandbox app successfully created for $extension_name!"
103
- echo "🧪 This app is intended for test purposes."
57
+ echo "🚀 Sandbox app successfully created for ${extension_name}!"
58
+ echo "🚀 Using $RAILSDB and Solidus $BRANCH"
59
+ echo "🚀 Use 'export DB=[postgres|mysql|sqlite]' to control the DB adapter"
60
+ echo "🚀 Use 'export SOLIDUS_BRANCH=<BRANCH-NAME>' to control the Solidus version"
61
+ echo "🚀 This app is intended for test purposes."
@@ -0,0 +1,5 @@
1
+ class AddDeviceDataToBraintreeSources < ActiveRecord::Migration[5.1]
2
+ def change
3
+ add_column :solidus_paypal_braintree_sources, :device_data, :string
4
+ end
5
+ end
@@ -1,12 +1,41 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'rails/generators/app_base'
4
+
3
5
  module SolidusBraintree
4
6
  module Generators
5
- class InstallGenerator < Rails::Generators::Base
6
- class_option :auto_run_migrations, type: :boolean, default: false
7
+ class InstallGenerator < Rails::Generators::AppBase
8
+ argument :app_path, type: :string, default: Rails.root
9
+
10
+ class_option :migrate, type: :boolean, default: true
11
+ class_option :backend, type: :boolean, default: true
12
+ class_option :frontend, type: :string, default: 'starter'
13
+
14
+ # This is only used to run all-specs during development and CI, regular installation limits
15
+ # installed specs to frontend, which are the ones related to code copied to the target application.
16
+ class_option :specs, type: :string, enum: %w[all frontend], default: 'frontend', hide: true
17
+
7
18
  source_root File.expand_path('templates', __dir__)
8
19
 
9
- def setup_initializer
20
+ def normalize_components_options
21
+ @components = {
22
+ backend: options[:backend],
23
+ starter_frontend: options[:frontend] == 'starter',
24
+ classic_frontend: options[:frontend] == 'classic',
25
+ }
26
+ end
27
+
28
+ def add_test_gems
29
+ gem_group :test do
30
+ ['vcr', 'webmock'].each do |gem_name|
31
+ gem gem_name unless Bundler.locked_gems.dependencies[gem_name]
32
+ end
33
+ end
34
+
35
+ bundle_command 'install'
36
+ end
37
+
38
+ def setup_initializers
10
39
  legacy_initializer_pathname =
11
40
  Pathname.new(destination_root).join('config/initializers/solidus_paypal_braintree.rb')
12
41
 
@@ -17,57 +46,128 @@ module SolidusBraintree
17
46
  "SolidusPaypalBraintree.configure do |config|\n",
18
47
  "SolidusBraintree.configure do |config|\n"
19
48
  else
20
- template 'initializer.rb', 'config/initializers/solidus_braintree.rb'
49
+ directory 'config/initializers', 'config/initializers'
21
50
  end
22
51
  end
23
52
 
24
- def setup_javascripts
25
- gsub_file 'vendor/assets/javascripts/spree/frontend/all.js',
26
- "//= require spree/frontend/solidus_paypal_braintree\n", ''
27
-
28
- append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/solidus_braintree\n"
53
+ def run_migrations
54
+ rake 'railties:install:migrations FROM=solidus_braintree'
55
+ run 'bin/rails db:migrate' if options[:migrate]
56
+ end
29
57
 
30
- gsub_file 'vendor/assets/javascripts/spree/backend/all.js',
31
- "//= require spree/backend/solidus_paypal_braintree\n", ''
58
+ def mount_engine
59
+ gsub_file 'config/routes.rb',
60
+ "mount SolidusPaypalBraintree::Engine, at: '/solidus_paypal_braintree'\n", ''
32
61
 
33
- append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/solidus_braintree\n"
62
+ route "mount SolidusBraintree::Engine, at: '/solidus_braintree'"
34
63
  end
35
64
 
36
- def setup_stylesheets
37
- gsub_file 'vendor/assets/stylesheets/spree/frontend/all.css',
38
- " *= require spree/frontend/solidus_paypal_braintree\n", ''
65
+ def install_solidus_backend_support
66
+ support_code_for(:backend) do
67
+ gsub_file 'vendor/assets/javascripts/spree/backend/all.js',
68
+ "//= require spree/backend/solidus_paypal_braintree\n", ''
39
69
 
40
- inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css',
41
- " *= require spree/frontend/solidus_braintree\n", before: %r{\*/}, verbose: true
70
+ append_file 'vendor/assets/javascripts/spree/backend/all.js',
71
+ "//= require spree/backend/solidus_braintree\n"
42
72
 
43
- gsub_file 'vendor/assets/stylesheets/spree/backend/all.css',
44
- " *= require spree/backend/solidus_paypal_braintree\n", ''
73
+ gsub_file 'vendor/assets/stylesheets/spree/backend/all.css',
74
+ " *= require spree/backend/solidus_paypal_braintree\n", ''
45
75
 
46
- inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css',
47
- " *= require spree/backend/solidus_braintree\n", before: %r{\*/}, verbose: true
76
+ inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css',
77
+ " *= require spree/backend/solidus_braintree\n", before: %r{\*/}, verbose: true
78
+ end
48
79
  end
49
80
 
50
- def add_migrations
51
- rake 'railties:install:migrations FROM=solidus_braintree'
81
+ def install_solidus_starter_frontend_support
82
+ support_code_for(:starter_frontend) do
83
+ directory 'app', 'app'
84
+
85
+ inject_into_file 'vendor/assets/javascripts/spree/frontend/all.js',
86
+ "//= require jquery3\n",
87
+ before: '//= require rails-ujs',
88
+ verbose: true
89
+
90
+ gsub_file 'vendor/assets/javascripts/spree/frontend/all.js',
91
+ "//= require spree/frontend/solidus_paypal_braintree\n", ''
92
+
93
+ append_file 'app/assets/javascripts/solidus_starter_frontend.js',
94
+ "//= require spree/frontend/solidus_braintree\n"
95
+
96
+ gsub_file 'vendor/assets/stylesheets/spree/frontend/all.css',
97
+ " *= require spree/frontend/solidus_paypal_braintree\n", ''
98
+
99
+ inject_into_file 'app/assets/stylesheets/solidus_starter_frontend.css',
100
+ " *= require spree/frontend/solidus_braintree\n", before: %r{\*/}, verbose: true
101
+
102
+ inject_into_class 'app/controllers/checkouts_controller.rb',
103
+ 'CheckoutsController',
104
+ " helper SolidusBraintree::BraintreeCheckoutHelper\n\n",
105
+ verbose: true
106
+
107
+ inject_into_class 'app/controllers/carts_controller.rb',
108
+ 'CartsController',
109
+ " helper SolidusBraintree::BraintreeCheckoutHelper\n\n",
110
+ verbose: true
111
+
112
+ inject_into_file 'app/views/orders/_payment_info.html.erb',
113
+ " <li><%= render 'payments/braintree_payment_details', payment: payment %></li>\n",
114
+ after: "<li><%= payment.payment_method.name %></li>\n",
115
+ verbose: true
116
+
117
+ spec_paths =
118
+ case options[:specs]
119
+ when 'all' then %w[spec]
120
+ when 'frontend'
121
+ %w[
122
+ spec/solidus_braintree_helper.rb
123
+ spec/system/frontend
124
+ spec/support
125
+ spec/fixtures
126
+ ]
127
+ end
128
+
129
+ spec_paths.each do |path|
130
+ if engine.root.join(path).directory?
131
+ directory engine.root.join(path), path
132
+ else
133
+ template engine.root.join(path), path
134
+ end
135
+ end
136
+ end
52
137
  end
53
138
 
54
- def mount_engine
55
- gsub_file 'config/routes.rb',
56
- "mount SolidusPaypalBraintree::Engine, at: '/solidus_paypal_braintree'\n", ''
57
-
58
- route "mount SolidusBraintree::Engine, at: '/solidus_braintree'"
139
+ def alert_no_classic_frontend_support
140
+ support_code_for(:classic_frontend) do
141
+ message = <<~TEXT
142
+ For solidus_frontend compatibility, please use version 2.x.
143
+ The new version of this extension only supports Solidus Starter Frontend.
144
+ No frontend code has been copied to your application.
145
+ TEXT
146
+ say_status :error, set_color(message.tr("\n", ' '), :red), :red
147
+ end
59
148
  end
60
149
 
61
- def run_migrations
62
- run_migrations = options[:auto_run_migrations] ||
63
- ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]'))
150
+ private
64
151
 
65
- if run_migrations
66
- rake 'db:migrate'
152
+ def support_code_for(component_name, &block)
153
+ if @components[component_name]
154
+ say_status :install, "[#{engine.engine_name}] solidus_#{component_name}", :blue
155
+ shell.indent(&block)
67
156
  else
68
- puts 'Skipping bin/rails db:migrate, don\'t forget to run it!' # rubocop:disable Rails/Output
157
+ say_status :skip, "[#{engine.engine_name}] solidus_#{component_name}", :blue
69
158
  end
70
159
  end
160
+
161
+ def engine
162
+ SolidusBraintree::Engine
163
+ end
164
+
165
+ def bundle_command(command, env = {})
166
+ # Make `bundle install` less verbose by skipping the "Using ..." messages
167
+ super(command, env.reverse_merge('BUNDLE_SUPPRESS_INSTALL_USING_MESSAGES' => 'true'))
168
+ ensure
169
+ Bundler.reset_paths!
170
+ end
71
171
  end
72
172
  end
73
173
  end
@@ -1,4 +1,4 @@
1
- //= require solidus_braintree/paypal_button
1
+ //= require spree/frontend/solidus_braintree/paypal_button
2
2
 
3
3
  // This is the PayPal button on the cart page
4
4
  $(document).ready(function() {
@@ -0,0 +1,13 @@
1
+ SolidusBraintree.ajax = function(url, options) {
2
+ if (typeof url === "object") {
3
+ options = url;
4
+ url = undefined;
5
+ }
6
+ options = options || {};
7
+ options = $.extend(options, {
8
+ headers: {
9
+ 'Authorization': 'Bearer '
10
+ }
11
+ });
12
+ return $.ajax(url, options);
13
+ };
@@ -1,4 +1,4 @@
1
- //= require solidus_braintree/constants
1
+ //= require spree/frontend/solidus_braintree/constants
2
2
  /**
3
3
  * Constructor for Apple Pay button object
4
4
  * @constructor
@@ -94,7 +94,7 @@ SolidusBraintree.ApplepayButton.prototype.tokenize = function (session, payment)
94
94
  };
95
95
 
96
96
  SolidusBraintree.ApplepayButton.prototype._createTransaction = function (session, payment, payload) {
97
- Spree.ajax({
97
+ SolidusBraintree.ajax({
98
98
  data: this._transactionParams(payload, payment.shippingContact),
99
99
  dataType: 'json',
100
100
  type: 'POST',
@@ -1,4 +1,4 @@
1
- //= require solidus_braintree/frontend
1
+ //= require spree/frontend/solidus_braintree/frontend
2
2
 
3
3
  $(function() {
4
4
  /* This provides a default error handler for Braintree. Since we prevent
@@ -40,9 +40,9 @@ $(function() {
40
40
  $paymentForm.on("submit",function(event) {
41
41
  var $field = $(hostedField);
42
42
 
43
- if ($field.is(":visible") && !$field.data("submitting")) {
43
+ if ($field.is(":visible") && $field.is(":enabled") && !$field.data("submitting")) {
44
44
  var $nonce = $("#payment_method_nonce", $field);
45
-
45
+ var $deviceData = $("#device_data", $field);
46
46
  if ($nonce.length > 0 && $nonce.val() === "") {
47
47
  var client = braintreeForm._merchantConfigurationOptions._solidusClient;
48
48
 
@@ -56,6 +56,10 @@ $(function() {
56
56
  }
57
57
 
58
58
  $nonce.val(payload.nonce);
59
+
60
+ if (client._dataCollectorInstance) {
61
+ $deviceData.val(client._dataCollectorInstance.deviceData);
62
+ }
59
63
 
60
64
  if (!client.useThreeDSecure) {
61
65
  $paymentForm.submit();
@@ -84,7 +88,7 @@ $(function() {
84
88
 
85
89
  var $paymentForm = $("#checkout_form_payment");
86
90
  var $hostedFields = $("[data-braintree-hosted-fields]");
87
- var $submitButton = $("input[type='submit']", $paymentForm);
91
+ var $submitButton = $("[type='submit']", $paymentForm);
88
92
 
89
93
  // If we're not using hosted fields, the form doesn't need to wait.
90
94
  if ($hostedFields.length > 0) {
@@ -93,8 +97,9 @@ $(function() {
93
97
  var fieldPromises = $hostedFields.map(function(index, field) {
94
98
  var $this = $(this);
95
99
  var id = $this.data("id");
100
+ var useDataCollector = $this.data("use-data-collector");
96
101
 
97
- var braintreeForm = new SolidusBraintree.createHostedForm(id);
102
+ var braintreeForm = new SolidusBraintree.createHostedForm(id, useDataCollector);
98
103
 
99
104
  var formInitializationSuccess = function(formObject) {
100
105
  addFormHook(formObject, field);