solidus_braintree 2.0.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +39 -8
  3. data/.gitignore +1 -0
  4. data/.rubocop.yml +8 -1
  5. data/CHANGELOG.md +37 -29
  6. data/Rakefile +6 -1
  7. data/app/assets/config/solidus_braintree_manifest.js +0 -1
  8. data/app/assets/javascripts/spree/backend/solidus_braintree.js +4 -4
  9. data/app/models/solidus_braintree/gateway.rb +4 -0
  10. data/app/models/solidus_braintree/response.rb +1 -1
  11. data/app/models/solidus_braintree/source.rb +5 -0
  12. data/bin/dummy-app +37 -0
  13. data/bin/rails-dummy-app +17 -0
  14. data/bin/rspec +11 -0
  15. data/bin/sandbox +20 -62
  16. data/db/migrate/20230210104310_add_device_data_to_braintree_sources.rb +5 -0
  17. data/lib/generators/solidus_braintree/install/install_generator.rb +134 -34
  18. data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/javascripts/spree/frontend/paypal_button.js +1 -1
  19. data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/ajax.js +13 -0
  20. data/{app/assets/javascripts → lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend}/solidus_braintree/apple_pay_button.js +2 -2
  21. data/{app/assets/javascripts → lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend}/solidus_braintree/checkout.js +10 -5
  22. data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/client.js +239 -0
  23. data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/constants.js +89 -0
  24. data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/frontend.js +15 -0
  25. data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/hosted_form.js +48 -0
  26. data/{app/assets/javascripts → lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend}/solidus_braintree/paypal_button.js +2 -2
  27. data/{app/assets/javascripts → lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend}/solidus_braintree/paypal_messaging.js +1 -1
  28. data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/promise.js +20 -0
  29. data/{app/assets/javascripts → lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend}/solidus_braintree/venmo_button.js +1 -1
  30. data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree.js +1 -0
  31. data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/stylesheets/spree/frontend/solidus_braintree.scss +11 -0
  32. data/lib/{controllers/frontend → generators/solidus_braintree/install/templates/app/controllers}/solidus_braintree/checkouts_controller.rb +1 -1
  33. data/lib/{controllers/frontend → generators/solidus_braintree/install/templates/app/controllers}/solidus_braintree/transactions_controller.rb +3 -3
  34. data/lib/generators/solidus_braintree/install/templates/app/views/checkouts/existing_payment/_braintree.html.erb +2 -0
  35. data/lib/{views/frontend/spree/checkout → generators/solidus_braintree/install/templates/app/views/checkouts}/payment/_braintree.html.erb +1 -1
  36. 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
  37. data/{app → lib/generators/solidus_braintree/install/templates/app}/views/spree/shared/_apple_pay_button.html.erb +1 -1
  38. data/{app → lib/generators/solidus_braintree/install/templates/app}/views/spree/shared/_braintree_head_scripts.html.erb +1 -1
  39. data/{app → lib/generators/solidus_braintree/install/templates/app}/views/spree/shared/_braintree_hosted_fields.html.erb +1 -4
  40. data/lib/solidus_braintree/engine.rb +15 -10
  41. data/lib/solidus_braintree/version.rb +1 -1
  42. data/solidus_braintree.gemspec +3 -5
  43. data/spec/controllers/solidus_braintree/checkouts_controller_spec.rb +2 -2
  44. data/spec/controllers/solidus_braintree/client_tokens_controller_spec.rb +2 -2
  45. data/spec/controllers/solidus_braintree/configurations_controller_spec.rb +2 -2
  46. data/spec/controllers/solidus_braintree/transactions_controller_spec.rb +3 -3
  47. data/spec/fixtures/views/carts/_cart_footer.html.erb +18 -0
  48. data/spec/helpers/solidus_braintree/braintree_admin_helper_spec.rb +1 -1
  49. data/spec/helpers/solidus_braintree/braintree_checkout_helper_spec.rb +1 -1
  50. data/spec/models/solidus_braintree/address_spec.rb +1 -1
  51. data/spec/models/solidus_braintree/avs_result_spec.rb +1 -1
  52. data/spec/models/solidus_braintree/gateway_spec.rb +35 -3
  53. data/spec/models/solidus_braintree/response_spec.rb +1 -1
  54. data/spec/models/solidus_braintree/source_spec.rb +17 -1
  55. data/spec/models/solidus_braintree/transaction_address_spec.rb +2 -2
  56. data/spec/models/solidus_braintree/transaction_import_spec.rb +2 -2
  57. data/spec/models/solidus_braintree/transaction_spec.rb +2 -2
  58. data/spec/models/spree/store_spec.rb +2 -2
  59. data/spec/requests/spree/api/orders_controller_spec.rb +2 -2
  60. data/spec/solidus_braintree_helper.rb +7 -0
  61. data/{lib/solidus_braintree/testing_support → spec/support/solidus_braintree}/factories.rb +17 -15
  62. data/spec/support/{order_ready_for_payment.rb → solidus_braintree/order_ready_for_payment.rb} +9 -2
  63. data/spec/support/solidus_braintree/order_walkthrough.rb +87 -0
  64. data/spec/support/solidus_braintree/with_prepended_view_fixtures.rb +19 -0
  65. data/spec/{features → system}/backend/configuration_spec.rb +2 -2
  66. data/spec/{features → system}/backend/new_payment_spec.rb +3 -4
  67. data/spec/{features → system}/frontend/braintree_credit_card_checkout_spec.rb +23 -15
  68. data/spec/{features → system}/frontend/paypal_checkout_spec.rb +6 -3
  69. data/spec/{features → system}/frontend/venmo_checkout_spec.rb +8 -9
  70. metadata +88 -107
  71. data/app/assets/javascripts/solidus_braintree/frontend.js +0 -14
  72. data/app/assets/javascripts/spree/frontend/solidus_braintree.js +0 -1
  73. data/app/decorators/controllers/solidus_braintree/checkout_controller_decorator.rb +0 -11
  74. data/app/decorators/controllers/solidus_braintree/orders_controller_decorator.rb +0 -11
  75. data/app/overrides/spree/payments/payment/add_paypal_funding_source_to_payment.rb +0 -9
  76. data/app/views/spree/checkout/existing_payment/_braintree.html.erb +0 -10
  77. data/spec/fixtures/views/spree/orders/edit.html.erb +0 -50
  78. data/spec/spec_helper.rb +0 -32
  79. data/spec/support/views.rb +0 -1
  80. /data/app/assets/javascripts/{solidus_braintree → spree/backend/solidus_braintree}/client.js +0 -0
  81. /data/app/assets/javascripts/{solidus_braintree → spree/backend/solidus_braintree}/constants.js +0 -0
  82. /data/app/assets/javascripts/{solidus_braintree → spree/backend/solidus_braintree}/hosted_form.js +0 -0
  83. /data/app/assets/javascripts/{solidus_braintree → spree/backend/solidus_braintree}/promise.js +0 -0
  84. /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_active_blue_button_280x48.svg +0 -0
  85. /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_active_blue_button_320x48.svg +0 -0
  86. /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_active_blue_button_375x48.svg +0 -0
  87. /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_active_white_button_280x48.svg +0 -0
  88. /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_active_white_button_320x48.svg +0 -0
  89. /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_active_white_button_375x48.svg +0 -0
  90. /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_blue_acceptance_mark.svg +0 -0
  91. /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_blue_button_280x48.svg +0 -0
  92. /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_blue_button_320x48.svg +0 -0
  93. /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_blue_button_375x48.svg +0 -0
  94. /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_blue_logo.svg +0 -0
  95. /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_white_acceptance_mark.svg +0 -0
  96. /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_white_button_280x48.svg +0 -0
  97. /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_white_button_320x48.svg +0 -0
  98. /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_white_button_375x48.svg +0 -0
  99. /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_white_logo.svg +0 -0
  100. /data/{app → lib/generators/solidus_braintree/install/templates/app}/helpers/solidus_braintree/braintree_checkout_helper.rb +0 -0
  101. /data/{app → lib/generators/solidus_braintree/install/templates/app}/views/spree/shared/_braintree_errors.html.erb +0 -0
  102. /data/{app → lib/generators/solidus_braintree/install/templates/app}/views/spree/shared/_paypal_cart_button.html.erb +0 -0
  103. /data/lib/{views/frontend → generators/solidus_braintree/install/templates/app/views}/spree/shared/_paypal_checkout_button.html.erb +0 -0
  104. /data/{app → lib/generators/solidus_braintree/install/templates/app}/views/spree/shared/_paypal_messaging.html.erb +0 -0
  105. /data/{app → lib/generators/solidus_braintree/install/templates/app}/views/spree/shared/_venmo_button.html.erb +0 -0
  106. /data/lib/generators/solidus_braintree/install/templates/{initializer.rb → config/initializers/solidus_braintree.rb} +0 -0
  107. /data/spec/support/{capybara.rb → solidus_braintree/capybara.rb} +0 -0
  108. /data/spec/support/{gateway_helpers.rb → solidus_braintree/gateway_helpers.rb} +0 -0
  109. /data/spec/support/{vcr.rb → solidus_braintree/vcr.rb} +0 -0
