solidus_braintree 3.2.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.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +7 -0
  3. data/.github/workflows/lint.yml +25 -0
  4. data/.github/workflows/test.yml +77 -0
  5. data/.rubocop.yml +5 -84
  6. data/.standard.yml +6 -0
  7. data/7.2 +0 -0
  8. data/Gemfile +12 -20
  9. data/README.md +7 -5
  10. data/Rakefile +7 -7
  11. data/app/helpers/solidus_braintree/braintree_admin_helper.rb +4 -4
  12. data/app/models/solidus_braintree/avs_result.rb +34 -34
  13. data/app/models/solidus_braintree/base_record.rb +11 -0
  14. data/app/models/solidus_braintree/configuration.rb +12 -12
  15. data/app/models/solidus_braintree/customer.rb +1 -1
  16. data/app/models/solidus_braintree/gateway.rb +14 -17
  17. data/app/models/solidus_braintree/response.rb +9 -9
  18. data/app/models/solidus_braintree/source.rb +9 -7
  19. data/app/models/solidus_braintree/transaction.rb +2 -2
  20. data/app/models/solidus_braintree/transaction_address.rb +5 -5
  21. data/app/models/solidus_braintree/transaction_import.rb +2 -2
  22. data/app/{decorators/models/solidus_braintree/spree_store_decorator.rb → patches/models/solidus_braintree/spree_store_patch.rb} +1 -1
  23. data/app/{decorators/models/solidus_braintree/spree_user_decorator.rb → patches/models/solidus_braintree/spree_user_patch.rb} +2 -2
  24. data/bin/dummy-app +23 -3
  25. data/bin/rails-sandbox +4 -4
  26. data/bin/rspec +6 -0
  27. data/bin/sandbox +55 -31
  28. data/db/migrate/20161114231422_create_solidus_paypal_braintree_configurations.rb +2 -2
  29. data/db/migrate/20170508085402_add_not_null_constraint_to_sources_payment_type.rb +2 -2
  30. data/db/migrate/20230109080950_rename_solidus_paypal_braintree_source_type.rb +3 -3
  31. data/{app/decorators/controllers → lib/controllers/api}/solidus_braintree/client_tokens_controller.rb +2 -2
  32. data/lib/controllers/backend/solidus_braintree/configurations_controller.rb +4 -4
  33. data/lib/generators/solidus_braintree/install/install_generator.rb +48 -40
  34. data/lib/generators/solidus_braintree/install/templates/app/controllers/solidus_braintree/checkouts_controller.rb +7 -7
  35. data/lib/generators/solidus_braintree/install/templates/app/controllers/solidus_braintree/transactions_controller.rb +7 -7
  36. data/lib/generators/solidus_braintree/install/templates/app/helpers/solidus_braintree/braintree_checkout_helper.rb +5 -5
  37. data/{app/decorators/controllers/solidus_braintree/admin_payments_controller_decorator.rb → lib/patches/backend/controllers/solidus_braintree/admin_payments_controller_patch.rb} +1 -1
  38. data/lib/solidus_braintree/engine.rb +13 -24
  39. data/lib/solidus_braintree/extension_configuration.rb +1 -1
  40. data/lib/solidus_braintree/request_protection.rb +2 -2
  41. data/lib/solidus_braintree/version.rb +1 -1
  42. data/lib/solidus_braintree.rb +8 -10
  43. data/lib/solidus_paypal_braintree.rb +2 -2
  44. data/mise.toml +2 -0
  45. data/solidus_braintree.gemspec +23 -22
  46. metadata +62 -152
  47. data/.circleci/config.yml +0 -80
  48. data/app/models/application_record.rb +0 -5
  49. data/lib/views/backend_v1.2/spree/admin/payments/source_forms/_braintree.html.erb +0 -16
  50. data/lib/views/backend_v2.4/spree/admin/shared/preference_fields/_hash.html.erb +0 -12
  51. data/spec/controllers/solidus_braintree/checkouts_controller_spec.rb +0 -99
  52. data/spec/controllers/solidus_braintree/client_tokens_controller_spec.rb +0 -55
  53. data/spec/controllers/solidus_braintree/configurations_controller_spec.rb +0 -73
  54. data/spec/controllers/solidus_braintree/transactions_controller_spec.rb +0 -183
  55. data/spec/fixtures/cassettes/admin/invalid_credit_card.yml +0 -63
  56. data/spec/fixtures/cassettes/admin/resubmit_credit_card.yml +0 -352
  57. data/spec/fixtures/cassettes/admin/valid_credit_card.yml +0 -412
  58. data/spec/fixtures/cassettes/braintree/create_profile.yml +0 -71
  59. data/spec/fixtures/cassettes/braintree/generate_token.yml +0 -63
  60. data/spec/fixtures/cassettes/braintree/token.yml +0 -63
  61. data/spec/fixtures/cassettes/checkout/invalid_credit_card.yml +0 -63
  62. data/spec/fixtures/cassettes/checkout/resubmit_credit_card.yml +0 -216
  63. data/spec/fixtures/cassettes/checkout/update.yml +0 -71
  64. data/spec/fixtures/cassettes/checkout/valid_credit_card.yml +0 -171
  65. data/spec/fixtures/cassettes/checkout/valid_venmo_transaction.yml +0 -599
  66. data/spec/fixtures/cassettes/gateway/authorize/credit_card/address.yml +0 -86
  67. data/spec/fixtures/cassettes/gateway/authorize/merchant_account/EUR.yml +0 -154
  68. data/spec/fixtures/cassettes/gateway/authorize/paypal/EUR.yml +0 -90
  69. data/spec/fixtures/cassettes/gateway/authorize/paypal/address.yml +0 -90
  70. data/spec/fixtures/cassettes/gateway/authorize.yml +0 -86
  71. data/spec/fixtures/cassettes/gateway/authorized_transaction.yml +0 -73
  72. data/spec/fixtures/cassettes/gateway/cancel/missing.yml +0 -63
  73. data/spec/fixtures/cassettes/gateway/cancel/refunds.yml +0 -272
  74. data/spec/fixtures/cassettes/gateway/cancel/void.yml +0 -201
  75. data/spec/fixtures/cassettes/gateway/capture.yml +0 -141
  76. data/spec/fixtures/cassettes/gateway/complete.yml +0 -157
  77. data/spec/fixtures/cassettes/gateway/credit.yml +0 -208
  78. data/spec/fixtures/cassettes/gateway/customer.yml +0 -79
  79. data/spec/fixtures/cassettes/gateway/purchase.yml +0 -87
  80. data/spec/fixtures/cassettes/gateway/settled_transaction.yml +0 -140
  81. data/spec/fixtures/cassettes/gateway/void.yml +0 -137
  82. data/spec/fixtures/cassettes/source/bin.yml +0 -295
  83. data/spec/fixtures/cassettes/source/card_type.yml +0 -267
  84. data/spec/fixtures/cassettes/source/last4.yml +0 -267
  85. data/spec/fixtures/cassettes/transaction/import/valid/capture.yml +0 -224
  86. data/spec/fixtures/cassettes/transaction/import/valid.yml +0 -71
  87. data/spec/fixtures/views/carts/_cart_footer.html.erb +0 -18
  88. data/spec/helpers/solidus_braintree/braintree_admin_helper_spec.rb +0 -17
  89. data/spec/helpers/solidus_braintree/braintree_checkout_helper_spec.rb +0 -70
  90. data/spec/models/solidus_braintree/address_spec.rb +0 -71
  91. data/spec/models/solidus_braintree/avs_result_spec.rb +0 -317
  92. data/spec/models/solidus_braintree/gateway_spec.rb +0 -774
  93. data/spec/models/solidus_braintree/response_spec.rb +0 -280
  94. data/spec/models/solidus_braintree/source_spec.rb +0 -555
  95. data/spec/models/solidus_braintree/transaction_address_spec.rb +0 -235
  96. data/spec/models/solidus_braintree/transaction_import_spec.rb +0 -302
  97. data/spec/models/solidus_braintree/transaction_spec.rb +0 -86
  98. data/spec/models/spree/store_spec.rb +0 -14
  99. data/spec/requests/spree/api/orders_controller_spec.rb +0 -36
  100. data/spec/solidus_braintree_spec_helper.rb +0 -9
  101. data/spec/support/solidus_braintree/capybara.rb +0 -7
  102. data/spec/support/solidus_braintree/factories.rb +0 -55
  103. data/spec/support/solidus_braintree/gateway_helpers.rb +0 -29
  104. data/spec/support/solidus_braintree/order_ready_for_payment.rb +0 -44
  105. data/spec/support/solidus_braintree/order_walkthrough.rb +0 -87
  106. data/spec/support/solidus_braintree/vcr.rb +0 -38
  107. data/spec/support/solidus_braintree/with_prepended_view_fixtures.rb +0 -19
  108. data/spec/system/backend/configuration_spec.rb +0 -23
  109. data/spec/system/backend/new_payment_spec.rb +0 -136
  110. data/spec/system/frontend/braintree_credit_card_checkout_spec.rb +0 -199
  111. data/spec/system/frontend/paypal_checkout_spec.rb +0 -168
  112. data/spec/system/frontend/venmo_checkout_spec.rb +0 -193
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a594a4aeb7d585ddd83ce566831645aa8a9dea516d5d843ec0adb19be69706cc
4
- data.tar.gz: 281cf7ebd47dffac6f7ba3ff0bcdb58b02b146335c45fa1ce11779875c641296
3
+ metadata.gz: 20decb10931454aa4855df2b427a24c1f22f502b363ebba35b13e2757eeb53b3
4
+ data.tar.gz: 3d93d374dc39443b75e2473de2c073d0357b087df6d44a5436cf8fc4fb37c0d8
5
5
  SHA512:
