solidus_paypal_braintree 0.2.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +40 -0
  3. data/.gem_release.yml +5 -0
  4. data/.github/stale.yml +17 -0
  5. data/.gitignore +18 -0
  6. data/.rspec +2 -0
  7. data/.rubocop.yml +76 -0
  8. data/CHANGELOG.md +258 -0
  9. data/Gemfile +41 -0
  10. data/LICENSE +2 -2
  11. data/README.md +208 -48
  12. data/Rakefile +4 -28
  13. data/app/assets/config/solidus_paypal_braintree_manifest.js +1 -0
  14. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_active_blue_button_280x48.svg +19 -0
  15. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_active_blue_button_320x48.svg +19 -0
  16. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_active_blue_button_375x48.svg +19 -0
  17. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_active_white_button_280x48.svg +19 -0
  18. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_active_white_button_320x48.svg +19 -0
  19. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_active_white_button_375x48.svg +19 -0
  20. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_blue_acceptance_mark.svg +15 -0
  21. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_blue_button_280x48.svg +19 -0
  22. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_blue_button_320x48.svg +19 -0
  23. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_blue_button_375x48.svg +19 -0
  24. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_blue_logo.svg +18 -0
  25. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_white_acceptance_mark.svg +20 -0
  26. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_white_button_280x48.svg +19 -0
  27. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_white_button_320x48.svg +19 -0
  28. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_white_button_375x48.svg +19 -0
  29. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_white_logo.svg +18 -0
  30. data/app/assets/javascripts/solidus_paypal_braintree/checkout.js +32 -3
  31. data/app/assets/javascripts/solidus_paypal_braintree/client.js +58 -5
  32. data/app/assets/javascripts/solidus_paypal_braintree/constants.js +36 -5
  33. data/app/assets/javascripts/solidus_paypal_braintree/frontend.js +2 -0
  34. data/app/assets/javascripts/solidus_paypal_braintree/hosted_form.js +15 -5
  35. data/app/assets/javascripts/solidus_paypal_braintree/paypal_button.js +90 -26
  36. data/app/assets/javascripts/solidus_paypal_braintree/paypal_messaging.js +22 -0
  37. data/app/assets/javascripts/solidus_paypal_braintree/venmo_button.js +86 -0
  38. data/app/assets/javascripts/spree/backend/solidus_paypal_braintree.js +2 -2
  39. data/app/assets/javascripts/spree/frontend/paypal_button.js +15 -13
  40. data/app/assets/stylesheets/spree/frontend/solidus_paypal_braintree.css +12 -0
  41. data/app/decorators/controllers/solidus_paypal_braintree/admin_payments_controller_decorator.rb +11 -0
  42. data/app/decorators/controllers/solidus_paypal_braintree/checkout_controller_decorator.rb +11 -0
  43. data/app/decorators/controllers/solidus_paypal_braintree/client_tokens_controller.rb +41 -0
  44. data/app/decorators/controllers/solidus_paypal_braintree/orders_controller_decorator.rb +11 -0
  45. data/app/decorators/models/solidus_paypal_braintree/spree/store_decorator.rb +20 -0
  46. data/app/decorators/models/solidus_paypal_braintree/spree/user_decorator.rb +13 -0
  47. data/app/helpers/solidus_paypal_braintree/braintree_admin_helper.rb +23 -0
  48. data/app/helpers/solidus_paypal_braintree/braintree_checkout_helper.rb +60 -0
  49. data/app/models/application_record.rb +2 -0
  50. data/app/models/solidus_paypal_braintree/address.rb +64 -0
  51. data/app/models/solidus_paypal_braintree/avs_result.rb +69 -0
  52. data/app/models/solidus_paypal_braintree/configuration.rb +39 -3
  53. data/app/models/solidus_paypal_braintree/customer.rb +7 -3
  54. data/app/models/solidus_paypal_braintree/gateway.rb +150 -43
  55. data/app/models/solidus_paypal_braintree/response.rb +49 -21
  56. data/app/models/solidus_paypal_braintree/source.rb +70 -10
  57. data/app/models/solidus_paypal_braintree/transaction.rb +3 -2
  58. data/app/models/solidus_paypal_braintree/transaction_address.rb +36 -15
  59. data/app/models/solidus_paypal_braintree/transaction_import.rb +18 -12
  60. data/app/overrides/spree/payments/payment/add_paypal_funding_source_to_payment.rb +9 -0
  61. data/app/views/spree/api/payments/source_views/_paypal_braintree.json.jbuilder +3 -0
  62. data/app/views/spree/checkout/existing_payment/_paypal_braintree.html.erb +10 -0
  63. data/app/views/spree/shared/_apple_pay_button.html.erb +27 -0
  64. data/app/views/spree/shared/_braintree_errors.html.erb +16 -0
  65. data/app/views/spree/shared/_braintree_hosted_fields.html.erb +25 -8
  66. data/app/views/spree/shared/_paypal_braintree_head_scripts.html.erb +26 -0
  67. data/app/views/spree/shared/_paypal_cart_button.html.erb +38 -0
  68. data/app/views/spree/shared/_paypal_messaging.html.erb +13 -0
  69. data/app/views/spree/shared/_venmo_button.html.erb +33 -0
  70. data/bin/console +17 -0
  71. data/bin/rails +15 -0
  72. data/bin/setup +8 -0
  73. data/config/locales/en.yml +66 -0
  74. data/config/locales/it.yml +56 -0
  75. data/config/routes.rb +2 -0
  76. data/db/migrate/20160906201711_create_solidus_paypal_braintree_customers.rb +3 -1
  77. data/db/migrate/20161125172005_add_braintree_configuration_to_stores.rb +5 -7
  78. data/db/migrate/20170505193712_add_null_constraint_to_sources.rb +3 -1
  79. data/db/migrate/20190705115327_add_paypal_button_preferences_to_braintree_configurations.rb +5 -0
  80. data/db/migrate/20190911141712_add_3d_secure_to_braintree_configuration.rb +5 -0
  81. data/db/migrate/20211222170950_add_paypal_funding_source_to_solidus_paypal_braintree_sources.rb +5 -0
  82. data/db/migrate/20220104150301_add_venmo_to_braintree_configuration.rb +5 -0
  83. data/lib/controllers/backend/solidus_paypal_braintree/configurations_controller.rb +23 -5
  84. data/lib/controllers/frontend/solidus_paypal_braintree/checkouts_controller.rb +25 -21
  85. data/lib/controllers/frontend/solidus_paypal_braintree/transactions_controller.rb +56 -50
  86. data/lib/generators/solidus_paypal_braintree/install/install_generator.rb +7 -6
  87. data/lib/solidus_paypal_braintree/country_mapper.rb +4 -2
  88. data/lib/solidus_paypal_braintree/engine.rb +34 -22
  89. data/lib/solidus_paypal_braintree/factories.rb +41 -6
  90. data/lib/solidus_paypal_braintree/request_protection.rb +21 -0
  91. data/lib/solidus_paypal_braintree/version.rb +3 -1
  92. data/lib/solidus_paypal_braintree.rb +5 -1
  93. data/lib/views/backend/solidus_paypal_braintree/configurations/list.html.erb +38 -5
  94. data/lib/views/backend/spree/admin/payments/source_forms/_paypal_braintree.html.erb +2 -2
  95. data/lib/views/backend/spree/admin/payments/source_views/_paypal_braintree.html.erb +7 -2
  96. data/lib/views/backend/spree/admin/shared/preference_fields/_preference_select.html.erb +13 -0
  97. data/lib/views/backend_v1.2/spree/admin/payments/source_forms/_paypal_braintree.html.erb +2 -2
  98. data/lib/views/backend_v2.4/spree/admin/shared/preference_fields/_hash.html.erb +12 -0
  99. data/lib/views/frontend/solidus_paypal_braintree/payments/_payment.html.erb +12 -0
  100. data/lib/views/frontend/spree/checkout/payment/_paypal_braintree.html.erb +10 -77
  101. data/lib/views/frontend/spree/shared/_paypal_checkout_button.html.erb +32 -0
  102. data/solidus_paypal_braintree.gemspec +43 -0
  103. data/spec/controllers/solidus_paypal_braintree/checkouts_controller_spec.rb +99 -0
  104. data/spec/controllers/solidus_paypal_braintree/client_tokens_controller_spec.rb +55 -0
  105. data/spec/controllers/solidus_paypal_braintree/configurations_controller_spec.rb +73 -0
  106. data/spec/controllers/solidus_paypal_braintree/transactions_controller_spec.rb +183 -0
  107. data/spec/features/backend/configuration_spec.rb +23 -0
  108. data/spec/features/backend/new_payment_spec.rb +137 -0
  109. data/spec/features/frontend/braintree_credit_card_checkout_spec.rb +191 -0
  110. data/spec/features/frontend/paypal_checkout_spec.rb +166 -0
  111. data/spec/features/frontend/venmo_checkout_spec.rb +189 -0
  112. data/spec/fixtures/cassettes/admin/invalid_credit_card.yml +63 -0
  113. data/spec/fixtures/cassettes/admin/resubmit_credit_card.yml +352 -0
  114. data/spec/fixtures/cassettes/admin/valid_credit_card.yml +412 -0
  115. data/spec/fixtures/cassettes/braintree/create_profile.yml +71 -0
  116. data/spec/fixtures/cassettes/braintree/generate_token.yml +63 -0
  117. data/spec/fixtures/cassettes/braintree/token.yml +63 -0
  118. data/spec/fixtures/cassettes/checkout/invalid_credit_card.yml +63 -0
  119. data/spec/fixtures/cassettes/checkout/resubmit_credit_card.yml +216 -0
  120. data/spec/fixtures/cassettes/checkout/update.yml +71 -0
  121. data/spec/fixtures/cassettes/checkout/valid_credit_card.yml +156 -0
  122. data/spec/fixtures/cassettes/checkout/valid_venmo_transaction.yml +599 -0
  123. data/spec/fixtures/cassettes/gateway/authorize/credit_card/address.yml +86 -0
  124. data/spec/fixtures/cassettes/gateway/authorize/merchant_account/EUR.yml +154 -0
  125. data/spec/fixtures/cassettes/gateway/authorize/paypal/EUR.yml +90 -0
  126. data/spec/fixtures/cassettes/gateway/authorize/paypal/address.yml +90 -0
  127. data/spec/fixtures/cassettes/gateway/authorize.yml +86 -0
  128. data/spec/fixtures/cassettes/gateway/authorized_transaction.yml +73 -0
  129. data/spec/fixtures/cassettes/gateway/cancel/missing.yml +63 -0
  130. data/spec/fixtures/cassettes/gateway/cancel/refunds.yml +272 -0
  131. data/spec/fixtures/cassettes/gateway/cancel/void.yml +201 -0
  132. data/spec/fixtures/cassettes/gateway/capture.yml +141 -0
  133. data/spec/fixtures/cassettes/gateway/complete.yml +157 -0
  134. data/spec/fixtures/cassettes/gateway/credit.yml +208 -0
  135. data/spec/fixtures/cassettes/gateway/purchase.yml +87 -0
  136. data/spec/fixtures/cassettes/gateway/settled_transaction.yml +140 -0
  137. data/spec/fixtures/cassettes/gateway/void.yml +137 -0
  138. data/spec/fixtures/cassettes/source/card_type.yml +267 -0
  139. data/spec/fixtures/cassettes/source/last4.yml +267 -0
  140. data/spec/fixtures/cassettes/transaction/import/valid/capture.yml +224 -0
  141. data/spec/fixtures/cassettes/transaction/import/valid.yml +71 -0
  142. data/spec/fixtures/views/spree/orders/edit.html.erb +50 -0
  143. data/spec/helpers/solidus_paypal_braintree/braintree_admin_helper_spec.rb +17 -0
  144. data/spec/helpers/solidus_paypal_braintree/braintree_checkout_helper_spec.rb +70 -0
  145. data/spec/models/solidus_paypal_braintree/address_spec.rb +71 -0
  146. data/spec/models/solidus_paypal_braintree/avs_result_spec.rb +317 -0
  147. data/spec/models/solidus_paypal_braintree/gateway_spec.rb +692 -0
  148. data/spec/models/solidus_paypal_braintree/response_spec.rb +280 -0
  149. data/spec/models/solidus_paypal_braintree/source_spec.rb +499 -0
  150. data/spec/models/solidus_paypal_braintree/transaction_address_spec.rb +235 -0
  151. data/spec/models/solidus_paypal_braintree/transaction_import_spec.rb +300 -0
  152. data/spec/models/solidus_paypal_braintree/transaction_spec.rb +85 -0
  153. data/spec/models/spree/store_spec.rb +14 -0
  154. data/spec/requests/spree/api/orders_controller_spec.rb +36 -0
  155. data/spec/spec_helper.rb +29 -0
  156. data/spec/support/capybara.rb +7 -0
  157. data/spec/support/factories.rb +2 -0
  158. data/spec/support/gateway_helpers.rb +29 -0
  159. data/spec/support/order_ready_for_payment.rb +37 -0
  160. data/spec/support/vcr.rb +42 -0
  161. data/spec/support/views.rb +1 -0
  162. metadata +226 -166
  163. data/app/controllers/solidus_paypal_braintree/client_tokens_controller.rb +0 -21
  164. data/app/helpers/braintree_admin_helper.rb +0 -18
  165. data/app/models/spree/store_decorator.rb +0 -11
  166. data/app/overrides/admin_navigation_menu.rb +0 -6
  167. data/config/initializers/braintree.rb +0 -1
  168. data/lib/views/backend/solidus_paypal_braintree/configurations/_admin_tab.html.erb +0 -3