@@ -1,4 +1,4 @@
1
- //= require solidus_braintree/constants
1
+ //= require spree/frontend/solidus_braintree/constants
2
2
  /**
3
3
  * Constructor for PayPal button object
4
4
  * @constructor
@@ -99,7 +99,7 @@ SolidusBraintree.PaypalButton.prototype._tokenizeCallback = function(tokenizeErr
99
99
 
100
100
  var params = this._transactionParams(payload);
101
101
 
102
- return Spree.ajax({
102
+ return SolidusBraintree.ajax({
103
103
  url: SolidusBraintree.config.paths.transactions,
104
104
  type: 'POST',
105
105
  dataType: 'json',
@@ -1,4 +1,4 @@
1
- //= require solidus_braintree/constants
1
+ //= require spree/frontend/solidus_braintree/constants
2
2
 
3
3
  SolidusBraintree.PaypalMessaging = function(paypalOptions) {
4
4
  this._paypalOptions = paypalOptions || {};
@@ -0,0 +1,20 @@
1
+ SolidusBraintree.PromiseShim = {
2
+ convertBraintreePromise: function(fn, args, context) {
3
+ var jqPromise = $.Deferred();
4
+
5
+ args = args || [];
6
+ context = context || this;
7
+
8
+ args = args.concat(function(error, data) {
9
+ if (error) {
10
+ jqPromise.reject(error);
11
+ } else {
12
+ jqPromise.resolve(data);
13
+ }
14
+ });
15
+
16
+ fn.apply(context, args);
17
+
18
+ return jqPromise.promise();
19
+ }
20
+ }
@@ -1,4 +1,4 @@
1
- //= require solidus_braintree/constants
1
+ //= require spree/frontend/solidus_braintree/constants
2
2
  /**
3
3
  * Constructor for Venmo button object
4
4
  * @constructor
@@ -0,0 +1 @@
1
+ //= require spree/frontend/solidus_braintree/frontend
@@ -49,3 +49,14 @@ the installer will append this file to the app vendored assets here: 'vendor/ass
49
49
  .venmo-button.visible {
50
50
  visibility: visible;
51
51
  }
52
+
53
+ /*
54
+ WORKAROUND: Do not allow buttons in disabled payment-step to be clickable. Note
55
+ that it's still possible to trigger the PayPal button iframe by tabbing to it
56
+ and hitting enter.
57
+ */
58
+ fieldset.payment-step__details:disabled {
59
+ #apple-pay-button, #paypal-button iframe, #venmo-button {
60
+ pointer-events: none;
61
+ }
62
+ }
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusBraintree
4
- class CheckoutsController < ::Spree::CheckoutController
4
+ class CheckoutsController < CheckoutsController
5
5
  PERMITTED_PAYMENT_PARAMS = [
6
6
  :payment_method_id,
7
7
  { source_attributes: [
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusBraintree
4
- class TransactionsController < ::Spree::StoreController
4
+ class TransactionsController < StoreController
5
5
  class InvalidImportError < StandardError; end
6
6
 
7
7
  PERMITTED_BRAINTREE_TRANSACTION_PARAMS = [
@@ -48,9 +48,9 @@ module SolidusBraintree
48
48
 
49
49
  def redirect_url(import)
50
50
  if import.order.complete?
51
- spree.order_url(import.order)
51
+ main_app.order_url(import.order)
52
52
  else
53
- spree.checkout_state_url(import.order.state)
53
+ main_app.checkout_state_url(import.order.state)
54
54
  end
55
55
  end
56
56
 
@@ -0,0 +1,2 @@
1
+ <%= wallet_payment_source.payment_source.friendly_payment_type %>
2
+ <%= wallet_payment_source.payment_source.display_number %>
@@ -7,7 +7,7 @@
7
7
  <% end %>
8
8
 
9
9
  <% if current_store.braintree_configuration.credit_card? %>
10
- <fieldset class="braintree-hosted-fields" data-braintree-hosted-fields data-id="<%= id %>">
10
+ <fieldset class="braintree-hosted-fields" data-braintree-hosted-fields data-id="<%= id %>" data-use-data-collector="<%= SolidusBraintree::Gateway.first.preferred_use_data_collector %>">
11
11
  <%= render "spree/shared/braintree_hosted_fields", payment_method: payment_method %>
12
12
  </fieldset>
13
13
  <% end %>
@@ -1,12 +1,9 @@
1
- <br />
2
1
  <%= payment.source.try(:display_payment_type) %>
3
2
 
4
3
  <% if payment.source.try(:paypal?) %>
5
4
  <% if payment.source.respond_to?(:paypal_funding_source) && payment.source.paypal_funding_source.present? %>
6
- <br />
7
5
  <%= t('spree.paypal_funding', funding: payment.source.display_paypal_funding_source) %>
8
6
  <% end %>
9
7
  <% elsif payment.source.try(:venmo?) %>
10
- <br />
11
8
  <%= payment.source.source_description %>
12
9
  <% end %>
@@ -1,4 +1,4 @@
1
- <% address = current_order.ship_address %>
1
+ <% address = SolidusBraintree::Address.new(current_order.ship_address) %>
2
2
 
3
3
  <button id="apple-pay-button" class="apple-pay-button"></button>
4
4
 
@@ -22,5 +22,5 @@
22
22
  <script src="https://js.braintreegateway.com/web/3.84.0/js/venmo.min.js"></script>
23
23
  <% end %>
24
24
 
25
- <%= javascript_include_tag "solidus_braintree/checkout" %>
25
+ <%= javascript_include_tag "spree/frontend/solidus_braintree/checkout" %>
26
26
  <% end %>
@@ -22,15 +22,12 @@
22
22
  <div class="field" data-hook="card_code">
23
23
  <%= label_tag "card_code#{payment_method.id}", Spree::CreditCard.human_attribute_name(:card_code), class: "required" %>
24
24
  <div class="input" id="card_code<%= payment_method.id %>"></div>
25
-
26
- <a href="/content/cvv" class="info cvvLink" target="_blank">
27
- (<%= I18n.t("spree.what_is_this") %>)
28
- </a>
29
25
  </div>
30
26
 
31
27
  <div class="clear"></div>
32
28
  <input type="hidden" name="<%= prefix %>[payment_type]" value="<%= SolidusBraintree::Source::CREDIT_CARD %>">
33
29
  <input type="hidden" id="payment_method_nonce" name="<%= prefix %>[nonce]">
30
+ <input type="hidden" id="device_data" name="<%= prefix %>[device_data]">
34
31
  </div>
35
32
 
36
33
 
@@ -18,21 +18,26 @@ module SolidusBraintree
18
18
  config.to_prepare do
19
19
  app.config.spree.payment_methods << SolidusBraintree::Gateway
20
20
  SolidusBraintree::Gateway.allowed_admin_form_preference_types.push(:preference_select).uniq!
21
- ::Spree::PermittedAttributes.source_attributes.concat([:nonce, :payment_type, :paypal_funding_source]).uniq!
21
+
22
+ ::Spree::PermittedAttributes.source_attributes.concat(
23
+ [:nonce, :payment_type, :paypal_funding_source, :device_data]
24
+ ).uniq!
22
25
  end
23
26
  end
24
27
 
25
- if SolidusSupport.frontend_available?
26
- config.assets.precompile += [
27
- 'solidus_braintree/checkout.js',
28
- 'solidus_braintree/frontend.js',
29
- 'spree/frontend/apple_pay_button.js',
30
- 'solidus_braintree_manifest.js'
31
- ]
32
- paths["app/controllers"] << "lib/controllers/frontend"
33
- paths["app/views"] << "lib/views/frontend"
28
+ initializer 'add_solidus_braintree_response_to_log_entry_permitted_classes' do
29
+ Spree.config do |config|
30
+ config.log_entry_permitted_classes << 'SolidusBraintree::Response'
31
+ end
34
32
  end
35
33
 
34
+ config.assets.precompile += [
35
+ 'spree/frontend/solidus_braintree/checkout.js',
36
+ 'solidus_braintree_manifest.js'
37
+ ]
38
+ paths["app/controllers"] << "lib/controllers/frontend"
39
+ paths["app/views"] << "lib/views/frontend"
40
+
36
41
  if SolidusSupport.backend_available?
37
42
  config.assets.precompile += ["spree/backend/solidus_braintree.js"]
38
43
  paths["app/controllers"] << "lib/controllers/backend"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusBraintree
4
- VERSION = '2.0.0'
4
+ VERSION = '3.0.0'
5
5
  end
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.metadata['source_code_uri'] = 'https://github.com/solidusio/solidus_braintree'
18
18
  spec.metadata['changelog_uri'] = 'https://github.com/solidusio/solidus_braintree/blob/master/CHANGELOG.md'
19
19
 
20
- spec.required_ruby_version = Gem::Requirement.new('>= 2.5', '< 4')
20
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.7', '< 4')
21
21
 
22
22
  # Specify which files should be added to the gem when it is released.
23
23
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -31,14 +31,12 @@ Gem::Specification.new do |spec|
31
31
 
32
32
  spec.add_dependency 'activemerchant', '~> 1.48'
33
33
  spec.add_dependency 'braintree', '~> 3.4'
34
- spec.add_dependency 'solidus_api', ['>= 2.4.0', '< 4']
35
- spec.add_dependency 'solidus_core', ['>= 2.4.0', '< 4']
34
+ spec.add_dependency 'solidus_api', ['>= 3.4.0.dev', '< 4']
35
+ spec.add_dependency 'solidus_core', ['>= 3.4.0.dev', '< 4']
36
36
  spec.add_dependency 'solidus_support', ['>= 0.8.1', '< 1']
37
37
 
38
38
  spec.add_development_dependency 'rails-controller-testing'
39
39
  spec.add_development_dependency 'solidus_dev_support', '~> 2.5'
40
- spec.add_development_dependency 'vcr'
41
- spec.add_development_dependency 'webmock'
42
40
 
43
41
  spec.post_install_message = "If you're upgrading to v2.0.0, please see the README for upgrade instructions."
44
42
  end
@@ -1,5 +1,5 @@
1
- require 'spec_helper'
2
- require 'support/order_ready_for_payment'
1
+ require 'solidus_braintree_helper'
2
+ require 'support/solidus_braintree/order_ready_for_payment'
3
3
 
4
4
  RSpec.describe SolidusBraintree::CheckoutsController, type: :controller do
5
5
  routes { SolidusBraintree::Engine.routes }
@@ -1,6 +1,6 @@
1
- require 'spec_helper'
1
+ require 'solidus_braintree_helper'
2
2
 
3
- describe SolidusBraintree::ClientTokensController do
3
+ RSpec.describe SolidusBraintree::ClientTokensController do
4
4
  routes { SolidusBraintree::Engine.routes }
5
5
 
6
6
  cassette_options = { cassette_name: "braintree/token" }
@@ -1,6 +1,6 @@
1
- require 'spec_helper'
1
+ require 'solidus_braintree_helper'
2
2
 
3
- describe SolidusBraintree::ConfigurationsController, type: :controller do
3
+ RSpec.describe SolidusBraintree::ConfigurationsController, type: :controller do
4
4
  routes { SolidusBraintree::Engine.routes }
5
5
 
6
6
  let!(:store_1) { create :store }
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require 'solidus_braintree_helper'
2
2
 
3
3
  RSpec.describe SolidusBraintree::TransactionsController, type: :controller do
4
4
  routes { SolidusBraintree::Engine.routes }
@@ -130,7 +130,7 @@ RSpec.describe SolidusBraintree::TransactionsController, type: :controller do
130
130
  context "when format is HTML" do
131
131
  context "when import! leaves the order in confirm" do
132
132
  it "redirects the user to the confirm page" do
133
- expect(post_create).to redirect_to spree.checkout_state_path("confirm")
133
+ expect(post_create).to redirect_to '/checkout/confirm'
134
134
  end
135
135
  end
136
136
 
@@ -138,7 +138,7 @@ RSpec.describe SolidusBraintree::TransactionsController, type: :controller do
138
138
  before { allow(order).to receive(:complete?).and_return(true) }
139
139
 
140
140
  it "displays the order to the user" do
141
- expect(post_create).to redirect_to spree.order_path(order)
141
+ expect(post_create).to redirect_to "/orders/#{order.number}"
142
142
  end
143
143
  end
144
144
  end
@@ -0,0 +1,18 @@
1
+ <% order = order_form.object %>
2
+
3
+ <footer class="cart-footer">
4
+ <p class="cart-footer__total">
5
+ <%= t('spree.total') %>: <strong><%= order.display_total %></strong>
6
+ </p>
7
+
8
+ <div class="cart-footer__primary-action">
9
+ <%= order_form.button(
10
+ I18n.t('spree.checkout'),
11
+ class: 'button-primary',
12
+ id: 'checkout-link',
13
+ name: :checkout
14
+ ) %>
15
+ </div>
16
+
17
+ <%= render "spree/shared/paypal_cart_button" %>
18
+ </footer>
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require 'solidus_braintree_helper'
2
2
 
3
3
  RSpec.describe SolidusBraintree::BraintreeAdminHelper do
4
4
  describe '#braintree_transaction_link' do
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require 'solidus_braintree_helper'
2
2
 
3
3
  RSpec.describe SolidusBraintree::BraintreeCheckoutHelper do
4
4
  let!(:store) { create :store }
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require 'solidus_braintree_helper'
2
2
 
3
3
  RSpec.describe SolidusBraintree::Address do
4
4
  describe "::split_name" do
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require 'solidus_braintree_helper'
2
2
 
3
3
  RSpec.describe SolidusBraintree::AVSResult do
4
4
  describe 'AVS response message' do
@@ -1,6 +1,6 @@
1
- require 'spec_helper'
1
+ require 'solidus_braintree_helper'
2
2
  require 'webmock'
3
- require 'support/order_ready_for_payment'
3
+ require 'support/solidus_braintree/order_ready_for_payment'
4
4
 
5
5
  RSpec.describe SolidusBraintree::Gateway do
6
6
  let(:gateway) do
@@ -16,7 +16,8 @@ RSpec.describe SolidusBraintree::Gateway do
16
16
  nonce: 'fake-valid-nonce',
17
17
  user: user,
18
18
  payment_type: payment_type,
19
- payment_method: gateway
19
+ payment_method: gateway,
20
+ device_data: 'fake-device-data'
20
21
  )
21
22
  end
22
23
 
@@ -220,6 +221,37 @@ RSpec.describe SolidusBraintree::Gateway do
220
221
  expect(authorize.message).to eq 'authorized'
221
222
  expect(authorize.authorization).to be_present
222
223
  end
224
+
225
+ context 'with available device data' do
226
+ it 'passes the device data as a parameter in the request' do
227
+ expect_any_instance_of(Braintree::TransactionGateway).
228
+ to receive(:sale).
229
+ with(hash_including({ device_data: "fake-device-data" })).and_call_original
230
+ authorize
231
+ end
232
+ end
233
+
234
+ context 'without device_data' do
235
+ let(:source) do
236
+ SolidusBraintree::Source.create!(
237
+ nonce: 'fake-valid-nonce',
238
+ user: user,
239
+ payment_type: payment_type,
240
+ payment_method: gateway
241
+ )
242
+ end
243
+
244
+ before do
245
+ allow_any_instance_of(Braintree::TransactionGateway).to receive(:sale).and_call_original
246
+ end
247
+
248
+ it 'does not pass any device data in the request' do
249
+ expect_any_instance_of(Braintree::TransactionGateway)
250
+ .not_to receive(:sale).with(hash_including({ device_data: "" }))
251
+
252
+ authorize
253
+ end
254
+ end
223
255
  end
224
256
 
225
257
  context 'with different merchant account for currency', vcr: {
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require 'solidus_braintree_helper'
2
2
 
3
3
  RSpec.describe SolidusBraintree::Response do
4
4
  let(:failed_transaction) { nil }
@@ -1,4 +1,5 @@
1
- require 'spec_helper'
1
+ require 'solidus_braintree_helper'
2
+ require 'support/solidus_braintree/order_ready_for_payment'
2
3
 
3
4
  RSpec.describe SolidusBraintree::Source, type: :model do
4
5
  include_context 'when order is ready for payment'
@@ -536,4 +537,19 @@ RSpec.describe SolidusBraintree::Source, type: :model do
536
537
  it { is_expected.to be_falsy }
537
538
  end
538
539
  end
540
+
541
+ describe "#device_data" do
542
+ let(:payment_source) { build(:solidus_braintree_source) }
543
+
544
+ context "when blank on validation" do
545
+ before do
546
+ payment_source.device_data = ""
547
+ payment_source.valid?
548
+ end
549
+
550
+ it "is set to nil" do
551
+ expect(payment_source.device_data).to be_nil
552
+ end
553
+ end
554
+ end
539
555
  end
@@ -1,6 +1,6 @@
1
- require 'spec_helper'
1
+ require 'solidus_braintree_helper'
2
2
 
3
- describe SolidusBraintree::TransactionAddress do
3
+ RSpec.describe SolidusBraintree::TransactionAddress do
4
4
  describe "#valid?" do
5
5
  subject { address.valid? }
6
6
 
@@ -1,6 +1,6 @@
1
- require 'spec_helper'
1
+ require 'solidus_braintree_helper'
2
2
 
3
- describe SolidusBraintree::TransactionImport do
3
+ RSpec.describe SolidusBraintree::TransactionImport do
4
4
  let(:order) { Spree::Order.new }
5
5
  let!(:country) { create :country, iso: "US" }
6
6
  let(:braintree_gateway) { SolidusBraintree::Gateway.new }
@@ -1,6 +1,6 @@
1
- require 'spec_helper'
1
+ require 'solidus_braintree_helper'
2
2
 
3
- describe SolidusBraintree::Transaction do
3
+ RSpec.describe SolidusBraintree::Transaction do
4
4
  describe "#valid?" do
5
5
  subject { transaction.valid? }
6
6
 
@@ -1,6 +1,6 @@
1
- require 'spec_helper'
1
+ require 'solidus_braintree_helper'
2
2
 
3
- describe Spree::Store do
3
+ RSpec.describe Spree::Store do
4
4
  describe 'before_create :build_default_configuration' do
5
5
  context 'when a braintree_configuration record already exists' do
6
6
  it 'does not overwrite it' do
@@ -1,6 +1,6 @@
1
- require 'spec_helper'
1
+ require 'solidus_braintree_helper'
2
2
 
3
- describe Spree::Api::OrdersController, type: :request do
3
+ RSpec.describe Spree::Api::OrdersController, type: :request do
4
4
  stub_authorization!
5
5
 
6
6
  describe 'get show' do
@@ -0,0 +1,7 @@
1
+ require 'solidus_starter_frontend_helper'
2
+
3
+ require 'support/solidus_braintree/capybara'
4
+ require 'support/solidus_braintree/factories'
5
+ require 'support/solidus_braintree/gateway_helpers'
6
+ require 'support/solidus_braintree/order_walkthrough'
7
+ require 'support/solidus_braintree/vcr'
@@ -28,26 +28,28 @@ FactoryBot.define do
28
28
  payment_type { SolidusBraintree::Source::APPLE_PAY }
29
29
  end
30
30
  end
31
- end
32
31
 
33
- FactoryBot.modify do
34
- # The Solidus address factory randomizes the zipcode.
35
- # The OrderWalkThrough we use in the credit card checkout spec uses this factory for the user addresses.
36
- # For credit card payments we transmit the billing address to braintree, for paypal payments the shipping address.
37
- # As we match the body in our VCR settings VCR can not match the request anymore and therefore cannot replay existing
38
- # cassettes.
39
- #
32
+ factory :solidus_braintree_address, parent: :address do
33
+ trait :with_fixed_zipcode do
34
+ # The Solidus address factory randomizes the zipcode. The OrderWalkThrough
35
+ # we use in the credit card checkout spec uses this factory for the user
36
+ # addresses. For credit card payments we transmit the billing address to
37
+ # braintree, for paypal payments the shipping address. As we match the
38
+ # body in our VCR settings VCR can not match the request anymore and
39
+ # therefore cannot replay existing cassettes.
40
40
 
41
- factory :address do
42
- zipcode { '21088-0255' }
41
+ zipcode { '21088-0255' }
42
+ end
43
43
 
44
44
  if SolidusSupport.combined_first_and_last_name_in_address?
45
- transient do
46
- firstname { "John" }
47
- lastname { "Doe" }
48
- end
45
+ trait :with_first_and_last_name do
46
+ transient do
47
+ firstname { "John" }
48
+ lastname { "Doe" }
49
+ end
49
50
 
50
- name { "#{firstname} #{lastname}" }
51
+ name { "#{firstname} #{lastname}" }
52
+ end
51
53
  end
52
54
  end
53
55
  end
@@ -1,8 +1,15 @@
1
- shared_context 'when order is ready for payment' do
1
+ RSpec.shared_context 'when order is ready for payment' do
2
2
  let!(:country) { create :country }
3
3
 
4
4
  let(:user) { create :user }
5
- let(:address) { create :address, zipcode: "90210", lastname: "Doe", country: country }
5
+
6
+ let(:address) do
7
+ create :solidus_braintree_address,
8
+ :with_first_and_last_name,
9
+ zipcode: "90210",
10
+ lastname: "Doe",
11
+ country: country
12
+ end
6
13
 
7
14
  before do
8
15
  create :shipping_method, cost: 5
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusBraintree
4
+ class OrderWalkthrough
5
+ def self.up_to(state, user: nil)
6
+ new.up_to(state, user: user)
7
+ end
8
+
9
+ def up_to(state, user: nil)
10
+ # Need to create a valid zone too...
11
+ @zone = ::FactoryBot.create(:zone)
12
+ @country = ::FactoryBot.create(:country)
13
+ @state = ::FactoryBot.create(:state, country: @country)
14
+
15
+ @zone.members << ::Spree::ZoneMember.create(zoneable: @country)
16
+
17
+ # A shipping method must exist for rates to be displayed on checkout page
18
+ ::FactoryBot.create(:shipping_method, zones: [@zone]).tap do |sm|
19
+ sm.calculator.preferred_amount = 10
20
+ sm.calculator.preferred_currency = ::Spree::Config[:currency]
21
+ sm.calculator.save
22
+ end
23
+
24
+ order = ::Spree::Order.create!(
25
+ user: user,
26
+ email: "solidus@example.com",
27
+ store: ::Spree::Store.first || ::FactoryBot.create(:store)
28
+ )
29
+ add_line_item!(order)
30
+ order.next!
31
+
32
+ states_to_process = if state == :complete
33
+ states
34
+ else
35
+ end_state_position = states.index(state.to_sym)
36
+ states[..end_state_position]
37
+ end
38
+
39
+ states_to_process.each do |state_to_process|
40
+ send(state_to_process, order)
41
+ end
42
+
43
+ order
44
+ end
45
+
46
+ private
47
+
48
+ def add_line_item!(order)
49
+ ::FactoryBot.create(:line_item, order: order)
50
+ order.reload
51
+ end
52
+
53
+ def address(order)
54
+ order.bill_address =
55
+ ::FactoryBot.create(:solidus_braintree_address, :with_fixed_zipcode, country: @country, state: @state)
56
+
57
+ order.ship_address =
58
+ ::FactoryBot.create(:solidus_braintree_address, :with_fixed_zipcode, country: @country, state: @state)
59
+
60
+ order.next!
61
+ end
62
+
63
+ def delivery(order)
64
+ order.next!
65
+ end
66
+
67
+ def payment(order)
68
+ credit_card = ::FactoryBot.create(:credit_card, user: order.user)
69
+ order.payments.create!(payment_method: credit_card.payment_method, amount: order.total, source: credit_card)
70
+ # TODO: maybe look at some way of making this payment_state change automatic
71
+ order.payment_state = 'paid'
72
+ order.next!
73
+ end
74
+
75
+ def confirm(order)
76
+ order.complete!
77
+ end
78
+
79
+ def complete(order)
80
+ # noop?
81
+ end
82
+
83
+ def states
84
+ [:address, :delivery, :payment, :confirm]
85
+ end
86
+ end
87
+ end