6
- metadata.gz: b6ce1d929444ef3ba0e090dba54c4252a7339cd4f0b7f1d9d2d8216f1496ab85e545903f7e71c0cc517e7899455ca9befe3904174874bf42b2db67204553d25a
7
- data.tar.gz: 8b2ddbd7938cfb3b99af2ab28e675e539f3c01a8875cdb9af536e7871e7a79a94978705e5cbf86f87f493415f8aff858b797a479d42b282f259be1d7ae027a08
6
+ metadata.gz: 63729983efe298f30fdbaa79e951c8f8e8ec3dcea9378dce4d7249054784f286518cc4ec7fbbb1c39e9e662617bd6b15ebf3354dfcc6f79c80b39da0bc47888f
7
+ data.tar.gz: d18c988f0d90d5045bb3e6ecd00bd925afd638d4deebdd846d7dd2ac27aa22a8feb56eeedde53a87d1cf62efc000fb6aeb93664fbeb605dd12a9bb8b52aa9d6e
@@ -0,0 +1,7 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: bundler
4
+ directory: "/"
5
+ schedule:
6
+ interval: daily
7
+ open-pull-requests-limit: 10
@@ -0,0 +1,25 @@
1
+ name: Lint
2
+
3
+ on: [pull_request]
4
+
5
+ concurrency:
6
+ group: lint-${{ github.ref_name }}
7
+ cancel-in-progress: ${{ github.ref_name != 'main' }}
8
+
9
+ permissions:
10
+ contents: read
11
+
12
+ jobs:
13
+ ruby:
14
+ name: Check Ruby
15
+ runs-on: ubuntu-24.04
16
+ steps:
17
+ - name: Checkout code
18
+ uses: actions/checkout@v3
19
+ - name: Install Ruby and gems
20
+ uses: ruby/setup-ruby@v1
21
+ with:
22
+ ruby-version: "3.2"
23
+ bundler-cache: true
24
+ - name: Lint Ruby files
25
+ run: bundle exec standardrb
@@ -0,0 +1,77 @@
1
+ name: Test
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ pull_request:
8
+ schedule:
9
+ - cron: "0 0 * * 4" # every Thursday
10
+
11
+ concurrency:
12
+ group: test-${{ github.ref_name }}
13
+ cancel-in-progress: ${{ github.ref_name != 'main' }}
14
+
15
+ permissions:
16
+ contents: read
17
+
18
+ jobs:
19
+ rspec:
20
+ name: Solidus ${{ matrix.solidus_branch }}, Rails ${{ matrix.rails_version }} and Ruby ${{ matrix.ruby_version }} on ${{ matrix.database }}
21
+ runs-on: ubuntu-24.04
22
+ strategy:
23
+ fail-fast: false
24
+ matrix:
25
+ rails_version: ["8.1", "8.0"]
26
+ ruby_version: ["3.4", "4.0"]
27
+ solidus_branch: ["v4.6", "v4.7", "v4.8"]
28
+ database: ["postgresql", "mysql", "sqlite"]
29
+ exclude:
30
+ - solidus_branch: "v4.6"
31
+ rails_version: "8.1"
32
+ env:
33
+ BRAINTREE_PUBLIC_KEY: ${{ secrets.BRAINTREE_PUBLIC_KEY }}
34
+ BRAINTREE_PRIVATE_KEY: ${{ secrets.BRAINTREE_PRIVATE_KEY }}
35
+ BRAINTREE_MERCHANT_ID: ${{ secrets.BRAINTREE_MERCHANT_ID }}
36
+ BRAINTREE_PAYPAL_PAYEE_EMAIL: ${{ secrets.BRAINTREE_PAYPAL_PAYEE_EMAIL }}
37
+ services:
38
+ postgres:
39
+ image: postgres:18
40
+ env:
41
+ POSTGRES_HOST_AUTH_METHOD: trust
42
+ options: >-
43
+ --health-cmd="pg_isready"
44
+ --health-interval=10s
45
+ --health-timeout=5s
46
+ --health-retries=5
47
+ ports:
48
+ - 5432:5432
49
+ mysql:
50
+ image: mysql:8
51
+ env:
52
+ MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
53
+ options: >-
54
+ --health-cmd="mysqladmin ping"
55
+ --health-interval=10s
56
+ --health-timeout=5s
57
+ --health-retries=5
58
+ ports:
59
+ - 3306:3306
60
+ steps:
61
+ - uses: actions/checkout@v4
62
+ - name: Run extension tests
63
+ uses: solidusio/test-solidus-extension@main
64
+ with:
65
+ database: ${{ matrix.database }}
66
+ rails-version: ${{ matrix.rails_version }}
67
+ ruby-version: ${{ matrix.ruby_version }}
68
+ solidus-branch: ${{ matrix.solidus_branch }}
69
+ - name: Upload failure artifacts
70
+ if: failure()
71
+ uses: actions/upload-artifact@v4
72
+ with:
73
+ name: failures-solidus${{ matrix.solidus_branch }}-rails${{ matrix.rails_version }}-ruby${{ matrix.ruby_version }}-${{ matrix.database }}
74
+ path: |
75
+ dummy-app/tmp/capybara
76
+ dummy-app/log/test.log
77
+ if-no-files-found: ignore
data/.rubocop.yml CHANGED
@@ -1,86 +1,7 @@
1
- require:
2
- - solidus_dev_support/rubocop
1
+ require: standard
3
2
 