@@ -1,15 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_model'
2
4
 
3
5
  module SolidusPaypalBraintree
4
6
  class Transaction
5
7
  include ActiveModel::Model
6
8
 
7
- attr_accessor :nonce, :payment_method, :payment_type, :address, :email, :phone
9
+ attr_accessor :nonce, :payment_method, :payment_type, :paypal_funding_source, :address, :email, :phone
8
10
 
9
11
  validates :nonce, presence: true
10
12
  validates :payment_method, presence: true
11
13
  validates :payment_type, presence: true
12
- validates :phone, presence: true
13
14
  validates :email, presence: true
14
15
 
15
16
  validate do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_model'
2
4
 
3
5
  module SolidusPaypalBraintree
@@ -6,18 +8,18 @@ module SolidusPaypalBraintree
6
8
  include ActiveModel::Validations::Callbacks
7
9
  include SolidusPaypalBraintree::CountryMapper
8
10
 
9
- attr_accessor :country_code, :last_name, :first_name,
10
- :city, :zip, :state_code, :address_line_1, :address_line_2
11
+ attr_accessor :country_code, :name, :city, :zip, :state_code,
12
+ :address_line_1, :address_line_2, :first_name, :last_name
11
13
 
12
- validates :first_name, :last_name, :address_line_1, :city, :zip,
13
- :state_code, :country_code, presence: true
14
+ validates :address_line_1, :city, :zip, :country_code, presence: true
15
+ validates :name, presence: true, unless: ->(address){ address.first_name.present? }
14
16
 
