solidus_braintree 3.3.0 → 3.4.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 +4 -4
- data/.github/dependabot.yml +7 -0
- data/.github/workflows/lint.yml +25 -0
- data/.github/workflows/test.yml +77 -0
- data/.rubocop.yml +5 -84
- data/.standard.yml +6 -0
- data/Gemfile +12 -17
- data/README.md +7 -5
- data/Rakefile +7 -7
- data/app/helpers/solidus_braintree/braintree_admin_helper.rb +4 -4
- data/app/models/solidus_braintree/avs_result.rb +34 -34
- data/app/models/solidus_braintree/base_record.rb +1 -1
- data/app/models/solidus_braintree/configuration.rb +11 -11
- data/app/models/solidus_braintree/gateway.rb +14 -16
- data/app/models/solidus_braintree/response.rb +9 -9
- data/app/models/solidus_braintree/source.rb +5 -5
- data/app/models/solidus_braintree/transaction.rb +2 -2
- data/app/models/solidus_braintree/transaction_address.rb +5 -5
- data/app/models/solidus_braintree/transaction_import.rb +2 -2
- data/app/{decorators/models/solidus_braintree/spree_store_decorator.rb → patches/models/solidus_braintree/spree_store_patch.rb} +1 -1
- data/app/{decorators/models/solidus_braintree/spree_user_decorator.rb → patches/models/solidus_braintree/spree_user_patch.rb} +2 -2
- data/bin/dummy-app +22 -3
- data/bin/rails-sandbox +4 -4
- data/bin/rspec +6 -0
- data/bin/sandbox +55 -31
- data/db/migrate/20161114231422_create_solidus_paypal_braintree_configurations.rb +2 -2
- data/db/migrate/20170508085402_add_not_null_constraint_to_sources_payment_type.rb +2 -2
- data/db/migrate/20230109080950_rename_solidus_paypal_braintree_source_type.rb +3 -3
- data/lib/controllers/api/solidus_braintree/client_tokens_controller.rb +2 -2
- data/lib/controllers/backend/solidus_braintree/configurations_controller.rb +4 -4
- data/lib/generators/solidus_braintree/install/install_generator.rb +48 -40
- data/lib/generators/solidus_braintree/install/templates/app/controllers/solidus_braintree/checkouts_controller.rb +7 -7
- data/lib/generators/solidus_braintree/install/templates/app/controllers/solidus_braintree/transactions_controller.rb +7 -7
- data/lib/generators/solidus_braintree/install/templates/app/helpers/solidus_braintree/braintree_checkout_helper.rb +5 -5
- data/{app/decorators/controllers/solidus_braintree/admin_payments_controller_decorator.rb → lib/patches/backend/controllers/solidus_braintree/admin_payments_controller_patch.rb} +1 -1
- data/lib/solidus_braintree/engine.rb +13 -24
- data/lib/solidus_braintree/extension_configuration.rb +1 -1
- data/lib/solidus_braintree/request_protection.rb +2 -2
- data/lib/solidus_braintree/version.rb +1 -1
- data/lib/solidus_braintree.rb +8 -8
- data/lib/solidus_paypal_braintree.rb +2 -2
- data/mise.toml +2 -0
- data/solidus_braintree.gemspec +23 -22
- metadata +59 -147
- data/.circleci/config.yml +0 -79
- data/lib/views/backend_v1.2/spree/admin/payments/source_forms/_braintree.html.erb +0 -16
- data/lib/views/backend_v2.4/spree/admin/shared/preference_fields/_hash.html.erb +0 -12
- data/spec/controllers/solidus_braintree/checkouts_controller_spec.rb +0 -99
- data/spec/controllers/solidus_braintree/client_tokens_controller_spec.rb +0 -55
- data/spec/controllers/solidus_braintree/configurations_controller_spec.rb +0 -73
- data/spec/controllers/solidus_braintree/transactions_controller_spec.rb +0 -183
- data/spec/fixtures/cassettes/admin/invalid_credit_card.yml +0 -63
- data/spec/fixtures/cassettes/admin/resubmit_credit_card.yml +0 -352
- data/spec/fixtures/cassettes/admin/valid_credit_card.yml +0 -412
- data/spec/fixtures/cassettes/braintree/create_profile.yml +0 -71
- data/spec/fixtures/cassettes/braintree/generate_token.yml +0 -63
- data/spec/fixtures/cassettes/braintree/token.yml +0 -63
- data/spec/fixtures/cassettes/checkout/invalid_credit_card.yml +0 -63
- data/spec/fixtures/cassettes/checkout/resubmit_credit_card.yml +0 -216
- data/spec/fixtures/cassettes/checkout/update.yml +0 -71
- data/spec/fixtures/cassettes/checkout/valid_credit_card.yml +0 -171
- data/spec/fixtures/cassettes/checkout/valid_venmo_transaction.yml +0 -599
- data/spec/fixtures/cassettes/gateway/authorize/credit_card/address.yml +0 -86
- data/spec/fixtures/cassettes/gateway/authorize/merchant_account/EUR.yml +0 -154
- data/spec/fixtures/cassettes/gateway/authorize/paypal/EUR.yml +0 -90
- data/spec/fixtures/cassettes/gateway/authorize/paypal/address.yml +0 -90
- data/spec/fixtures/cassettes/gateway/authorize.yml +0 -86
- data/spec/fixtures/cassettes/gateway/authorized_transaction.yml +0 -73
- data/spec/fixtures/cassettes/gateway/cancel/missing.yml +0 -63
- data/spec/fixtures/cassettes/gateway/cancel/refunds.yml +0 -272
- data/spec/fixtures/cassettes/gateway/cancel/void.yml +0 -201
- data/spec/fixtures/cassettes/gateway/capture.yml +0 -141
- data/spec/fixtures/cassettes/gateway/complete.yml +0 -157
- data/spec/fixtures/cassettes/gateway/credit.yml +0 -208
- data/spec/fixtures/cassettes/gateway/customer.yml +0 -79
- data/spec/fixtures/cassettes/gateway/purchase.yml +0 -87
- data/spec/fixtures/cassettes/gateway/settled_transaction.yml +0 -140
- data/spec/fixtures/cassettes/gateway/void.yml +0 -137
- data/spec/fixtures/cassettes/source/bin.yml +0 -295
- data/spec/fixtures/cassettes/source/card_type.yml +0 -267
- data/spec/fixtures/cassettes/source/last4.yml +0 -267
- data/spec/fixtures/cassettes/transaction/import/valid/capture.yml +0 -224
- data/spec/fixtures/cassettes/transaction/import/valid.yml +0 -71
- data/spec/fixtures/views/carts/_cart_footer.html.erb +0 -18
- data/spec/helpers/solidus_braintree/braintree_admin_helper_spec.rb +0 -17
- data/spec/helpers/solidus_braintree/braintree_checkout_helper_spec.rb +0 -70
- data/spec/models/solidus_braintree/address_spec.rb +0 -71
- data/spec/models/solidus_braintree/avs_result_spec.rb +0 -317
- data/spec/models/solidus_braintree/gateway_spec.rb +0 -774
- data/spec/models/solidus_braintree/response_spec.rb +0 -280
- data/spec/models/solidus_braintree/source_spec.rb +0 -555
- data/spec/models/solidus_braintree/transaction_address_spec.rb +0 -235
- data/spec/models/solidus_braintree/transaction_import_spec.rb +0 -302
- data/spec/models/solidus_braintree/transaction_spec.rb +0 -86
- data/spec/models/spree/store_spec.rb +0 -14
- data/spec/requests/spree/api/orders_controller_spec.rb +0 -36
- data/spec/solidus_braintree_spec_helper.rb +0 -9
- data/spec/support/solidus_braintree/capybara.rb +0 -7
- data/spec/support/solidus_braintree/factories.rb +0 -55
- data/spec/support/solidus_braintree/gateway_helpers.rb +0 -29
- data/spec/support/solidus_braintree/order_ready_for_payment.rb +0 -44
- data/spec/support/solidus_braintree/order_walkthrough.rb +0 -87
- data/spec/support/solidus_braintree/vcr.rb +0 -38
- data/spec/support/solidus_braintree/with_prepended_view_fixtures.rb +0 -19
- data/spec/system/backend/configuration_spec.rb +0 -23
- data/spec/system/backend/new_payment_spec.rb +0 -136
- data/spec/system/frontend/braintree_credit_card_checkout_spec.rb +0 -199
- data/spec/system/frontend/paypal_checkout_spec.rb +0 -168
- data/spec/system/frontend/venmo_checkout_spec.rb +0 -193
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require "active_model"
|
|
4
4
|
|
|
5
5
|
module SolidusBraintree
|
|
6
6
|
class Transaction
|
|
@@ -15,7 +15,7 @@ module SolidusBraintree
|
|
|
15
15
|
|
|
16
16
|
validate do
|
|
17
17
|
unless payment_method.is_a? SolidusBraintree::Gateway
|
|
18
|
-
errors.add(:payment_method,
|
|
18
|
+
errors.add(:payment_method, "Must be braintree")
|
|
19
19
|
end
|
|
20
20
|
if address&.invalid?
|
|
21
21
|
address.errors.each do |error|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
3
|
+
require "active_model"
|
|
4
|
+
require "solidus_braintree/country_mapper"
|
|
5
5
|
|
|
6
6
|
module SolidusBraintree
|
|
7
7
|
class TransactionAddress
|
|
@@ -13,7 +13,7 @@ module SolidusBraintree
|
|
|
13
13
|
:address_line_1, :address_line_2, :first_name, :last_name
|
|
14
14
|
|
|
15
15
|
validates :address_line_1, :city, :zip, :country_code, presence: true
|
|
16
|
-
validates :name, presence: true, unless: ->(address){ address.first_name.present? }
|
|
16
|
+
validates :name, presence: true, unless: ->(address) { address.first_name.present? }
|
|
17
17
|
|
|
18
18
|
before_validation do
|
|
19
19
|
self.country_code = country_code.presence || "us"
|
|
@@ -28,7 +28,7 @@ module SolidusBraintree
|
|
|
28
28
|
attributes[:country_code] = iso_from_name(country_name)
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
super
|
|
31
|
+
super
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
def spree_country
|
|
@@ -36,7 +36,7 @@ module SolidusBraintree
|
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
def spree_state
|
|
39
|
-
spree_country && state_code && (
|
|
39
|
+
spree_country && state_code && (@state ||= spree_country.states.find_by(
|
|
40
40
|
::Spree::State.arel_table[:name].matches(state_code).or(
|
|
41
41
|
::Spree::State.arel_table[:abbr].matches(state_code)
|
|
42
42
|
)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require "active_model"
|
|
4
4
|
|
|
5
5
|
module SolidusBraintree
|
|
6
6
|
class TransactionImport
|
|
@@ -61,7 +61,7 @@ module SolidusBraintree
|
|
|
61
61
|
advance_order(payment, end_state)
|
|
62
62
|
else
|
|
63
63
|
raise InvalidImportError,
|
|
64
|
-
"Validation failed: #{errors.full_messages.join(
|
|
64
|
+
"Validation failed: #{errors.full_messages.join(", ")}"
|
|
65
65
|
end
|
|
66
66
|
end
|
|
67
67
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module SolidusBraintree
|
|
4
|
-
module
|
|
4
|
+
module SpreeStorePatch
|
|
5
5
|
def self.prepended(base)
|
|
6
6
|
base.has_one :braintree_configuration, class_name: "SolidusBraintree::Configuration", dependent: :destroy
|
|
7
7
|
base.before_create :build_default_configuration
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module SolidusBraintree
|
|
4
|
-
module
|
|
4
|
+
module SpreeUserPatch
|
|
5
5
|
def self.prepended(base)
|
|
6
|
-
base.has_one :braintree_customer, class_name:
|
|
6
|
+
base.has_one :braintree_customer, class_name: "SolidusBraintree::Customer", inverse_of: :user
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
::Spree.user_class.prepend self
|
data/bin/dummy-app
CHANGED
|
@@ -6,7 +6,7 @@ extension_name="solidus_braintree"
|
|
|
6
6
|
|
|
7
7
|
# Stay away from the bundler env of the containing extension.
|
|
8
8
|
function unbundled {
|
|
9
|
-
ruby -rbundler -e'b = proc {system
|
|
9
|
+
ruby -rbundler -e'b = proc {system(*ARGV) or exit 1}; Bundler.respond_to?(:with_unbundled_env) ? Bundler.with_unbundled_env(&b) : Bundler.with_clean_env(&b)' -- "$@"
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
# "sqlite" is set by the ORB extension instead of "sqlite3",
|
|
@@ -15,7 +15,9 @@ test "$DB" = "sqlite" && export DB="sqlite3"
|
|
|
15
15
|
|
|
16
16
|
rm -rf ./dummy-app
|
|
17
17
|
rails_version=`bundle exec ruby -e'require "rails"; puts Rails.version'`
|
|
18
|
-
|
|
18
|
+
# `bundle exec` would leak the extension's BUNDLE_GEMFILE into the commands
|
|
19
|
+
# `rails new` spawns (importmap:install, ...), which then silently fail.
|
|
20
|
+
bundle exec ruby -e 'ENV.replace(Bundler.original_env); load Gem.bin_path("railties", "rails")' -- new dummy-app \
|
|
19
21
|
--database=${DB:-sqlite3} \
|
|
20
22
|
--skip-git \
|
|
21
23
|
--skip-keeps \
|
|
@@ -29,8 +31,25 @@ if [ ! -d "dummy-app" ]; then
|
|
|
29
31
|
fi
|
|
30
32
|
|
|
31
33
|
cd ./dummy-app
|
|
32
|
-
|
|
34
|
+
|
|
35
|
+
mkdir -p app/assets/config
|
|
36
|
+
cat <<MANIFESTJS > app/assets/config/manifest.js
|
|
37
|
+
//= link_tree ../images
|
|
38
|
+
//= link_directory ../javascripts .js
|
|
39
|
+
//= link_directory ../stylesheets .css
|
|
40
|
+
MANIFESTJS
|
|
41
|
+
|
|
42
|
+
unbundled bundle add solidus --github solidusio/solidus --branch "${SOLIDUS_BRANCH:-${BRANCH:-main}}" --version '> 0.a'
|
|
43
|
+
# ActiveSupport < 8.1 passes `quirks_mode` to JSON.generate, which json 3 rejects.
|
|
44
|
+
if ruby -e "exit Gem::Version.new('$rails_version') < Gem::Version.new('8.1')"; then
|
|
45
|
+
unbundled bundle add json --version '< 3'
|
|
46
|
+
fi
|
|
33
47
|
unbundled bundle exec rake db:drop db:create
|
|
48
|
+
# Solidus >= 4.8 fetches the storefront from main for prerelease (.dev) versions,
|
|
49
|
+
# which on a stable branch installs a storefront incompatible with its core.
|
|
50
|
+
if [ -n "$SOLIDUS_BRANCH" ] && [ -z "$SOLIDUS_STOREFRONT_TEMPLATE" ]; then
|
|
51
|
+
export SOLIDUS_STOREFRONT_TEMPLATE="https://github.com/solidusio/solidus/raw/$SOLIDUS_BRANCH/storefront/template.rb"
|
|
52
|
+
fi
|
|
34
53
|
unbundled bundle exec rails generate solidus:install --auto-accept --payment-method=none --no-seed --no-sample --admin-preview=false "$@"
|
|
35
54
|
unbundled bundle add $extension_name --path ..
|
|
36
55
|
unbundled bundle exec rails generate $extension_name:install --migrate --specs=all
|
data/bin/rails-sandbox
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
|
|
3
|
-
app_root =
|
|
3
|
+
app_root = "sandbox"
|
|
4
4
|
|
|
5
5
|
unless File.exist? "#{app_root}/bin/rails"
|
|
6
|
-
warn
|
|
6
|
+
warn "Creating the sandbox app..."
|
|
7
7
|
Dir.chdir "#{__dir__}/.." do
|
|
8
8
|
system "#{__dir__}/sandbox" or begin
|
|
9
|
-
warn
|
|
9
|
+
warn "Automatic creation of the sandbox app failed"
|
|
10
10
|
exit 1
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
Dir.chdir app_root
|
|
16
|
-
exec
|
|
16
|
+
exec "bin/rails", *ARGV
|
data/bin/rspec
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
set -e
|
|
4
4
|
|
|
5
|
+
# The dummy app's database.yml (from `rails new`) ignores DB_HOST/DB_USERNAME
|
|
6
|
+
# for PostgreSQL, but libpq picks up PGHOST/PGUSER.
|
|
7
|
+
if [ "$DB" = "postgresql" ]; then
|
|
8
|
+
export PGHOST="${PGHOST:-$DB_HOST}" PGUSER="${PGUSER:-$DB_USERNAME}"
|
|
9
|
+
fi
|
|
10
|
+
|
|
5
11
|
echo "Updating the dummy app..."
|
|
6
12
|
bin/rails-dummy-app generate solidus_braintree:install --force --migrate --specs=all
|
|
7
13
|
|
data/bin/sandbox
CHANGED
|
@@ -1,40 +1,38 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
|
|
3
3
|
set -e
|
|
4
|
+
test -z "${DEBUG+empty_string}" || set -x
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
;;
|
|
12
|
-
sqlite|'')
|
|
13
|
-
RAILSDB="sqlite3"
|
|
14
|
-
;;
|
|
15
|
-
*)
|
|
16
|
-
echo "Invalid DB specified: $DB"
|
|
17
|
-
exit 1
|
|
18
|
-
;;
|
|
19
|
-
esac
|
|
6
|
+
test "$DB" = "sqlite" && export DB="sqlite3"
|
|
7
|
+
|
|
8
|
+
if [ -z "$PAYMENT_METHOD" ]
|
|
9
|
+
then
|
|
10
|
+
PAYMENT_METHOD="none"
|
|
11
|
+
fi
|
|
20
12
|
|
|
21
|
-
if [
|
|
13
|
+
if [ -z "$SOLIDUS_BRANCH" ]
|
|
22
14
|
then
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
BRANCH="main"
|
|
15
|
+
echo "~~> Use 'export SOLIDUS_BRANCH=[main|v4.0|...]' to control the Solidus branch"
|
|
16
|
+
SOLIDUS_BRANCH="main"
|
|
26
17
|
fi
|
|
18
|
+
echo "~~> Using branch $SOLIDUS_BRANCH of solidus"
|
|
27
19
|
|
|
28
20
|
extension_name="solidus_braintree"
|
|
29
21
|
|
|
30
22
|
# Stay away from the bundler env of the containing extension.
|
|
31
23
|
function unbundled {
|
|
32
|
-
ruby -rbundler -e'
|
|
24
|
+
ruby -rbundler -e'
|
|
25
|
+
Bundler.with_unbundled_env {system *ARGV}' -- \
|
|
26
|
+
env BUNDLE_SUPPRESS_INSTALL_USING_MESSAGES=true $@
|
|
33
27
|
}
|
|
34
28
|
|
|
29
|
+
echo "~~~> Removing the old sandbox"
|
|
35
30
|
rm -rf ./sandbox
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
|
|
32
|
+
echo "~~~> Creating a pristine Rails app"
|
|
33
|
+
rails_version=`bundle exec ruby -e'require "rails"; puts Rails.version'`
|
|
34
|
+
rails _${rails_version}_ new sandbox \
|
|
35
|
+
--database="${DB:-sqlite3}" \
|
|
38
36
|
--skip-git \
|
|
39
37
|
--skip-keeps \
|
|
40
38
|
--skip-rc \
|
|
@@ -46,16 +44,42 @@ if [ ! -d "sandbox" ]; then
|
|
|
46
44
|
exit 1
|
|
47
45
|
fi
|
|
48
46
|
|
|
47
|
+
echo "~~~> Adding solidus (with i18n) to the Gemfile"
|
|
49
48
|
cd ./sandbox
|
|
50
|
-
|
|
49
|
+
cat <<RUBY >> Gemfile
|
|
50
|
+
gem 'solidus', github: 'solidusio/solidus', branch: '$SOLIDUS_BRANCH'
|
|
51
|
+
gem 'rails-i18n'
|
|
52
|
+
gem 'solidus_i18n'
|
|
53
|
+
gem 'solidus_auth_devise'
|
|
54
|
+
|
|
55
|
+
gem '$extension_name', path: '..'
|
|
56
|
+
|
|
57
|
+
group :test, :development do
|
|
58
|
+
platforms :mri do
|
|
59
|
+
gem 'pry-byebug'
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
RUBY
|
|
63
|
+
|
|
64
|
+
echo "Generating manifest file"
|
|
65
|
+
mkdir -p app/assets/config
|
|
66
|
+
cat <<MANIFESTJS > app/assets/config/manifest.js
|
|
67
|
+
//= link_tree ../images
|
|
68
|
+
//= link_directory ../javascripts .js
|
|
69
|
+
//= link_directory ../stylesheets .css
|
|
70
|
+
MANIFESTJS
|
|
71
|
+
|
|
72
|
+
unbundled bundle install --gemfile Gemfile
|
|
73
|
+
|
|
51
74
|
unbundled bundle exec rake db:drop db:create
|
|
52
|
-
|
|
53
|
-
unbundled bundle
|
|
54
|
-
|
|
75
|
+
|
|
76
|
+
unbundled bundle exec rails generate solidus:install \
|
|
77
|
+
--auto-accept \
|
|
78
|
+
$@
|
|
79
|
+
|
|
80
|
+
unbundled bundle exec rails generate solidus:auth:install --auto-run-migrations
|
|
81
|
+
unbundled bundle exec rails generate ${extension_name}:install --auto-run-migrations
|
|
55
82
|
|
|
56
83
|
echo
|
|
57
|
-
echo "🚀 Sandbox app successfully created for $
|
|
58
|
-
echo "
|
|
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."
|
|
84
|
+
echo "🚀 Sandbox app successfully created for $extension_name!"
|
|
85
|
+
echo "🧪 This app is intended for test purposes."
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
class CreateSolidusPaypalBraintreeConfigurations < SolidusSupport::Migration[4.2]
|
|
2
2
|
def change
|
|
3
3
|
create_table :solidus_paypal_braintree_configurations do |t|
|
|
4
|
-
t.boolean :paypal,
|
|
4
|
+
t.boolean :paypal, null: false, default: false
|
|
5
5
|
t.boolean :apple_pay, null: false, default: false
|
|
6
|
-
t.integer :store_id,
|
|
6
|
+
t.integer :store_id, null: false, index: true, foreign_key: {references: :spree_stores}
|
|
7
7
|
|
|
8
8
|
t.timestamps null: false
|
|
9
9
|
end
|
|
@@ -5,8 +5,8 @@ class AddNotNullConstraintToSourcesPaymentType < SolidusSupport::Migration[4.2]
|
|
|
5
5
|
def change
|
|
6
6
|
reversible do |dir|
|
|
7
7
|
dir.up do
|
|
8
|
-
SolidusPaypalBraintreeSource.where(payment_type: nil)
|
|
9
|
-
update_all(payment_type:
|
|
8
|
+
SolidusPaypalBraintreeSource.where(payment_type: nil)
|
|
9
|
+
.update_all(payment_type: "CreditCard")
|
|
10
10
|
end
|
|
11
11
|
end
|
|
12
12
|
change_column_null(:solidus_paypal_braintree_sources, :payment_type, false)
|
|
@@ -7,19 +7,19 @@ class RenameSolidusPaypalBraintreeSourceType < ActiveRecord::Migration[6.1]
|
|
|
7
7
|
|
|
8
8
|
def up
|
|
9
9
|
Spree::Payment.unscoped
|
|
10
|
-
.where(source_type:
|
|
10
|
+
.where(source_type: "SolidusPaypalBraintree::Source").in_batches do |relation|
|
|
11
11
|
relation.update_all("source_type = 'SolidusBraintree::Source'")
|
|
12
12
|
sleep(0.01)
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
Spree::WalletPaymentSource.unscoped
|
|
16
|
-
.where(payment_source_type:
|
|
16
|
+
.where(payment_source_type: "SolidusPaypalBraintree::Source").in_batches do |relation|
|
|
17
17
|
relation.update_all("payment_source_type = 'SolidusBraintree::Source'")
|
|
18
18
|
sleep(0.01)
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
Spree::PaymentMethod.unscoped
|
|
22
|
-
.where(
|
|
22
|
+
.where("type = ?", "SolidusPaypalBraintree::Gateway").in_batches do |relation|
|
|
23
23
|
relation.update_all("type = 'SolidusBraintree::Gateway'")
|
|
24
24
|
sleep(0.01)
|
|
25
25
|
end
|
|
@@ -9,9 +9,9 @@ module SolidusBraintree
|
|
|
9
9
|
def create
|
|
10
10
|
token = @gateway.generate_token
|
|
11
11
|
if token
|
|
12
|
-
render json: {
|
|
12
|
+
render json: {client_token: token, payment_method_id: @gateway.id}
|
|
13
13
|
else
|
|
14
|
-
render json: {
|
|
14
|
+
render json: {error: Gateway::TOKEN_GENERATION_DISABLED_MESSAGE}, status: :unprocessable_entity
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
17
|
|
|
@@ -16,9 +16,9 @@ module SolidusBraintree
|
|
|
16
16
|
params = configurations_params[:configuration_fields]
|
|
17
17
|
results = SolidusBraintree::Configuration.update(params.keys, params.values)
|
|
18
18
|
if results.all?(&:valid?)
|
|
19
|
-
flash[:success] = t(
|
|
19
|
+
flash[:success] = t("update_success", scope: "solidus_braintree.configurations")
|
|
20
20
|
else
|
|
21
|
-
flash[:error] = t(
|
|
21
|
+
flash[:error] = t("update_error", scope: "solidus_braintree.configurations")
|
|
22
22
|
end
|
|
23
23
|
redirect_to action: :list
|
|
24
24
|
end
|
|
@@ -26,8 +26,8 @@ module SolidusBraintree
|
|
|
26
26
|
private
|
|
27
27
|
|
|
28
28
|
def configurations_params
|
|
29
|
-
params.require(:configurations)
|
|
30
|
-
permit(configuration_fields: [
|
|
29
|
+
params.require(:configurations)
|
|
30
|
+
.permit(configuration_fields: [
|
|
31
31
|
:paypal,
|
|
32
32
|
:apple_pay,
|
|
33
33
|
:venmo,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require "rails/generators/app_base"
|
|
4
4
|
|
|
5
5
|
module SolidusBraintree
|
|
6
6
|
module Generators
|
|
@@ -9,115 +9,115 @@ module SolidusBraintree
|
|
|
9
9
|
|
|
10
10
|
class_option :migrate, type: :boolean, default: true
|
|
11
11
|
class_option :backend, type: :boolean, default: true
|
|
12
|
-
class_option :frontend, type: :string, default:
|
|
12
|
+
class_option :frontend, type: :string, default: "starter"
|
|
13
13
|
|
|
14
14
|
# This is only used to run all-specs during development and CI, regular installation limits
|
|
15
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:
|
|
16
|
+
class_option :specs, type: :string, enum: %w[all frontend], default: "frontend", hide: true
|
|
17
17
|
|
|
18
|
-
source_root File.expand_path(
|
|
18
|
+
source_root File.expand_path("templates", __dir__)
|
|
19
19
|
|
|
20
20
|
def normalize_components_options
|
|
21
21
|
@components = {
|
|
22
22
|
backend: options[:backend],
|
|
23
|
-
starter_frontend: options[:frontend] ==
|
|
24
|
-
classic_frontend: options[:frontend] ==
|
|
23
|
+
starter_frontend: options[:frontend] == "starter",
|
|
24
|
+
classic_frontend: options[:frontend] == "classic"
|
|
25
25
|
}
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
def add_test_gems
|
|
29
29
|
gem_group :test do
|
|
30
|
-
[
|
|
30
|
+
["vcr", "webmock"].each do |gem_name|
|
|
31
31
|
gem gem_name unless Bundler.locked_gems.dependencies[gem_name]
|
|
32
32
|
end
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
-
bundle_command
|
|
35
|
+
bundle_command "install"
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
def setup_initializers
|
|
39
39
|
legacy_initializer_pathname =
|
|
40
|
-
Pathname.new(destination_root).join(
|
|
40
|
+
Pathname.new(destination_root).join("config/initializers/solidus_paypal_braintree.rb")
|
|
41
41
|
|
|
42
42
|
if legacy_initializer_pathname.exist?
|
|
43
|
-
legacy_initializer_pathname.rename(
|
|
43
|
+
legacy_initializer_pathname.rename("config/initializers/solidus_braintree.rb")
|
|
44
44
|
|
|
45
|
-
gsub_file
|
|
45
|
+
gsub_file "config/initializers/solidus_braintree.rb",
|
|
46
46
|
"SolidusPaypalBraintree.configure do |config|\n",
|
|
47
47
|
"SolidusBraintree.configure do |config|\n"
|
|
48
48
|
else
|
|
49
|
-
directory
|
|
49
|
+
directory "config/initializers", "config/initializers"
|
|
50
50
|
end
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
def run_migrations
|
|
54
|
-
rake
|
|
55
|
-
run
|
|
54
|
+
rake "railties:install:migrations FROM=solidus_braintree"
|
|
55
|
+
run "bin/rails db:migrate" if options[:migrate]
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
def mount_engine
|
|
59
|
-
gsub_file
|
|
60
|
-
"mount SolidusPaypalBraintree::Engine, at: '/solidus_paypal_braintree'\n",
|
|
59
|
+
gsub_file "config/routes.rb",
|
|
60
|
+
"mount SolidusPaypalBraintree::Engine, at: '/solidus_paypal_braintree'\n", ""
|
|
61
61
|
|
|
62
62
|
route "mount SolidusBraintree::Engine, at: '#{solidus_mount_point}solidus_braintree'"
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
def install_solidus_backend_support
|
|
66
66
|
support_code_for(:backend) do
|
|
67
|
-
gsub_file
|
|
68
|
-
"//= require spree/backend/solidus_paypal_braintree\n",
|
|
67
|
+
gsub_file "vendor/assets/javascripts/spree/backend/all.js",
|
|
68
|
+
"//= require spree/backend/solidus_paypal_braintree\n", ""
|
|
69
69
|
|
|
70
|
-
append_file
|
|
70
|
+
append_file "vendor/assets/javascripts/spree/backend/all.js",
|
|
71
71
|
"//= require spree/backend/solidus_braintree\n"
|
|
72
72
|
|
|
73
|
-
gsub_file
|
|
74
|
-
" *= 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", ""
|
|
75
75
|
|
|
76
|
-
inject_into_file
|
|
76
|
+
inject_into_file "vendor/assets/stylesheets/spree/backend/all.css",
|
|
77
77
|
" *= require spree/backend/solidus_braintree\n", before: %r{\*/}, verbose: true
|
|
78
78
|
end
|
|
79
79
|
end
|
|
80
80
|
|
|
81
81
|
def install_solidus_starter_frontend_support
|
|
82
82
|
support_code_for(:starter_frontend) do
|
|
83
|
-
directory
|
|
83
|
+
directory "app", "app"
|
|
84
84
|
|
|
85
|
-
inject_into_file
|
|
85
|
+
inject_into_file "vendor/assets/javascripts/spree/frontend/all.js",
|
|
86
86
|
"//= require jquery3\n",
|
|
87
|
-
before:
|
|
87
|
+
before: "//= require rails-ujs",
|
|
88
88
|
verbose: true
|
|
89
89
|
|
|
90
|
-
gsub_file
|
|
91
|
-
"//= require spree/frontend/solidus_paypal_braintree\n",
|
|
90
|
+
gsub_file "vendor/assets/javascripts/spree/frontend/all.js",
|
|
91
|
+
"//= require spree/frontend/solidus_paypal_braintree\n", ""
|
|
92
92
|
|
|
93
|
-
append_file
|
|
93
|
+
append_file "app/assets/javascripts/#{frontend_manifest_name}.js",
|
|
94
94
|
"//= require spree/frontend/solidus_braintree\n"
|
|
95
95
|
|
|
96
|
-
gsub_file
|
|
97
|
-
" *= require spree/frontend/solidus_paypal_braintree\n",
|
|
96
|
+
gsub_file "vendor/assets/stylesheets/spree/frontend/all.css",
|
|
97
|
+
" *= require spree/frontend/solidus_paypal_braintree\n", ""
|
|
98
98
|
|
|
99
|
-
inject_into_file
|
|
99
|
+
inject_into_file "app/assets/stylesheets/#{frontend_manifest_name}.css",
|
|
100
100
|
" *= require spree/frontend/solidus_braintree\n", before: %r{\*/}, verbose: true
|
|
101
101
|
|
|
102
|
-
inject_into_class
|
|
103
|
-
|
|
102
|
+
inject_into_class "app/controllers/checkouts_controller.rb",
|
|
103
|
+
"CheckoutsController",
|
|
104
104
|
" helper SolidusBraintree::BraintreeCheckoutHelper\n\n",
|
|
105
105
|
verbose: true
|
|
106
106
|
|
|
107
|
-
inject_into_class
|
|
108
|
-
|
|
107
|
+
inject_into_class "app/controllers/carts_controller.rb",
|
|
108
|
+
"CartsController",
|
|
109
109
|
" helper SolidusBraintree::BraintreeCheckoutHelper\n\n",
|
|
110
110
|
verbose: true
|
|
111
111
|
|
|
112
|
-
inject_into_file
|
|
112
|
+
inject_into_file "app/views/orders/_payment_info.html.erb",
|
|
113
113
|
" <li><%= render 'payments/braintree_payment_details', payment: payment %></li>\n",
|
|
114
114
|
after: "<li><%= payment.payment_method.name %></li>\n",
|
|
115
115
|
verbose: true
|
|
116
116
|
|
|
117
117
|
spec_paths =
|
|
118
118
|
case options[:specs]
|
|
119
|
-
when
|
|
120
|
-
when
|
|
119
|
+
when "all" then %w[spec]
|
|
120
|
+
when "frontend"
|
|
121
121
|
%w[
|
|
122
122
|
spec/solidus_braintree_spec_helper.rb
|
|
123
123
|
spec/system/frontend
|
|
@@ -143,12 +143,20 @@ module SolidusBraintree
|
|
|
143
143
|
The new version of this extension only supports Solidus Starter Frontend.
|
|
144
144
|
No frontend code has been copied to your application.
|
|
145
145
|
TEXT
|
|
146
|
-
say_status :error, set_color(message.tr("\n",
|
|
146
|
+
say_status :error, set_color(message.tr("\n", " "), :red), :red
|
|
147
147
|
end
|
|
148
148
|
end
|
|
149
149
|
|
|
150
150
|
private
|
|
151
151
|
|
|
152
|
+
def frontend_manifest_name
|
|
153
|
+
if File.exist?(File.join(destination_root, "app/assets/javascripts/solidus_storefront.js"))
|
|
154
|
+
"solidus_storefront"
|
|
155
|
+
else
|
|
156
|
+
"solidus_starter_frontend"
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
152
160
|
def solidus_mount_point
|
|
153
161
|
mount_point = Spree::Core::Engine.routes.find_script_name({})
|
|
154
162
|
mount_point += "/" unless mount_point.end_with?("/")
|
|
@@ -170,7 +178,7 @@ module SolidusBraintree
|
|
|
170
178
|
|
|
171
179
|
def bundle_command(command, env = {})
|
|
172
180
|
# Make `bundle install` less verbose by skipping the "Using ..." messages
|
|
173
|
-
super(command, env.reverse_merge(
|
|
181
|
+
super(command, env.reverse_merge("BUNDLE_SUPPRESS_INSTALL_USING_MESSAGES" => "true"))
|
|
174
182
|
ensure
|
|
175
183
|
Bundler.reset_paths!
|
|
176
184
|
end
|
|
@@ -4,10 +4,10 @@ module SolidusBraintree
|
|
|
4
4
|
class CheckoutsController < CheckoutsController
|
|
5
5
|
PERMITTED_PAYMENT_PARAMS = [
|
|
6
6
|
:payment_method_id,
|
|
7
|
-
{
|
|
7
|
+
{source_attributes: [
|
|
8
8
|
:nonce,
|
|
9
9
|
:payment_type
|
|
10
|
-
]
|
|
10
|
+
]}
|
|
11
11
|
].freeze
|
|
12
12
|
|
|
13
13
|
def update
|
|
@@ -21,11 +21,11 @@ module SolidusBraintree
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def payment_params
|
|
24
|
-
params
|
|
25
|
-
require(:order)
|
|
26
|
-
require(:payments_attributes)
|
|
27
|
-
first
|
|
28
|
-
permit(PERMITTED_PAYMENT_PARAMS)
|
|
24
|
+
params
|
|
25
|
+
.require(:order)
|
|
26
|
+
.require(:payments_attributes)
|
|
27
|
+
.first
|
|
28
|
+
.permit(PERMITTED_PAYMENT_PARAMS)
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
31
|
end
|
|
@@ -10,10 +10,10 @@ module SolidusBraintree
|
|
|
10
10
|
:paypal_funding_source,
|
|
11
11
|
:phone,
|
|
12
12
|
:email,
|
|
13
|
-
{
|
|
13
|
+
{address_attributes: [
|
|
14
14
|
:country_code, :country_name, :name, :city, :zip, :state_code,
|
|
15
15
|
:address_line_1, :address_line_2, :first_name, :last_name
|
|
16
|
-
]
|
|
16
|
+
]},
|
|
17
17
|
:device_data
|
|
18
18
|
].freeze
|
|
19
19
|
|
|
@@ -27,11 +27,11 @@ module SolidusBraintree
|
|
|
27
27
|
import.import!(import_state, restart_checkout: restart_checkout)
|
|
28
28
|
|
|
29
29
|
format.html { redirect_to redirect_url(import) }
|
|
30
|
-
format.json { render json: {
|
|
30
|
+
format.json { render json: {redirectUrl: redirect_url(import)} }
|
|
31
31
|
else
|
|
32
32
|
status = 422
|
|
33
33
|
format.html { import_error(import) }
|
|
34
|
-
format.json { render json: {
|
|
34
|
+
format.json { render json: {errors: import.errors, status: status}, status: status }
|
|
35
35
|
end
|
|
36
36
|
end
|
|
37
37
|
end
|
|
@@ -39,12 +39,12 @@ module SolidusBraintree
|
|
|
39
39
|
private
|
|
40
40
|
|
|
41
41
|
def import_state
|
|
42
|
-
params[:state] ||
|
|
42
|
+
params[:state] || "confirm"
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
def import_error(import)
|
|
46
46
|
raise InvalidImportError,
|
|
47
|
-
"Import invalid: #{import.errors.full_messages.join(
|
|
47
|
+
"Import invalid: #{import.errors.full_messages.join(", ")}"
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
def redirect_url(import)
|
|
@@ -58,7 +58,7 @@ module SolidusBraintree
|
|
|
58
58
|
def transaction_params
|
|
59
59
|
params.require(:transaction)
|
|
60
60
|
.permit(PERMITTED_BRAINTREE_TRANSACTION_PARAMS)
|
|
61
|
-
.merge({
|
|
61
|
+
.merge({payment_method: payment_method})
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
def payment_method
|