4
- AllCops:
5
- NewCops: disable
6
- TargetRubyVersion: '3.0'
7
- Exclude:
8
- - sandbox/**/*
9
- - dummy-app/**/*
10
- - spec/dummy/**/*
11
- - vendor/bundle/**/*
12
-
13
- Layout/FirstArgumentIndentation:
14
- EnforcedStyle: consistent
15
-
16
- Layout/FirstArrayElementIndentation:
17
- EnforcedStyle: consistent
18
-
19
- Layout/FirstHashElementIndentation:
20
- EnforcedStyle: consistent
21
-
22
- Layout/MultilineMethodCallIndentation:
23
- EnforcedStyle: indented
24
-
25
- Naming/VariableNumber:
26
- Enabled: false
27
-
28
- # We use this extensively, the alternatives are not viable or desirable.
29
- RSpec/AnyInstance:
30
- Enabled: false
31
-
32
- # No need to make the code more complex for no real gain.
33
- RSpec/MessageSpies:
34
- Enabled: false
35
-
36
- # Let's consider legitimate to have multiple expectations within an example.
37
- RSpec/MultipleExpectations:
38
- Enabled: false
39
-
40
- # Allow to use subject as is, no big deal.
41
- RSpec/NamedSubject:
42
- Enabled: false
3
+ inherit_gem:
4
+ standard: config/base.yml
43
5
 