15
17
  before_validation do
16
18
  self.country_code = country_code.presence || "us"
17
19
  end
18
20
 
19
21
  validates :spree_country, presence: true
20
- validates :spree_state, presence: true, if: :should_match_state_model?
22
+ validates :state_code, :spree_state, presence: true, if: :should_match_state_model?
21
23
 
22
24
  def initialize(attributes = {})
23
25
  country_name = attributes.delete(:country_name) || ""
@@ -29,25 +31,45 @@ module SolidusPaypalBraintree
29
31
  end
30
32
 
31
33
  def spree_country
32
- country_code && (@country ||= Spree::Country.find_by(iso: country_code.upcase))
34
+ country_code && (@country ||= ::Spree::Country.find_by(iso: country_code.upcase))
33
35
  end
34
36
 
35
37
  def spree_state
36
- spree_country && state_code && ( @state ||= spree_country.states.where(
37
- Spree::State.arel_table[:name].matches(state_code).or(
38
- Spree::State.arel_table[:abbr].matches(state_code)
38
+ spree_country && state_code && ( @state ||= spree_country.states.find_by(
39
+ ::Spree::State.arel_table[:name].matches(state_code).or(
40
+ ::Spree::State.arel_table[:abbr].matches(state_code)
39
41
  )
40
- ).first )
42
+ ))
41
43
  end
42
44
 
43
45
  def to_spree_address
44
- address = Spree::Address.new first_name: first_name,
45
- last_name: last_name,
46
+ address = ::Spree::Address.new(
46
47
  city: city,
47
48
  country: spree_country,
48
49
  address1: address_line_1,
49
50
  address2: address_line_2,
50
51
  zipcode: zip
52
+ )
53
+
54
+ if SolidusSupport.combined_first_and_last_name_in_address?
55
+ address.name = begin
56
+ if first_name.nil?
57
+ name
58
+ else
59
+ [first_name, last_name].join(" ")
60
+ end
61
+ end
62
+ else
63
+ ::Spree::Deprecation.warn("first_name and last_name are deprecated. Use name instead.", caller)
64
+ if first_name.nil?
65
+ first, last = SolidusPaypalBraintree::Address.split_name(name)
66
+ address.firstname = first
67
+ address.lastname = last || "(left blank)"
68
+ else
69
+ address.firstname = first_name
70
+ address.lastname = last_name || "(left blank)"
71
+ end
72
+ end
51
73
 
52
74
  if spree_state
53
75
  address.state = spree_state
@@ -57,10 +79,9 @@ module SolidusPaypalBraintree
57
79
  address
58
80
  end
59
81
 
60
- # Check to see if this address should match to a state
61
- # model in the database.
82
+ # Check to see if this address should match to a state model in the database
62
83
  def should_match_state_model?
63
- spree_country.present? && spree_country.states.any?
84
+ spree_country&.states_required?
64
85
  end
65
86
  end
66
87
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_model'
2
4
 
3
5
  module SolidusPaypalBraintree
@@ -25,32 +27,36 @@ module SolidusPaypalBraintree
25
27
  end
26
28
 
27
29
  def source
28
- SolidusPaypalBraintree::Source.new nonce: transaction.nonce,
30
+ SolidusPaypalBraintree::Source.new(
31
+ nonce: transaction.nonce,
29
32
  payment_type: transaction.payment_type,
30
33
  payment_method: transaction.payment_method,
34
+ paypal_funding_source: transaction.paypal_funding_source,
31
35
  user: user
36
+ )
32
37
  end
33
38
 
34
- def user
35
- order.user
36
- end
39
+ delegate :user, to: :order
37
40
 
38
- def import!(end_state)
41
+ def import!(end_state, restart_checkout: false)
39
42
  if valid?
40
- order.email = user.try!(:email) || transaction.email
43
+ order.email = user&.email || transaction.email
41
44
 
42
45
  if address
43
46
  order.shipping_address = order.billing_address = address
44
47
  # work around a bug in most solidus versions
45
48
  # about tax zone cachine between address changes
46
- order.instance_variable_set("@tax_zone", nil)
49
+ order.instance_variable_set(:@tax_zone, nil)
47
50
  end
48
51
 
49
- payment = order.payments.new source: source,
52
+ payment = order.payments.new(
53
+ source: source,
50
54
  payment_method: transaction.payment_method,
51
55
  amount: order.total
56
+ )
52
57
 
53
58
  order.save!
59
+ order.restart_checkout_flow if restart_checkout
54
60
  advance_order(payment, end_state)
55
61
  else
56
62
  raise InvalidImportError,
@@ -82,11 +88,11 @@ module SolidusPaypalBraintree
82
88
 
83
89
  def update_payment_total(payment)
84
90
  payment_total = order.payments.where(state: %w[checkout pending]).sum(:amount)
85
- remaining_total = order.outstanding_balance - payment_total
91
+ payment_difference = order.outstanding_balance - payment_total
86
92
 
87
- if remaining_total > 0
88
- payment.update!(amount: payment.amount + remaining_total)
89
- end
93
+ return unless payment_difference != 0
94
+
95
+ payment.update!(amount: payment.amount + payment_difference)
90
96
  end
91
97
  end
92
98
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ Deface::Override.new(
4
+ name: "payments/payment/add_paypal_funding_source_to_payment",
5
+ virtual_path: "spree/payments/_payment",
6
+ original: "0b5b5ae53626059cb3a202ef95d10827dd399925",
7
+ insert_after: "erb[loud]:contains('content_tag(:span, payment.payment_method.name)')",
8
+ partial: "solidus_paypal_braintree/payments/payment"
9
+ )
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ json.call(payment_source, :id, :token, :created_at)
@@ -0,0 +1,10 @@
1
+ <tr id="<%= dom_id(wallet_payment_source, 'spree')%>" class="<%= cycle('even', 'odd') %>">
2
+ <td>
3
+ <%= radio_button_tag "order[wallet_payment_source_id]",
4
+ wallet_payment_source.id,
5
+ default,
6
+ class: "existing-cc-radio" %>
7
+ </td>
8
+ <td><%= wallet_payment_source.payment_source.friendly_payment_type %></td>
9
+ <td><%= wallet_payment_source.payment_source.display_number %></td>
10
+ </tr>
@@ -0,0 +1,27 @@
1
+ <% address = current_order.ship_address %>
2
+
3
+ <button id="apple-pay-button" class="apple-pay-button"></button>
4
+
5
+ <script>
6
+ var applePayButtonElement = document.getElementById('apple-pay-button');
7
+ var applePayOptions = {
8
+ paymentMethodId: <%= id %>,
9
+ storeName: "<%= current_store.name %>",
10
+ orderEmail: "<%= current_order.email %>",
11
+ amount: "<%= current_order.total %>",
12
+ shippingContact: {
13
+ emailAddress: '<%= current_order.email %>',
14
+ givenName: '<%= address.firstname %>',
15
+ familyName: '<%= address.lastname %>',
16
+ phoneNumber: '<%= address.phone %>',
17
+ addressLines: ['<%= address.address1 %>','<%= address.address2 %>'],
18
+ locality: '<%= address.city %>',
19
+ administrativeArea: '<%= address.state.name %>',
20
+ postalCode: '<%= address.zipcode %>',
21
+ country: '<%= address.country.name %>',
22
+ countryCode: '<%= address.country.iso %>'
23
+ }
24
+ };
25
+ var button = new SolidusPaypalBraintree.createApplePayButton(applePayButtonElement, applePayOptions);
26
+ button.initialize();
27
+ </script>
@@ -0,0 +1,16 @@
1
+ <script type="text/javascript">
2
+ BraintreeError.DEFAULT = "<%= I18n.t('solidus_paypal_braintree.errors.default_error')%>"
3
+ BraintreeError.PAYPAL_POPUP_CLOSED = "<%= I18n.t('solidus_paypal_braintree.errors.paypal_popup_closed') %>"
4
+ BraintreeError.HOSTED_FIELDS_FIELDS_EMPTY = "<%= I18n.t('solidus_paypal_braintree.errors.empty_fields')%>"
5
+ BraintreeError.HOSTED_FIELDS_FIELDS_INVALID = "<%= I18n.t('solidus_paypal_braintree.errors.invalid_fields')%>"
6
+ BraintreeError.HOSTED_FIELDS_FAILED_TOKENIZATION = "<%= I18n.t('solidus_paypal_braintree.errors.invalid_card')%>"
7
+ BraintreeError.HOSTED_FIELDS_TOKENIZATION_NETWORK_ERROR = "<%= I18n.t('solidus_paypal_braintree.errors.network_error')%>"
8
+ BraintreeError.HOSTED_FIELDS_FIELD_DUPLICATE_IFRAME = "<%= I18n.t('solidus_paypal_braintree.errors.duplicate_iframe')%>"
9
+ BraintreeError.HOSTED_FIELDS_TOKENIZATION_FAIL_ON_DUPLICATE = "<%= I18n.t('solidus_paypal_braintree.errors.fail_on_duplicate')%>"
10
+ BraintreeError.HOSTED_FIELDS_TOKENIZATION_CVV_VERIFICATION_FAILED = "<%= I18n.t('solidus_paypal_braintree.errors.cvv_verification_failed')%>"
11
+ BraintreeError.THREEDS_AUTHENTICATION_FAILED = "<%= t('solidus_paypal_braintree.errors.threeds.authentication_failed') %>";
12
+ BraintreeError.THREEDS_CARDINAL_SDK_ERROR = "<%= t('solidus_paypal_braintree.errors.threeds.authentication_failed') %>";
13
+ BraintreeError.VENMO_CANCELED = "<%= t('solidus_paypal_braintree.errors.venmo.canceled') %>";
14
+ BraintreeError.VENMO_DESKTOP_CANCELED = "<%= t('solidus_paypal_braintree.errors.venmo.desktop_canceled') %>";
15
+ BraintreeError.VENMO_APP_CANCELED = "<%= t('solidus_paypal_braintree.errors.venmo.app_canceled') %>";
16
+ </script>
@@ -1,22 +1,30 @@
1
- <% prefix = "payment_source[#{id}]" %>
1
+ <% if defined?(id) && !defined?(payment_method) %>
2
+ <% payment_method = Spree::PaymentMethod.find(id) %>
3
+ <% Spree::Deprecation.warn(
4
+ "passing id to _braintree_hosted_fields.html.erb is deprecated. Please pass the payment_method directly.",
5
+ caller
6
+ ) %>
7
+ <% end %>
8
+
9
+ <% prefix = "payment_source[#{payment_method.id}]" %>
2
10
 
3
11
  <div class="hosted-fields">
4
12
  <div class="field" data-hook="card_number">
5
- <%= label_tag "card_number#{id}", Spree::CreditCard.human_attribute_name(:number), class: "required" %>
6
- <div class="input" id="card_number<%= id %>"></div>
13
+ <%= label_tag "card_number#{payment_method.id}", Spree::CreditCard.human_attribute_name(:number), class: "required" %>
14
+ <div class="input" id="card_number<%= payment_method.id %>"></div>
7
15
  </div>
8
16
 
9
17
  <div class="field" data-hook="card_expiration">
10
- <%= label_tag "card_expiry#{id}", Spree::CreditCard.human_attribute_name(:expiration), class: "required" %>
11
- <div class="input" id="card_expiry<%= id %>"></div>
18
+ <%= label_tag "card_expiry#{payment_method.id}", Spree::CreditCard.human_attribute_name(:expiration), class: "required" %>
19
+ <div class="input" id="card_expiry<%= payment_method.id %>"></div>
12
20
  </div>
13
21
 
14
22
  <div class="field" data-hook="card_code">
15
- <%= label_tag "card_code#{id}", Spree::CreditCard.human_attribute_name(:card_code), class: "required" %>
16
- <div class="input" id="card_code<%= id %>"></div>
23
+ <%= label_tag "card_code#{payment_method.id}", Spree::CreditCard.human_attribute_name(:card_code), class: "required" %>
24
+ <div class="input" id="card_code<%= payment_method.id %>"></div>
17
25
 
18
26
  <a href="/content/cvv" class="info cvvLink" target="_blank">
19
- (<%= Spree.t(:what_is_this) %>)
27
+ (<%= I18n.t("spree.what_is_this") %>)
20
28
  </a>
21
29
  </div>
22
30
 
@@ -24,3 +32,12 @@
24
32
  <input type="hidden" name="<%= prefix %>[payment_type]" value="<%= SolidusPaypalBraintree::Source::CREDIT_CARD %>">
25
33
  <input type="hidden" id="payment_method_nonce" name="<%= prefix %>[nonce]">
26
34
  </div>
35
+
36
+
37
+ <script>
38
+ <% if current_store.braintree_configuration.three_d_secure? %>
39
+ var threeDSecureOptions = <%= raw braintree_3ds_options_for(current_order).to_json %>;
40
+ <% end -%>
41
+ var credit_card_fields_style = <%= raw payment_method.preferred_credit_card_fields_style.to_json %>
42
+ var placeholder_text = <%= raw payment_method.preferred_placeholder_text.to_json %>
43
+ </script>
@@ -0,0 +1,26 @@
1
+ <% content_for :head do %>
2
+ <script src="https://js.braintreegateway.com/web/3.84.0/js/client.min.js"></script>
3
+ <script src="https://js.braintreegateway.com/web/3.84.0/js/data-collector.min.js"></script>
4
+
5
+ <% if current_store.braintree_configuration.paypal? %>
6
+ <script src="https://js.braintreegateway.com/web/3.84.0/js/paypal-checkout.min.js"></script>
7
+ <% end %>
8
+
9
+ <% if current_store.braintree_configuration.credit_card? %>
10
+ <script src="https://js.braintreegateway.com/web/3.84.0/js/hosted-fields.min.js"></script>
11
+
12
+ <% if current_store.braintree_configuration.three_d_secure? %>
13
+ <script src="https://js.braintreegateway.com/web/3.84.0/js/three-d-secure.min.js"></script>
14
+ <% end %>
15
+ <% end %>
16
+
17
+ <% if current_store.braintree_configuration.apple_pay? %>
18
+ <script src="https://js.braintreegateway.com/web/3.84.0/js/apple-pay.min.js"></script>
19
+ <% end %>
20
+
21
+ <% if current_store.braintree_configuration.venmo? %>
22
+ <script src="https://js.braintreegateway.com/web/3.84.0/js/venmo.min.js"></script>
23
+ <% end %>
24
+
25
+ <%= javascript_include_tag "solidus_paypal_braintree/checkout" %>
26
+ <% end %>
@@ -0,0 +1,38 @@
1
+ <%= render "spree/shared/paypal_braintree_head_scripts" %>
2
+
3
+ <div id="paypal-button"></div>
4
+ <div data-pp-message data-pp-placement="payment" data-pp-amount="<%= current_order.total %>"></div>
5
+
6
+ <script>
7
+ var paypalOptions = {
8
+ flow: '<%= SolidusPaypalBraintree::Gateway.first.preferred_paypal_flow %>',
9
+ amount: '<%= current_order.total %>',
10
+ currency: '<%= current_order.currency %>',
11
+ enableShippingAddress: true,
12
+ buyerCountry: '<%= SolidusPaypalBraintree::Gateway.first.preferred_force_buyer_country %>',
13
+ environment: '<%= Rails.env.production? ? "production" : "sandbox" %>',
14
+ locale: '<%= paypal_button_preference(:paypal_button_locale, store: current_store) %>',
15
+ useDataCollector: <%= SolidusPaypalBraintree::Gateway.first.preferred_use_data_collector %>,
16
+ style: {
17
+ color: '<%= paypal_button_preference(:paypal_button_color, store: current_store) %>',
18
+ shape: '<%= paypal_button_preference(:paypal_button_shape, store: current_store) %>',
19
+ label: '<%= paypal_button_preference(:paypal_button_label, store: current_store) %>',
20
+ layout: '<%= paypal_button_preference(:paypal_button_layout, store: current_store) %>',
21
+ <% if paypal_button_preference(:paypal_button_layout, store: current_store) == "horizontal" %>
22
+ tagline: '<%= paypal_button_preference(:paypal_button_tagline, store: current_store) %>',
23
+ <% end %>
24
+ messaging: '<%= paypal_button_preference(:paypal_button_messaging, store: current_store) %>'
25
+ }
26
+ }
27
+ var options = {
28
+ restart_checkout: true
29
+ }
30
+
31
+ var button = new SolidusPaypalBraintree.createPaypalButton(
32
+ document.querySelector("#paypal-button"),
33
+ paypalOptions,
34
+ options
35
+ )
36
+
37
+ button.initialize();
38
+ </script>
@@ -0,0 +1,13 @@
1
+ <%= render "spree/shared/paypal_braintree_head_scripts" %>
2
+
3
+ <div data-pp-message data-pp-placement="<%= options[:placement] %>" data-pp-amount="<%= options[:total] %>"></div>
4
+
5
+ <script>
6
+ var message = new SolidusPaypalBraintree.createPaypalMessaging(
7
+ {
8
+ currency: "<%= options[:currency] %>"
9
+ }
10
+ )
11
+
12
+ message.initialize();
13
+ </script>
@@ -0,0 +1,33 @@
1
+ <%= button_tag '', id: 'venmo-button', class: 'venmo-button', type: 'button' %>
2
+
3
+ <% store = Spree::Store.default %>
4
+ <% style = venmo_button_style(store) %>
5
+
6
+ <style>
7
+ .venmo-button {
8
+ width: <%= style[:width] %>px;
9
+ background-image: url('<%= venmo_button_asset_url(style)%>');
10
+ }
11
+ .venmo-button:active, .venmo-button:hover {
12
+ background-color: transparent !important;
13
+ background-image: url('<%= venmo_button_asset_url(style, active: true)%>') !important;
14
+ }
15
+ </style>
16
+
17
+ <% prefix = "payment_source[#{payment_method.id}]" %>
18
+
19
+ <div class="venmo-fields">
20
+ <div class="clear"></div>
21
+ <input disabled type="hidden" name="<%= prefix %>[payment_type]" value="<%= SolidusPaypalBraintree::Source::VENMO %>">
22
+ <input disabled type="hidden" id="venmo_payment_method_nonce" name="<%= prefix %>[nonce]">
23
+ </div>
24
+
25
+ <script>
26
+ var venmoButtonElement = document.getElementById('venmo-button');
27
+ var venmoOptions = {
28
+ newBrowserTabSupported: <%= SolidusPaypalBraintree::Gateway.first.preferred_venmo_new_tab_support %>,
29
+ flow: '<%= SolidusPaypalBraintree::Gateway.first.preferred_paypal_flow %>'
30
+ };
31
+ var button = new SolidusPaypalBraintree.createVenmoButton(venmoButtonElement, venmoOptions);
32
+ button.initialize();
33
+ </script>
data/bin/console ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require "bundler/setup"
6
+ require "solidus_paypal_braintree"
7
+
8
+ # You can add fixtures and/or initialization code here to make experimenting
9
+ # with your gem easier. You can also use a different console, if you like.
10
+ $LOAD_PATH.unshift(*Dir["#{__dir__}/../app/*"])
11
+
12
+ # (If you use this, don't forget to add pry to your Gemfile!)
13
+ # require "pry"
14
+ # Pry.start
15
+
16
+ require "irb"
17
+ IRB.start(__FILE__)
data/bin/rails ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ app_root = 'spec/dummy'
6
+
7
+ unless File.exist? "#{app_root}/bin/rails"
8
+ system "bin/rake", app_root or begin
9
+ warn "Automatic creation of the dummy app failed"
10
+ exit 1
11
+ end
12
+ end
13
+
14
+ Dir.chdir app_root
15
+ exec 'bin/rails', *ARGV
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ gem install bundler --conservative
7
+ bundle update
8
+ bundle exec rake clobber
@@ -2,6 +2,13 @@ en:
2
2
  activerecord:
3
3
  models:
4
4
  solidus_paypal_braintree/gateway: Braintree
5
+ attributes:
6
+ solidus_paypal_braintree/configuration:
7
+ paypal: PayPal
8
+ apple_pay: Apple Pay
9
+ credit_card: Credit Card
10
+ three_d_secure: 3D Secure
11
+ venmo: Venmo
5
12
  spree:
6
13
  admin:
7
14
  tab:
@@ -14,17 +21,76 @@ en:
14
21
  private_key: Private key
15
22
  public_key: Public key
16
23
  token_generation_enabled: Token generation enabled?
24
+ paypal_flow: PayPal flow
25
+ paypal_funding: 'PayPal Funding: %{funding}'
26
+ paypal_funding_source: 'PayPal Funding Source'
17
27
  solidus_paypal_braintree:
18
28
  braintree: Braintree
19
29
  nonce: Nonce
20
30
  token: Token
31
+ errors:
32
+ default_error: "Something bad happened!"
33
+ paypal_popup_closed: "PayPal popup has been closed before payment completion."
34
+ empty_fields: "All fields are empty! Please fill out the form."
35
+ invalid_fields: "Some payment input fields are invalid."
36
+ invalid_card: "Credit card data is incorrect."
37
+ network_error: "Network error occurred."
38
+ duplicate_iframe: "Duplicate Braintree iframe."
39
+ fail_on_duplicate: "This payment method already exists in your vault."
40
+ cvv_verification_failed: "CVV did not pass verification."
41
+ threeds:
42
+ authentication_failed: "3D Secure authentication failed. Please try again using a different payment method."
43
+ venmo:
44
+ canceled: "App is not available or you aborted the payment flow."
45
+ desktop_canceled: "Venmo authorization was canceled by closing the Venmo Desktop modal."
46
+ app_canceled: "Payment flow was canceled."
21
47
  payment_type:
22
48
  label: Payment Type
23
49
  apple_pay_card: Apple Pay
24
50
  credit_card: Credit Card
25
51
  pay_pal_account: PayPal
52
+ venmo_account: Venmo
26
53
  configurations:
27
54
  title: Braintree Configurations
28
55
  tab: Braintree
29
56
  update_success: Successfully updated Braintree configurations.
30
57
  update_error: An error occurred while updating Braintree configurations.
58
+ gateway_rejection_reasons:
59
+ avs: AVS check failed.
60
+ avs_and_cvv: AVS and CVV check failed.
61
+ cvv: CVV check failed.
62
+ duplicate: Duplicate transaction.
63
+ fraud: Credit card was rejected because of potential fraud.
64
+ three_d_secure: 3D Secure check failed.
65
+ transaction_statuses:
66
+ authorization_expired: Payment authorization has expired.
67
+ failed: An error occurred when sending the transaction to the processor.
68
+ gateway_rejected: Gateway rejected this transaction.
69
+ processor_declined: Processor declined this transaction.
70
+ settlement_declined: Settlement was declined by processor.
71
+ paypal_funding_sources:
72
+ applepay: 'Apple Pay'
73
+ bancontact: 'Bancontact'
74
+ blik: 'BLIK'
75
+ boleto: 'Boleto'
76
+ card: 'Credit or debit card'
77
+ credit: 'PayPal Credit'
78
+ eps: 'eps'
79
+ giropay: 'giropay'
80
+ ideal: 'iDEAL'
81
+ itau: 'Itau'
82
+ maxima: 'Maxima'
83
+ mercadopago: 'Mercado Pago'
84
+ mybank: 'MyBank'
85
+ oxxo: 'Oxxo'
86
+ p24: 'Przelewy24'
87
+ paylater: 'Pay Later'
88
+ paypal: 'PayPal'
89
+ payu: 'PayU'
90
+ sepa: 'SEPA-Lastschrift'
91
+ sofort: 'Sofort'
92
+ trustly: 'Trustly'
93
+ venmo: 'Venmo'
94
+ verkkopankki: 'Verkkopankki'
95
+ wechatpay: 'WeChat Pay'
96
+ zimpler: 'Zimpler'
@@ -0,0 +1,56 @@
1
+ it:
2
+ activerecord:
3
+ models:
4
+ solidus_paypal_braintree/gateway: Braintree
5
+ spree:
6
+ admin:
7
+ tab:
8
+ braintree: Braintree
9
+ client_sdk_enabled: Client SDK abilitato?
10
+ environment: Environment
11
+ merchant_currency_map: Associazioni tra merchant Braintree e valute
12
+ merchant_id: Merchant ID
13
+ paypal_payee_email_map: Associazioni tra email beneficiari PayPal e valute
14
+ private_key: Private key
15
+ public_key: Public key
16
+ token_generation_enabled: Generazione dei Token abilitata?
17
+ paypal_flow: Flusso PayPal
18
+ solidus_paypal_braintree:
19
+ braintree: Braintree
20
+ nonce: Nonce
21
+ token: Token
22
+ errors:
23
+ default_error: Qualcosa è andato storto!
24
+ paypal_popup_closed: La finestra di PayPal è stata chiusa prima di completare il pagamento.
25
+ empty_fields: I campi non possono essere vuoti!
26
+ invalid_fields: Alcuni campi non sono corretti.
27
+ invalid_card: I dati della carta di credito non sono corretti.
28
+ network_error: Si è verificato un errore di rete.
29
+ duplicate_iframe: Ci sono due iframe di Braintree.
30
+ fail_on_duplicate: Questo metodo di pagamento esiste già.
31
+ cvv_verification_failed: Il codice CVV non è corretto.
32
+ threeds:
33
+ authentication_failed: "Autenticazione 3D Secure fallita. Riprova usando un altro metodo di pagamento."
34
+ payment_type:
35
+ label: Metodo di Pagamento
36
+ apple_pay_card: Apple Pay
37
+ credit_card: Carta di credito
38
+ pay_pal_account: PayPal
39
+ configurations:
40
+ title: Configurazioni di Braintree
41
+ tab: Braintree
42
+ update_success: Configurazioni di Braintree aggiornate con successo.
43
+ update_error: Si è verificato un errore durante l'aggiornamento delle configurazioni di Braintree.
44
+ gateway_rejection_reasons:
45
+ avs: Controllo AVS fallito.
46
+ avs_and_cvv: Controlli AVS e CVV falliti.
47
+ cvv: Controllo CVV fallito.
48
+ duplicate: Transazione duplicata.
49
+ fraud: La carta di credito è stata rifiutata a seguito di un potenziale uso fraudolento.
50
+ three_d_secure: Controllo '3D Secure' fallito.
51
+ transaction_statuses:
52
+ authorization_expired: L'autorizzazione di pagamento è scaduta.
53
+ failed: Si è verificato un errore durante l'invio della transazione al sistema di pagamento.
54
+ gateway_rejected: Il gateway di pagamento ha rifiutato questa transazione.
55
+ processor_declined: Il sistema di pagamento ha rifiutato questa transazione.
56
+ settlement_declined: Il saldo di questa transazione è stato rifiutato dal sistema di pagamento.
data/config/routes.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  SolidusPaypalBraintree::Engine.routes.draw do
2
4
  resource :checkout, only: [:update, :edit]
3
5
  resource :client_token, only: [:create], format: :json
@@ -3,9 +3,11 @@ class CreateSolidusPaypalBraintreeCustomers < SolidusSupport::Migration[4.2]
3
3
  create_table :solidus_paypal_braintree_customers do |t|
4
4
  t.references :user
5
5
  t.string :braintree_customer_id
6
+
7
+ t.timestamps
6
8
  end
7
9
 
8
10
  add_index :solidus_paypal_braintree_customers, :user_id, unique: true, name: "index_braintree_customers_on_user_id"
9
- add_index :solidus_paypal_braintree_customers, :braintree_customer_id, unique: true, name: "index_braintree_customers_on_braintree_customer_id"
11
+ add_index :solidus_paypal_braintree_customers, :braintree_customer_id, unique: true, name: "index_braintree_customers_on_braintree_customer_id" # rubocop:disable Layout/LineLength
10
12
  end
11
13
  end
@@ -1,9 +1,7 @@
1
1
  class AddBraintreeConfigurationToStores < SolidusSupport::Migration[4.2]
2
- def up
3
- Spree::Store.all.each(&:create_braintree_configuration)
4
- end
5
-
6
- def down
7
- SolidusPaypalBraintree::Configuration.joins(:store).destroy_all
8
- end
2
+ # The content of this migration has been removed because store's Braintree
3
+ # configuration doesn't already have paypal_button_preferences fields, so
4
+ # their validations will break this migration.
5
+ #
6
+ # Ref here for more info https://github.com/solidusio/solidus_paypal_braintree/pull/249
9
7
  end