44
- # Let's set this to some really exagerate value.
45
- RSpec/NestedGroups:
46
- Max: 8
47
-
48
- # We don't use the FactoryBot mixin
49
- RSpec/FactoryBot/SyntaxMethods:
50
- Enabled: false
51
-
52
- RSpec/VerifiedDoubles:
53
- # Sometimes you really need an "anything" double
54
- IgnoreSymbolicNames: true
55
-
56
- Style/FrozenStringLiteralComment:
57
- Exclude:
58
- - spec/**/*
59
- - db/migrate/**/*
60
- - bin/**/*
61
-
62
- Style/ExplicitBlockArgument:
63
- Exclude:
64
- - lib/solidus_braintree/request_protection.rb
65
-
66
- Rails/SkipsModelValidations:
67
- Exclude:
68
- - db/migrate/**/*
69
-
70
- Rails/ReflectionClassName:
71
- Exclude:
72
- - app/models/solidus_braintree/customer.rb
73
- - app/models/solidus_braintree/source.rb
74
-
75
- RSpec/MultipleMemoizedHelpers:
76
- Exclude:
77
- - spec/models/solidus_braintree/transaction_import_spec.rb
78
- - spec/models/solidus_braintree/response_spec.rb
79
- - spec/models/solidus_braintree/gateway_spec.rb
80
- - spec/controllers/solidus_braintree/client_tokens_controller_spec.rb
81
- - spec/system/frontend/braintree_credit_card_checkout_spec.rb
82
- - spec/system/frontend/paypal_checkout_spec.rb
83
-
84
- Rails/ApplicationRecord:
85
- Exclude:
86
- - db/migrate/*
6
+ AllCops:
7
+ TargetRubyVersion: 3.1
data/.standard.yml ADDED
@@ -0,0 +1,6 @@
1
+ parallel: true
2
+ format: progress
3
+ ruby_version: 3.1
4
+ ignore:
5
+ - "spec/dummy/**/*"
6
+ - "dummy-app/**/*"
data/7.2 ADDED
File without changes
data/Gemfile CHANGED
@@ -1,33 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- source 'https://rubygems.org'
3
+ source "https://rubygems.org"
4
4
  git_source(:github) { |repo| "https://github.com/#{repo}.git" }
5
5
 
6
- branch = ENV.fetch('SOLIDUS_BRANCH', 'main')
7
- gem 'solidus', github: 'solidusio/solidus', branch: branch
6
+ branch = ENV.fetch("SOLIDUS_BRANCH", "main")
7
+ gem "solidus", github: "solidusio/solidus", branch: branch
8
8
 
9
- # Needed to help Bundler figure out how to resolve dependencies,
10
- # otherwise it takes forever to resolve them.
11
- # See https://github.com/bundler/bundler/issues/6677
12
- gem 'rails', '>0.a'
9
+ gem "rails", "~> #{ENV.fetch("RAILS_VERSION", "8.1")}"
13
10
 
14
11
  # Provides basic authentication functionality for testing parts of your engine
15
- gem 'solidus_auth_devise'
12
+ gem "solidus_auth_devise"
16
13
 
17
- case ENV.fetch('DB', nil)
18
- when 'mysql'
19
- gem 'mysql2'
20
- when 'postgresql'
21
- gem 'pg'
14
+ case ENV.fetch("DB", nil)
15
+ when "mysql"
16
+ gem "mysql2"
17
+ when "postgresql"
18
+ gem "pg"
22
19
  else
23
- gem 'sqlite3'
20
+ gem "sqlite3"
24
21
  end
25
22
 
26
- # While we still support Ruby < 3 we need to workaround a limitation in
27
- # the 'async' gem that relies on the latest ruby, since RubyGems doesn't
28
- # resolve gems based on the required ruby version.
29
- gem 'async', '< 3' if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3')
30
-
31
23
  gemspec
32
24
 
33
25
  # Use a local Gemfile to include development dependencies that might not be
@@ -35,4 +27,4 @@ gemspec
35
27
  #
36
28
  # We use `send` instead of calling `eval_gemfile` to work around an issue with
37
29
  # how Dependabot parses projects: https://github.com/dependabot/dependabot-core/issues/1658.
38
- send(:eval_gemfile, 'Gemfile-local') if File.exist? 'Gemfile-local'
30
+ send(:eval_gemfile, "Gemfile-local") if File.exist? "Gemfile-local"
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # SolidusBraintree
2
2
 
3
- [![CircleCI](https://circleci.com/gh/solidusio/solidus_braintree.svg?style=shield)](https://circleci.com/gh/solidusio/solidus_braintree)
3
+ [![Test](https://github.com/solidusio/solidus_braintree/actions/workflows/test.yml/badge.svg)](https://github.com/solidusio/solidus_braintree/actions/workflows/test.yml)
4
4
  [![codecov](https://codecov.io/gh/solidusio/solidus_braintree/branch/main/graph/badge.svg)](https://codecov.io/gh/solidusio/solidus_braintree)
5
5
 
6
6
  `solidus_braintree` is an extension that adds support for using [Braintree](https://www.braintreepayments.com) as a payment source in your [Solidus](https://solidus.io/) store. It uses Braintree's [JavaScript v3 SDK](https://braintree.github.io/braintree-web/current/) to support the following Braintree payment method types:
@@ -365,16 +365,18 @@ default configuration that gets created by overriding the private
365
365
 
366
366
  ## Testing
367
367
 
368
- To run the specs it is required to set the Braintree test account data in these environment variables:
369
- `BRAINTREE_PUBLIC_KEY`, `BRAINTREE_PRIVATE_KEY`, `BRAINTREE_MERCHANT_ID` and `BRAINTREE_PAYPAL_PAYEE_EMAIL`
370
-
371
- First bundle your dependencies, then run `rake`. `rake` will default to building the dummy app if it does not exist, then it will run specs, and [Rubocop](https://github.com/bbatsov/rubocop) static code analysis. The dummy app can be regenerated by using `rake test_app`.
368
+ The specs run inside a Rails app with the storefront installed, which `bin/dummy-app` generates into `dummy-app/`. First bundle your dependencies, then run `rake`. It builds the dummy app if it does not exist yet and runs the specs inside it. `SOLIDUS_BRANCH`, `RAILS_VERSION` and `DB` (`sqlite`, `mysql` or `postgresql`) select the versions to test against, and `rake clobber` removes the dummy app so that it is rebuilt from scratch.
372
369
 
373
370
  ```shell
374
371
  bundle
375
372
  bundle exec rake
373
+ bundle exec standardrb
376
374
  ```
377
375
 
376
+ Specs that use the Braintree JavaScript SDK in the browser need a Braintree sandbox account and are skipped unless `BRAINTREE_PUBLIC_KEY`, `BRAINTREE_PRIVATE_KEY` and `BRAINTREE_MERCHANT_ID` are set. The sandbox account needs a linked PayPal sandbox account, because PayPal Checkout does not work with Braintree's mocked PayPal flow. The Venmo specs additionally need Venmo to be enabled for the sandbox account and only run when `BRAINTREE_VENMO_ENABLED` is set. `BRAINTREE_PAYPAL_PAYEE_EMAIL` optionally sets the PayPal payee email used for EUR payments.
377
+
378
+ When re-recording VCR cassettes, disable duplicate transaction checking for the sandbox account, as several specs charge the same amount to the same test card.
379
+
378
380
  When testing your applications integration with this extension you may use it's factories.
379
381
  Simply add this require statement to your spec_helper:
380
382
 
data/Rakefile CHANGED
@@ -1,15 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bundler/gem_tasks'
4
- require 'solidus_dev_support/rake_tasks'
5
- SolidusDevSupport::RakeTasks.install
3
+ require "bundler/gem_tasks"
4
+ require "solidus_dev_support/rake_tasks"
5
+ SolidusDevSupport::RakeTasks.install(user_class: "Spree::User")
6
6
 
7
7
  task :default do
8
- require 'bundler'
8
+ require "bundler"
9
9
  Bundler.with_unbundled_env do
10
- sh 'bin/rspec'
10
+ sh "bin/rspec"
11
11
  end
12
12
  end
13
13
 
14
- CLOBBER.include('dummy-app')
15
- CLOBBER.include('sandbox')
14
+ CLOBBER.include("dummy-app")
15
+ CLOBBER.include("sandbox")
@@ -4,7 +4,7 @@ module SolidusBraintree
4
4
  module BraintreeAdminHelper
5
5
  # Returns a link to the Braintree web UI for the given Braintree payment
6
6
  def braintree_transaction_link(payment)
7
- environment = payment.payment_method.preferred_environment == 'sandbox' ? 'sandbox' : 'www'
7
+ environment = (payment.payment_method.preferred_environment == "sandbox") ? "sandbox" : "www"
8
8
  merchant_id = payment.payment_method.preferred_merchant_id
9
9
  response_code = payment.response_code
10
10
 
@@ -14,9 +14,9 @@ module SolidusBraintree
14
14
  link_to(
15
15
  response_code,
16
16
  "https://#{environment}.braintreegateway.com/merchants/#{merchant_id}/transactions/#{response_code}",
17
- title: 'Show payment on Braintree',
18
- target: '_blank',
19
- rel: 'noopener'
17
+ title: "Show payment on Braintree",
18
+ target: "_blank",
19
+ rel: "noopener"
20
20
  )
21
21
  end
22
22
  end
@@ -1,50 +1,50 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_merchant/billing/avs_result'
3
+ require "active_merchant/billing/avs_result"
4
4
 
5
5
  module SolidusBraintree
6
6
  class AVSResult < ActiveMerchant::Billing::AVSResult
7
7
  # Mapping took from ActiveMerchant::Billing::BraintreeBlueGateway
8
8
  AVS_MAPPING = {
9
- 'M' => {
10
- 'M' => 'M',
11
- 'N' => 'A',
12
- 'U' => 'B',
13
- 'I' => 'B',
14
- 'A' => 'B'
9
+ "M" => {
10
+ "M" => "M",
11
+ "N" => "A",
12
+ "U" => "B",
13
+ "I" => "B",
14
+ "A" => "B"
15
15
  },
16
- 'N' => {
17
- 'M' => 'Z',
18
- 'N' => 'C',
19
- 'U' => 'C',
20
- 'I' => 'C',
21
- 'A' => 'C'
16
+ "N" => {
17
+ "M" => "Z",
18
+ "N" => "C",
19
+ "U" => "C",
20
+ "I" => "C",
21
+ "A" => "C"
22
22
  },
23
- 'U' => {
24
- 'M' => 'P',
25
- 'N' => 'N',
26
- 'U' => 'I',
27
- 'I' => 'I',
28
- 'A' => 'I'
23
+ "U" => {
24
+ "M" => "P",
25
+ "N" => "N",
26
+ "U" => "I",
27
+ "I" => "I",
28
+ "A" => "I"
29
29
  },
30
- 'I' => {
31
- 'M' => 'P',
32
- 'N' => 'C',
33
- 'U' => 'I',
34
- 'I' => 'I',
35
- 'A' => 'I'
30
+ "I" => {
31
+ "M" => "P",
32
+ "N" => "C",
33
+ "U" => "I",
34
+ "I" => "I",
35
+ "A" => "I"
36
36
  },
37
- 'A' => {
38
- 'M' => 'P',
39
- 'N' => 'C',
40
- 'U' => 'I',
41
- 'I' => 'I',
42
- 'A' => 'I'
37
+ "A" => {
38
+ "M" => "P",
39
+ "N" => "C",
40
+ "U" => "I",
41
+ "I" => "I",
42
+ "A" => "I"
43
43
  },
44
- 'B' => {
45
- 'B' => 'B'
44
+ "B" => {
45
+ "B" => "B"
46
46
  },
47
- nil => { nil => nil }
47
+ nil => {nil => nil}
48
48
  }.freeze
49
49
 
50
50
  class << self
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusBraintree
4
+ def self.table_name_prefix
5
+ "solidus_paypal_braintree_"
6
+ end
7
+
8
+ class BaseRecord < ::Spree::Base
9
+ self.abstract_class = true
10
+ end
11
+ end
@@ -1,32 +1,32 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusBraintree
4
- class Configuration < ::Spree::Base
4
+ class Configuration < BaseRecord
5
5
  PAYPAL_BUTTON_PREFERENCES = {
6
- color: { availables: %w[gold blue silver white black], default: 'white' },
7
- shape: { availables: %w[pill rect], default: 'rect' },
8
- label: { availables: %w[checkout credit pay buynow paypal installment], default: 'checkout' },
9
- tagline: { availables: %w[true false], default: 'false' },
10
- layout: { availables: %w[horizontal vertical], default: 'horizontal' },
11
- messaging: { availables: %w[true false], default: 'false' }
6
+ color: {availables: %w[gold blue silver white black], default: "white"},
7
+ shape: {availables: %w[pill rect], default: "rect"},
8
+ label: {availables: %w[checkout credit pay buynow paypal installment], default: "checkout"},
9
+ tagline: {availables: %w[true false], default: "false"},
10
+ layout: {availables: %w[horizontal vertical], default: "horizontal"},
11
+ messaging: {availables: %w[true false], default: "false"}
12
12
  }.freeze
13
13
 
14
14
  include ::Spree::Preferences::Persistable
15
15
 
16
- belongs_to :store, class_name: 'Spree::Store', optional: false
16
+ belongs_to :store, class_name: "Spree::Store", optional: false
17
17
 
18
18
  # Preferences for Paypal button
19
19
  PAYPAL_BUTTON_PREFERENCES.each do |name, desc|
20
- preference_name = "paypal_button_#{name}".to_sym
21
- attribute_name = "preferred_#{preference_name}".to_sym
20
+ preference_name = :"paypal_button_#{name}"
21
+ attribute_name = :"preferred_#{preference_name}"
22
22
 
23
23
  preference preference_name, :string, default: desc[:default]
24
24
 
25
25
  validates attribute_name, inclusion: desc[:availables]
26
26
  end
27
27
 
28
- preference :venmo_button_color, :preference_select, default: 'blue'
29
- preference :venmo_button_width, :preference_select, default: '320'
28
+ preference :venmo_button_color, :preference_select, default: "blue"
29
+ preference :venmo_button_width, :preference_select, default: "320"
30
30
 
31
31
  def preferred_venmo_button_color_options
32
32
  [["Blue", "blue"], ["White", "white"]]
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusBraintree
4
- class Customer < ApplicationRecord
4
+ class Customer < BaseRecord
5
5
  belongs_to :user, class_name: ::Spree::UserClassHandle.new, optional: true
6
6
  has_many :sources, class_name: "SolidusBraintree::Source", inverse_of: :customer, dependent: :destroy
7
7
  end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'braintree'
4
- require 'solidus_braintree/request_protection'
3
+ require "solidus_braintree/request_protection"
5
4
 
6
5
  module SolidusBraintree
7
6
  class Gateway < ::Spree::PaymentMethod
@@ -12,9 +11,9 @@ module SolidusBraintree
12
11
  # Error message from Braintree that gets returned by a non voidable transaction
13
12
  NON_VOIDABLE_STATUS_ERROR_REGEXP = /can only be voided if status is authorized/
14
13
 
15
- TOKEN_GENERATION_DISABLED_MESSAGE = 'Token generation is disabled. ' \
16
- 'To re-enable set the `token_generation_enabled` preference on the ' \
17
- 'gateway to `true`.'
14
+ TOKEN_GENERATION_DISABLED_MESSAGE = "Token generation is disabled. " \
15
+ "To re-enable set the `token_generation_enabled` preference on the " \
16
+ "gateway to `true`."
18
17
 
19
18
  ALLOWED_BRAINTREE_OPTIONS = [
20
19
  :device_data,
@@ -36,9 +35,9 @@ module SolidusBraintree
36
35
  preference(:token_generation_enabled, :boolean, default: true)
37
36
 
38
37
  # Preferences for configuration of Braintree credentials
39
- preference(:environment, :string, default: 'sandbox')
38
+ preference(:environment, :string, default: "sandbox")
40
39
  preference(:merchant_id, :string, default: nil)
41
- preference(:public_key, :string, default: nil)
40
+ preference(:public_key, :string, default: nil)
42
41
  preference(:private_key, :string, default: nil)
43
42
  preference(:http_open_timeout, :integer, default: 60)
44
43
  preference(:http_read_timeout, :integer, default: 60)
@@ -46,7 +45,7 @@ module SolidusBraintree
46
45
  preference(:paypal_payee_email_map, :hash, default: {})
47
46
 
48
47
  # Which checkout flow to use (vault/checkout)
49
- preference(:paypal_flow, :string, default: 'vault')
48
+ preference(:paypal_flow, :string, default: "vault")
50
49
 
51
50
  # A hash that gets passed to the `style` key when initializing the credit card fields.
52
51
  # See https://developers.braintreepayments.com/guides/hosted-fields/styling/javascript/v3
@@ -302,7 +301,7 @@ module SolidusBraintree
302
301
  # Whether to store this payment method in the PayPal Vault. This only works when the checkout
303
302
  # flow is "vault", so make sure to call +super+ if you override it.
304
303
  def store_in_vault
305
- preferred_paypal_flow == 'vault'
304
+ preferred_paypal_flow == "vault"
306
305
  end
307
306
 
308
307
  def logger
@@ -335,26 +334,24 @@ module SolidusBraintree
335
334
  end
336
335
 
337
336
  def transaction_options(source, options, submit_for_settlement: false)
338
- params = options.select do |key, _|
339
- ALLOWED_BRAINTREE_OPTIONS.include?(key)
340
- end
337
+ params = options.slice(*ALLOWED_BRAINTREE_OPTIONS)
341
338
 
342
339
  params[:channel] = "Solidus"
343
- params[:options] = { store_in_vault_on_success: store_in_vault }
340
+ params[:options] = {store_in_vault_on_success: store_in_vault}
344
341
 
345
342
  if submit_for_settlement
346
343
  params[:options][:submit_for_settlement] = true
347
344
  end
348
345
 
349
- if paypal_email = paypal_payee_email_for(source, options)
350
- params[:options][:paypal] = { payee_email: paypal_email }
346
+ if (paypal_email = paypal_payee_email_for(source, options))
347
+ params[:options][:paypal] = {payee_email: paypal_email}
351
348
  end
352
349
 
353
350
  if source.venmo? && venmo_business_profile_id
354
- params[:options][:venmo] = { profile_id: venmo_business_profile_id }
351
+ params[:options][:venmo] = {profile_id: venmo_business_profile_id}
355
352
  end
356
353
 
357
- if merchant_account_id = merchant_account_for(source, options)
354
+ if (merchant_account_id = merchant_account_for(source, options))
358
355
  params[:merchant_account_id] = merchant_account_id
359
356
  end
360
357
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_merchant/billing/response'
4
- require_relative 'avs_result'
3
+ require "active_merchant/billing/response"
4
+ require_relative "avs_result"
5
5
 
6
6
  # Response object that all actions on the gateway should return
7
7
  module SolidusBraintree
@@ -57,21 +57,21 @@ module SolidusBraintree
57
57
  # Human readable error message for transaction responses
58
58
  def transaction_error_message(transaction)
59
59
  case transaction.status
60
- when 'gateway_rejected'
60
+ when "gateway_rejected"
61
61
  I18n.t(transaction.gateway_rejection_reason,
62
- scope: 'solidus_braintree.gateway_rejection_reasons',
62
+ scope: "solidus_braintree.gateway_rejection_reasons",
63
63
  default: "#{transaction.status.humanize} #{transaction.gateway_rejection_reason.humanize}")
64
- when 'processor_declined'
64
+ when "processor_declined"
65
65
  I18n.t(transaction.processor_response_code,
66
- scope: 'solidus_braintree.processor_response_codes',
66
+ scope: "solidus_braintree.processor_response_codes",
67
67
  default: "#{transaction.processor_response_text} (#{transaction.processor_response_code})")
68
- when 'settlement_declined'
68
+ when "settlement_declined"
69
69
  I18n.t(transaction.processor_settlement_response_code,
70
- scope: 'solidus_braintree.processor_settlement_response_codes',
70
+ scope: "solidus_braintree.processor_settlement_response_codes",
71
71
  default: "#{transaction.processor_settlement_response_text} (#{transaction.processor_settlement_response_code})") # rubocop:disable Layout/LineLength
72
72
  else
73
73
  I18n.t(transaction.status,
74
- scope: 'solidus_braintree.transaction_statuses',
74
+ scope: "solidus_braintree.transaction_statuses",
75
75
  default: transaction.status.humanize)
76
76
  end
77
77
  end