solidus_braintree 1.2.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (213) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +78 -0
  3. data/.gem_release.yml +5 -0
  4. data/.github/stale.yml +1 -0
  5. data/.github_changelog_generator +2 -0
  6. data/.gitignore +21 -10
  7. data/.rspec +1 -1
  8. data/.rubocop.yml +86 -0
  9. data/CHANGELOG.md +186 -18
  10. data/Gemfile +35 -17
  11. data/LICENSE +26 -0
  12. data/README.md +389 -24
  13. data/Rakefile +6 -16
  14. data/app/assets/config/solidus_braintree_manifest.js +0 -0
  15. data/app/assets/javascripts/spree/backend/solidus_braintree/client.js +239 -0
  16. data/app/assets/javascripts/spree/backend/solidus_braintree/constants.js +89 -0
  17. data/app/assets/javascripts/spree/backend/solidus_braintree/hosted_form.js +46 -0
  18. data/app/assets/javascripts/spree/backend/solidus_braintree/promise.js +20 -0
  19. data/app/assets/javascripts/spree/backend/solidus_braintree.js +96 -0
  20. data/app/assets/stylesheets/spree/backend/solidus_braintree.scss +28 -0
  21. data/app/decorators/controllers/solidus_braintree/admin_payments_controller_decorator.rb +11 -0
  22. data/app/decorators/controllers/solidus_braintree/client_tokens_controller.rb +41 -0
  23. data/app/decorators/models/solidus_braintree/spree/store_decorator.rb +20 -0
  24. data/app/decorators/models/solidus_braintree/spree/user_decorator.rb +13 -0
  25. data/app/helpers/solidus_braintree/braintree_admin_helper.rb +23 -0
  26. data/app/models/application_record.rb +5 -0
  27. data/app/models/solidus_braintree/address.rb +64 -0
  28. data/app/models/solidus_braintree/avs_result.rb +69 -0
  29. data/app/models/solidus_braintree/configuration.rb +39 -0
  30. data/app/models/solidus_braintree/customer.rb +8 -0
  31. data/app/models/solidus_braintree/gateway.rb +437 -0
  32. data/app/models/solidus_braintree/response.rb +80 -0
  33. data/app/models/solidus_braintree/source.rb +140 -0
  34. data/app/models/solidus_braintree/transaction.rb +31 -0
  35. data/app/models/solidus_braintree/transaction_address.rb +88 -0
  36. data/app/models/solidus_braintree/transaction_import.rb +98 -0
  37. data/app/views/spree/api/payments/source_views/_braintree.json.jbuilder +3 -0
  38. data/bin/console +4 -1
  39. data/bin/dummy-app +37 -0
  40. data/bin/rails +5 -5
  41. data/bin/rails-dummy-app +17 -0
  42. data/bin/rails-engine +13 -0
  43. data/bin/rails-sandbox +16 -0
  44. data/bin/rake +7 -0
  45. data/bin/rspec +11 -0
  46. data/bin/sandbox +61 -0
  47. data/bin/setup +5 -4
  48. data/config/locales/en.yml +94 -2
  49. data/config/locales/it.yml +56 -0
  50. data/config/routes.rb +12 -3
  51. data/db/migrate/20160830061749_create_solidus_paypal_braintree_sources.rb +16 -0
  52. data/db/migrate/20160906201711_create_solidus_paypal_braintree_customers.rb +13 -0
  53. data/db/migrate/20161114231422_create_solidus_paypal_braintree_configurations.rb +11 -0
  54. data/db/migrate/20161125172005_add_braintree_configuration_to_stores.rb +7 -0
  55. data/db/migrate/20170203191030_add_credit_card_to_braintree_configuration.rb +6 -0
  56. data/db/migrate/20170505193712_add_null_constraint_to_sources.rb +38 -0
  57. data/db/migrate/20170508085402_add_not_null_constraint_to_sources_payment_type.rb +14 -0
  58. data/db/migrate/20190705115327_add_paypal_button_preferences_to_braintree_configurations.rb +5 -0
  59. data/db/migrate/20190911141712_add_3d_secure_to_braintree_configuration.rb +5 -0
  60. data/db/migrate/20211222170950_add_paypal_funding_source_to_solidus_paypal_braintree_sources.rb +5 -0
  61. data/db/migrate/20220104150301_add_venmo_to_braintree_configuration.rb +5 -0
  62. data/db/migrate/20230109080950_rename_solidus_paypal_braintree_source_type.rb +31 -0
  63. data/db/migrate/20230210104310_add_device_data_to_braintree_sources.rb +5 -0
  64. data/lib/controllers/backend/solidus_braintree/configurations_controller.rb +48 -0
  65. data/lib/generators/solidus_braintree/install/install_generator.rb +155 -19
  66. data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_active_blue_button_280x48.svg +19 -0
  67. data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_active_blue_button_320x48.svg +19 -0
  68. data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_active_blue_button_375x48.svg +19 -0
  69. data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_active_white_button_280x48.svg +19 -0
  70. data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_active_white_button_320x48.svg +19 -0
  71. data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_active_white_button_375x48.svg +19 -0
  72. data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_blue_acceptance_mark.svg +15 -0
  73. data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_blue_button_280x48.svg +19 -0
  74. data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_blue_button_320x48.svg +19 -0
  75. data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_blue_button_375x48.svg +19 -0
  76. data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_blue_logo.svg +18 -0
  77. data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_white_acceptance_mark.svg +20 -0
  78. data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_white_button_280x48.svg +19 -0
  79. data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_white_button_320x48.svg +19 -0
  80. data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_white_button_375x48.svg +19 -0
  81. data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_white_logo.svg +18 -0
  82. data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/paypal_button.js +34 -0
  83. data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/ajax.js +13 -0
  84. data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/apple_pay_button.js +179 -0
  85. data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/checkout.js +113 -0
  86. data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/client.js +239 -0
  87. data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/constants.js +89 -0
  88. data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/frontend.js +15 -0
  89. data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/hosted_form.js +48 -0
  90. data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/paypal_button.js +178 -0
  91. data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/paypal_messaging.js +22 -0
  92. data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/promise.js +20 -0
  93. data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/venmo_button.js +86 -0
  94. data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree.js +1 -0
  95. data/lib/generators/solidus_braintree/install/templates/app/assets/stylesheets/spree/frontend/solidus_braintree.scss +62 -0
  96. data/lib/generators/solidus_braintree/install/templates/app/controllers/solidus_braintree/checkouts_controller.rb +31 -0
  97. data/lib/generators/solidus_braintree/install/templates/app/controllers/solidus_braintree/transactions_controller.rb +67 -0
  98. data/lib/generators/solidus_braintree/install/templates/app/helpers/solidus_braintree/braintree_checkout_helper.rb +60 -0
  99. data/lib/generators/solidus_braintree/install/templates/app/views/checkouts/existing_payment/_braintree.html.erb +2 -0
  100. data/lib/generators/solidus_braintree/install/templates/app/views/checkouts/payment/_braintree.html.erb +23 -0
  101. data/lib/generators/solidus_braintree/install/templates/app/views/payments/_braintree_payment_details.html.erb +9 -0
  102. data/lib/generators/solidus_braintree/install/templates/app/views/spree/shared/_apple_pay_button.html.erb +27 -0
  103. data/lib/generators/solidus_braintree/install/templates/app/views/spree/shared/_braintree_errors.html.erb +16 -0
  104. data/lib/generators/solidus_braintree/install/templates/app/views/spree/shared/_braintree_head_scripts.html.erb +26 -0
  105. data/lib/generators/solidus_braintree/install/templates/app/views/spree/shared/_braintree_hosted_fields.html.erb +40 -0
  106. data/lib/generators/solidus_braintree/install/templates/app/views/spree/shared/_paypal_cart_button.html.erb +38 -0
  107. data/lib/generators/solidus_braintree/install/templates/app/views/spree/shared/_paypal_checkout_button.html.erb +32 -0
  108. data/lib/generators/solidus_braintree/install/templates/app/views/spree/shared/_paypal_messaging.html.erb +13 -0
  109. data/lib/generators/solidus_braintree/install/templates/app/views/spree/shared/_venmo_button.html.erb +33 -0
  110. data/lib/generators/solidus_braintree/install/templates/config/initializers/solidus_braintree.rb +6 -0
  111. data/lib/solidus_braintree/country_mapper.rb +37 -0
  112. data/lib/solidus_braintree/engine.rb +61 -11
  113. data/lib/solidus_braintree/extension_configuration.rb +23 -0
  114. data/lib/solidus_braintree/request_protection.rb +21 -0
  115. data/lib/solidus_braintree/version.rb +3 -1
  116. data/lib/solidus_braintree.rb +14 -2
  117. data/lib/solidus_paypal_braintree.rb +6 -0
  118. data/lib/views/backend/solidus_braintree/configurations/list.html.erb +63 -0
  119. data/lib/views/backend/spree/admin/payments/source_forms/_braintree.html.erb +16 -0
  120. data/lib/views/backend/spree/admin/payments/source_views/_braintree.html.erb +39 -0
  121. data/lib/views/backend/spree/admin/shared/preference_fields/_preference_select.html.erb +13 -0
  122. data/lib/views/backend_v1.2/spree/admin/payments/source_forms/_braintree.html.erb +16 -0
  123. data/lib/views/backend_v2.4/spree/admin/shared/preference_fields/_hash.html.erb +12 -0
  124. data/solidus_braintree.gemspec +37 -38
  125. data/spec/controllers/solidus_braintree/checkouts_controller_spec.rb +99 -0
  126. data/spec/controllers/solidus_braintree/client_tokens_controller_spec.rb +55 -0
  127. data/spec/controllers/solidus_braintree/configurations_controller_spec.rb +73 -0
  128. data/spec/controllers/solidus_braintree/transactions_controller_spec.rb +183 -0
  129. data/spec/fixtures/cassettes/admin/invalid_credit_card.yml +63 -0
  130. data/spec/fixtures/cassettes/admin/resubmit_credit_card.yml +352 -0
  131. data/spec/fixtures/cassettes/admin/valid_credit_card.yml +412 -0
  132. data/spec/fixtures/cassettes/braintree/create_profile.yml +71 -0
  133. data/spec/fixtures/cassettes/braintree/generate_token.yml +63 -0
  134. data/spec/fixtures/cassettes/braintree/token.yml +63 -0
  135. data/spec/fixtures/cassettes/checkout/invalid_credit_card.yml +63 -0
  136. data/spec/fixtures/cassettes/checkout/resubmit_credit_card.yml +216 -0
  137. data/spec/fixtures/cassettes/checkout/update.yml +71 -0
  138. data/spec/fixtures/cassettes/checkout/valid_credit_card.yml +171 -0
  139. data/spec/fixtures/cassettes/checkout/valid_venmo_transaction.yml +599 -0
  140. data/spec/fixtures/cassettes/gateway/authorize/credit_card/address.yml +86 -0
  141. data/spec/fixtures/cassettes/gateway/authorize/merchant_account/EUR.yml +154 -0
  142. data/spec/fixtures/cassettes/gateway/authorize/paypal/EUR.yml +90 -0
  143. data/spec/fixtures/cassettes/gateway/authorize/paypal/address.yml +90 -0
  144. data/spec/fixtures/cassettes/gateway/authorize.yml +86 -0
  145. data/spec/fixtures/cassettes/gateway/authorized_transaction.yml +73 -0
  146. data/spec/fixtures/cassettes/gateway/cancel/missing.yml +63 -0
  147. data/spec/fixtures/cassettes/gateway/cancel/refunds.yml +272 -0
  148. data/spec/fixtures/cassettes/gateway/cancel/void.yml +201 -0
  149. data/spec/fixtures/cassettes/gateway/capture.yml +141 -0
  150. data/spec/fixtures/cassettes/gateway/complete.yml +157 -0
  151. data/spec/fixtures/cassettes/gateway/credit.yml +208 -0
  152. data/spec/fixtures/cassettes/gateway/customer.yml +79 -0
  153. data/spec/fixtures/cassettes/gateway/purchase.yml +87 -0
  154. data/spec/fixtures/cassettes/gateway/settled_transaction.yml +140 -0
  155. data/spec/fixtures/cassettes/gateway/void.yml +137 -0
  156. data/spec/fixtures/cassettes/source/bin.yml +295 -0
  157. data/spec/fixtures/cassettes/source/card_type.yml +267 -0
  158. data/spec/fixtures/cassettes/source/last4.yml +267 -0
  159. data/spec/fixtures/cassettes/transaction/import/valid/capture.yml +224 -0
  160. data/spec/fixtures/cassettes/transaction/import/valid.yml +71 -0
  161. data/spec/fixtures/views/carts/_cart_footer.html.erb +18 -0
  162. data/spec/helpers/solidus_braintree/braintree_admin_helper_spec.rb +17 -0
  163. data/spec/helpers/solidus_braintree/braintree_checkout_helper_spec.rb +70 -0
  164. data/spec/models/solidus_braintree/address_spec.rb +71 -0
  165. data/spec/models/solidus_braintree/avs_result_spec.rb +317 -0
  166. data/spec/models/solidus_braintree/gateway_spec.rb +774 -0
  167. data/spec/models/solidus_braintree/response_spec.rb +280 -0
  168. data/spec/models/solidus_braintree/source_spec.rb +555 -0
  169. data/spec/models/solidus_braintree/transaction_address_spec.rb +235 -0
  170. data/spec/models/solidus_braintree/transaction_import_spec.rb +302 -0
  171. data/spec/models/solidus_braintree/transaction_spec.rb +86 -0
  172. data/spec/models/spree/store_spec.rb +14 -0
  173. data/spec/requests/spree/api/orders_controller_spec.rb +36 -0
  174. data/spec/solidus_braintree_helper.rb +7 -0
  175. data/spec/support/solidus_braintree/capybara.rb +7 -0
  176. data/spec/support/solidus_braintree/factories.rb +55 -0
  177. data/spec/support/solidus_braintree/gateway_helpers.rb +29 -0
  178. data/spec/support/solidus_braintree/order_ready_for_payment.rb +44 -0
  179. data/spec/support/solidus_braintree/order_walkthrough.rb +87 -0
  180. data/spec/support/solidus_braintree/vcr.rb +42 -0
  181. data/spec/support/solidus_braintree/with_prepended_view_fixtures.rb +19 -0
  182. data/spec/system/backend/configuration_spec.rb +23 -0
  183. data/spec/system/backend/new_payment_spec.rb +136 -0
  184. data/spec/system/frontend/braintree_credit_card_checkout_spec.rb +199 -0
  185. data/spec/system/frontend/paypal_checkout_spec.rb +169 -0
  186. data/spec/system/frontend/venmo_checkout_spec.rb +193 -0
  187. metadata +289 -255
  188. data/.travis.yml +0 -41
  189. data/LICENSE.txt +0 -21
  190. data/app/controllers/spree/api/braintree_client_token_controller.rb +0 -13
  191. data/app/helpers/braintree_view_helpers.rb +0 -20
  192. data/app/models/concerns/solidus_braintree/add_name_validation_concern.rb +0 -8
  193. data/app/models/concerns/solidus_braintree/inject_device_data_concern.rb +0 -18
  194. data/app/models/concerns/solidus_braintree/payment_braintree_nonce_concern.rb +0 -8
  195. data/app/models/concerns/solidus_braintree/permitted_attributes_concern.rb +0 -11
  196. data/app/models/concerns/solidus_braintree/skip_require_card_numbers_concern.rb +0 -14
  197. data/app/models/concerns/solidus_braintree/use_data_field_concern.rb +0 -23
  198. data/app/models/credit_card_decorator.rb +0 -3
  199. data/app/models/payment_decorator.rb +0 -2
  200. data/app/models/permitted_attributes_decorator.rb +0 -1
  201. data/app/models/solidus/gateway/braintree_gateway.rb +0 -306
  202. data/app/overrides/spree/checkout/_confirm/braintree_security.html.erb.deface +0 -9
  203. data/app/views/spree/admin/payments/source_forms/_braintree.html.erb +0 -38
  204. data/app/views/spree/admin/payments/source_views/_braintree.html.erb +0 -30
  205. data/app/views/spree/checkout/payment/_braintree.html.erb +0 -55
  206. data/app/views/spree/checkout/payment/_braintree_initialization.html.erb +0 -12
  207. data/config/initializers/braintree.rb +0 -1
  208. data/db/migrate/20150910170527_add_data_to_credit_card.rb +0 -5
  209. data/db/migrate/20160426221931_add_braintree_device_data_to_order.rb +0 -5
  210. data/lib/assets/javascripts/spree/backend/braintree/solidus_braintree.js +0 -59
  211. data/lib/assets/javascripts/spree/frontend/braintree/solidus_braintree.js +0 -144
  212. data/lib/assets/javascripts/vendor/braintree.js +0 -8
  213. data/lib/assets/stylesheets/spree/frontend/solidus_braintree.scss +0 -26
@@ -0,0 +1,86 @@
1
+ //= require spree/frontend/solidus_braintree/constants
2
+ /**
3
+ * Constructor for Venmo button object
4
+ * @constructor
5
+ * @param {object} element - The DOM element of your Venmo button
6
+ */
7
+ SolidusBraintree.VenmoButton = function(element, venmoOptions) {
8
+ this._element = element;
9
+ this._client = null;
10
+ this._venmoOptions = venmoOptions || {};
11
+
12
+ if(!this._element) {
13
+ throw new Error("Element for the Venmo button must be present on the page");
14
+ }
15
+ };
16
+
17
+ /**
18
+ * Creates the Venmo session using the provided options and enables the button
19
+ *
20
+ * @param {object} options - The options passed to tokenize when constructing
21
+ * the Venmo instance
22
+ *
23
+ * See {@link https://braintree.github.io/braintree-web/3.84.0/module-braintree-web_venmo.html#.create}
24
+ */
25
+ SolidusBraintree.VenmoButton.prototype.initialize = function() {
26
+ this._client = new SolidusBraintree.createClient({
27
+ useVenmo: true,
28
+ newBrowserTabSupported: this._venmoOptions.newBrowserTabSupported,
29
+ flow: this._venmoOptions.flow
30
+ });
31
+
32
+ return this._client.initialize().then(this.initializeCallback.bind(this));
33
+ };
34
+
35
+ SolidusBraintree.VenmoButton.prototype.initializeCallback = function() {
36
+ this._venmoInstance = this._client.getVenmoInstance();
37
+
38
+ this._element.classList.add('visible');
39
+
40
+ // Check if tokenization results already exist. This occurs when your
41
+ // checkout page is relaunched in a new tab.
42
+ if (!this._venmoOptions.newBrowserTabSupported && this._venmoInstance.hasTokenizationResult()) {
43
+ this.tokenize();
44
+ }
45
+
46
+ this._element.addEventListener('click', function(event) {
47
+ event.preventDefault();
48
+ this._element.disabled = true;
49
+ this.initializeVenmoSession();
50
+ }.bind(this), false);
51
+ };
52
+
53
+ SolidusBraintree.VenmoButton.prototype.initializeVenmoSession = function() {
54
+ this.tokenize();
55
+ };
56
+
57
+ SolidusBraintree.VenmoButton.prototype.tokenize = function() {
58
+ var venmoButton = this._element;
59
+ this._venmoInstance.tokenize().then(handleVenmoSuccess).catch(handleVenmoError).then(function () {
60
+ venmoButton.removeAttribute('disabled');
61
+ });
62
+ };
63
+
64
+ function handleVenmoSuccess(payload) {
65
+ var $paymentForm = $("#checkout_form_payment");
66
+ var $nonceField = $("#venmo_payment_method_nonce", $paymentForm);
67
+
68
+ // Disable hostedFields' and enable Venmo's inputs as they use the same fields.
69
+ // Otherwise, they will clash. (Disabled inputs are not used on form submission)
70
+ $('.hosted-fields input').each(function(_index, input) {
71
+ input.disabled = true;
72
+ });
73
+ $('.venmo-fields input').each(function(_index, input) {
74
+ input.removeAttribute('disabled');
75
+ });
76
+
77
+ // remove hostedFields submit listener, otherwise empty credit card errors occur
78
+ $paymentForm.off('submit');
79
+
80
+ $nonceField.val(payload.nonce);
81
+ $paymentForm.submit();
82
+ }
83
+
84
+ function handleVenmoError(error) {
85
+ SolidusBraintree.config.braintreeErrorHandle(error);
86
+ }
@@ -0,0 +1 @@
1
+ //= require spree/frontend/solidus_braintree/frontend
@@ -0,0 +1,62 @@
1
+ /*
2
+ Placeholder manifest file.
3
+ the installer will append this file to the app vendored assets here: 'vendor/assets/stylesheets/spree/frontend/all.css'
4
+ */
5
+
6
+ .braintree-hosted-fields .input {
7
+ border: 1px solid #d9d9db;
8
+ border-radius: 3px;
9
+ color: #5498DA;
10
+ height: 30px;
11
+ padding: 5px 10px;
12
+ }
13
+
14
+ .paypal-button-widget .paypal-button:hover {
15
+ background: transparent;
16
+ }
17
+
18
+ .apple-pay-button {
19
+ -webkit-appearance: -apple-pay-button;
20
+ -apple-pay-button-type: buy;
21
+ visibility: hidden;
22
+ display: inline-block;
23
+ min-height: 30px;
24
+ border: 1px solid black;
25
+ background-image: -webkit-named-image(apple-pay-logo-black);
26
+ background-size: 100% calc(60% + 2px);
27
+ background-repeat: no-repeat;
28
+ background-color: white;
29
+ background-position: 50% 50%;
30
+ border-radius: 5px;
31
+ padding: 0;
32
+ margin: 5px auto;
33
+ transition: background-color .15s;
34
+ width: auto;
35
+ }
36
+
37
+ .apple-pay-button.visible {
38
+ visibility: visible;
39
+ }
40
+
41
+ .venmo-button {
42
+ visibility: hidden;
43
+ border: none;
44
+ height: 48px;
45
+ background-color: transparent;
46
+ background-repeat: no-repeat;
47
+ }
48
+
49
+ .venmo-button.visible {
50
+ visibility: visible;
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
+ }
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusBraintree
4
+ class CheckoutsController < CheckoutsController
5
+ PERMITTED_PAYMENT_PARAMS = [
6
+ :payment_method_id,
7
+ { source_attributes: [
8
+ :nonce,
9
+ :payment_type
10
+ ] }
11
+ ].freeze
12
+
13
+ def update
14
+ @payment = ::Spree::PaymentCreate.new(@order, payment_params).build
15
+
16
+ if @payment.save
17
+ render plain: "ok"
18
+ else
19
+ render plain: "not-ok"
20
+ end
21
+ end
22
+
23
+ def payment_params
24
+ params.
25
+ require(:order).
26
+ require(:payments_attributes).
27
+ first.
28
+ permit(PERMITTED_PAYMENT_PARAMS)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusBraintree
4
+ class TransactionsController < StoreController
5
+ class InvalidImportError < StandardError; end
6
+
7
+ PERMITTED_BRAINTREE_TRANSACTION_PARAMS = [
8
+ :nonce,
9
+ :payment_type,
10
+ :paypal_funding_source,
11
+ :phone,
12
+ :email,
13
+ { address_attributes: [
14
+ :country_code, :country_name, :name, :city, :zip, :state_code,
15
+ :address_line_1, :address_line_2, :first_name, :last_name
16
+ ] }
17
+ ].freeze
18
+
19
+ def create
20
+ transaction = SolidusBraintree::Transaction.new transaction_params
21
+ import = SolidusBraintree::TransactionImport.new(current_order, transaction)
22
+ restart_checkout = params[:options] && params[:options][:restart_checkout] == "true"
23
+
24
+ respond_to do |format|
25
+ if import.valid?
26
+ import.import!(import_state, restart_checkout: restart_checkout)
27
+
28
+ format.html { redirect_to redirect_url(import) }
29
+ format.json { render json: { redirectUrl: redirect_url(import) } }
30
+ else
31
+ status = 422
32
+ format.html { import_error(import) }
33
+ format.json { render json: { errors: import.errors, status: status }, status: status }
34
+ end
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def import_state
41
+ params[:state] || 'confirm'
42
+ end
43
+
44
+ def import_error(import)
45
+ raise InvalidImportError,
46
+ "Import invalid: #{import.errors.full_messages.join(', ')}"
47
+ end
48
+
49
+ def redirect_url(import)
50
+ if import.order.complete?
51
+ main_app.order_url(import.order)
52
+ else
53
+ main_app.checkout_state_url(import.order.state)
54
+ end
55
+ end
56
+
57
+ def transaction_params
58
+ params.require(:transaction)
59
+ .permit(PERMITTED_BRAINTREE_TRANSACTION_PARAMS)
60
+ .merge({ payment_method: payment_method })
61
+ end
62
+
63
+ def payment_method
64
+ SolidusBraintree::Gateway.find(params[:payment_method_id])
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusBraintree
4
+ module BraintreeCheckoutHelper
5
+ def braintree_3ds_options_for(order)
6
+ ship_address = SolidusBraintree::Address.new(order.ship_address)
7
+ bill_address = SolidusBraintree::Address.new(order.bill_address)
8
+ {
9
+ nonce: nil, # populated after tokenization
10
+ bin: nil, # populated after tokenization
11
+ onLookupComplete: nil, # populated after tokenization
12
+ amount: order.total,
13
+ email: order.email,
14
+ billingAddress: {
15
+ givenName: bill_address.firstname,
16
+ surname: bill_address.lastname,
17
+ phoneNumber: bill_address.phone,
18
+ streetAddress: bill_address.address1,
19
+ extendedAddress: bill_address.address2,
20
+ locality: bill_address.city,
21
+ region: bill_address.state&.abbr,
22
+ postalCode: bill_address.zipcode,
23
+ countryCodeAlpha2: bill_address.country&.iso,
24
+ },
25
+ additionalInformation: {
26
+ shippingGivenName: ship_address.firstname,
27
+ shippingSurname: ship_address.lastname,
28
+ shippingPhone: ship_address.phone,
29
+ shippingAddress: {
30
+ streedAddress: ship_address.address1,
31
+ extendedAddress: ship_address.address2,
32
+ locality: ship_address.city,
33
+ region: ship_address.state&.abbr,
34
+ postalCode: ship_address.zipcode,
35
+ countryCodeAlpha2: ship_address.country&.iso,
36
+ }
37
+ }
38
+ }
39
+ end
40
+
41
+ def paypal_button_preference(key, store:)
42
+ store.braintree_configuration.preferences[key]
43
+ end
44
+
45
+ def venmo_button_style(store)
46
+ configuration = store.braintree_configuration
47
+ color = configuration.preferred_venmo_button_color
48
+ width = configuration.preferred_venmo_button_width
49
+
50
+ { width: width, color: color }
51
+ end
52
+
53
+ def venmo_button_asset_url(style, active: false)
54
+ prefix = 'solidus_braintree/venmo/venmo_'
55
+ active_string = active ? 'active_' : ''
56
+ path = "#{prefix}#{active_string}#{style[:color]}_button_#{style[:width]}x48.svg"
57
+ asset_path(path)
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,2 @@
1
+ <%= wallet_payment_source.payment_source.friendly_payment_type %>
2
+ <%= wallet_payment_source.payment_source.display_number %>
@@ -0,0 +1,23 @@
1
+ <% id = payment_method.id %>
2
+
3
+ <%= render "spree/shared/braintree_head_scripts" %>
4
+
5
+ <% if current_store.braintree_configuration.paypal? %>
6
+ <%= render "spree/shared/paypal_checkout_button" %>
7
+ <% end %>
8
+
9
+ <% if current_store.braintree_configuration.credit_card? %>
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
+ <%= render "spree/shared/braintree_hosted_fields", payment_method: payment_method %>
12
+ </fieldset>
13
+ <% end %>
14
+
15
+ <% if current_store.braintree_configuration.apple_pay? %>
16
+ <%= render "spree/shared/apple_pay_button", id: id %>
17
+ <% end %>
18
+
19
+ <% if current_store.braintree_configuration.venmo? %>
20
+ <%= render "spree/shared/venmo_button", payment_method: payment_method %>
21
+ <% end %>
22
+
23
+ <%= render "spree/shared/braintree_errors" %>
@@ -0,0 +1,9 @@
1
+ <%= payment.source.try(:display_payment_type) %>
2
+
3
+ <% if payment.source.try(:paypal?) %>
4
+ <% if payment.source.respond_to?(:paypal_funding_source) && payment.source.paypal_funding_source.present? %>
5
+ <%= t('spree.paypal_funding', funding: payment.source.display_paypal_funding_source) %>
6
+ <% end %>
7
+ <% elsif payment.source.try(:venmo?) %>
8
+ <%= payment.source.source_description %>
9
+ <% end %>
@@ -0,0 +1,27 @@
1
+ <% address = SolidusBraintree::Address.new(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 SolidusBraintree.createApplePayButton(applePayButtonElement, applePayOptions);
26
+ button.initialize();
27
+ </script>
@@ -0,0 +1,16 @@
1
+ <script type="text/javascript">
2
+ BraintreeError.DEFAULT = "<%= I18n.t('solidus_braintree.errors.default_error')%>"
3
+ BraintreeError.PAYPAL_POPUP_CLOSED = "<%= I18n.t('solidus_braintree.errors.paypal_popup_closed') %>"
4
+ BraintreeError.HOSTED_FIELDS_FIELDS_EMPTY = "<%= I18n.t('solidus_braintree.errors.empty_fields')%>"
5
+ BraintreeError.HOSTED_FIELDS_FIELDS_INVALID = "<%= I18n.t('solidus_braintree.errors.invalid_fields')%>"
6
+ BraintreeError.HOSTED_FIELDS_FAILED_TOKENIZATION = "<%= I18n.t('solidus_braintree.errors.invalid_card')%>"
7
+ BraintreeError.HOSTED_FIELDS_TOKENIZATION_NETWORK_ERROR = "<%= I18n.t('solidus_braintree.errors.network_error')%>"
8
+ BraintreeError.HOSTED_FIELDS_FIELD_DUPLICATE_IFRAME = "<%= I18n.t('solidus_braintree.errors.duplicate_iframe')%>"
9
+ BraintreeError.HOSTED_FIELDS_TOKENIZATION_FAIL_ON_DUPLICATE = "<%= I18n.t('solidus_braintree.errors.fail_on_duplicate')%>"
10
+ BraintreeError.HOSTED_FIELDS_TOKENIZATION_CVV_VERIFICATION_FAILED = "<%= I18n.t('solidus_braintree.errors.cvv_verification_failed')%>"
11
+ BraintreeError.THREEDS_AUTHENTICATION_FAILED = "<%= t('solidus_braintree.errors.threeds.authentication_failed') %>";
12
+ BraintreeError.THREEDS_CARDINAL_SDK_ERROR = "<%= t('solidus_braintree.errors.threeds.authentication_failed') %>";
13
+ BraintreeError.VENMO_CANCELED = "<%= t('solidus_braintree.errors.venmo.canceled') %>";
14
+ BraintreeError.VENMO_DESKTOP_CANCELED = "<%= t('solidus_braintree.errors.venmo.desktop_canceled') %>";
15
+ BraintreeError.VENMO_APP_CANCELED = "<%= t('solidus_braintree.errors.venmo.app_canceled') %>";
16
+ </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 "spree/frontend/solidus_braintree/checkout" %>
26
+ <% end %>
@@ -0,0 +1,40 @@
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}]" %>
10
+
11
+ <div class="hosted-fields">
12
+ <div class="field" data-hook="card_number">
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>
15
+ </div>
16
+
17
+ <div class="field" data-hook="card_expiration">
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>
20
+ </div>
21
+
22
+ <div class="field" data-hook="card_code">
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>
25
+ </div>
26
+
27
+ <div class="clear"></div>
28
+ <input type="hidden" name="<%= prefix %>[payment_type]" value="<%= SolidusBraintree::Source::CREDIT_CARD %>">
29
+ <input type="hidden" id="payment_method_nonce" name="<%= prefix %>[nonce]">
30
+ <input type="hidden" id="device_data" name="<%= prefix %>[device_data]">
31
+ </div>
32
+
33
+
34
+ <script>
35
+ <% if current_store.braintree_configuration.three_d_secure? %>
36
+ var threeDSecureOptions = <%= raw braintree_3ds_options_for(current_order).to_json %>;
37
+ <% end -%>
38
+ var credit_card_fields_style = <%= raw payment_method.preferred_credit_card_fields_style.to_json %>
39
+ var placeholder_text = <%= raw payment_method.preferred_placeholder_text.to_json %>
40
+ </script>
@@ -0,0 +1,38 @@
1
+ <%= render "spree/shared/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: '<%= SolidusBraintree::Gateway.first.preferred_paypal_flow %>',
9
+ amount: '<%= current_order.total %>',
10
+ currency: '<%= current_order.currency %>',
11
+ enableShippingAddress: true,
12
+ buyerCountry: '<%= SolidusBraintree::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: <%= SolidusBraintree::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 SolidusBraintree.createPaypalButton(
32
+ document.querySelector("#paypal-button"),
33
+ paypalOptions,
34
+ options
35
+ )
36
+
37
+ button.initialize();
38
+ </script>
@@ -0,0 +1,32 @@
1
+ <div id="paypal-button"></div>
2
+ <div data-pp-message data-pp-placement="payment" data-pp-amount="<%= @order.total %>"></div>
3
+
4
+ <script>
5
+ var address = <%= sanitize SolidusBraintree::Address.new(current_order.ship_address).to_json %>
6
+
7
+ var paypalOptions = {
8
+ flow: '<%= SolidusBraintree::Gateway.first.preferred_paypal_flow %>',
9
+ amount: '<%= current_order.total %>',
10
+ currency: '<%= current_order.currency %>',
11
+ enableShippingAddress: true,
12
+ venmoFunding: <%= SolidusBraintree::Gateway.first.preferred_enable_venmo_funding %>,
13
+ buyerCountry: '<%= SolidusBraintree::Gateway.first.preferred_force_buyer_country %>',
14
+ shippingAddressOverride: address,
15
+ shippingAddressEditable: false,
16
+ environment: '<%= Rails.env.production? ? "production" : "sandbox" %>',
17
+ locale: '<%= paypal_button_preference(:paypal_button_locale, store: current_store) %>',
18
+ style: {
19
+ color: '<%= paypal_button_preference(:paypal_button_color, store: current_store) %>',
20
+ shape: '<%= paypal_button_preference(:paypal_button_shape, store: current_store) %>',
21
+ label: '<%= paypal_button_preference(:paypal_button_label, store: current_store) %>',
22
+ layout: '<%= paypal_button_preference(:paypal_button_layout, store: current_store) %>',
23
+ <% if paypal_button_preference(:paypal_button_layout, store: current_store) == "horizontal" %>
24
+ tagline: '<%= paypal_button_preference(:paypal_button_tagline, store: current_store) %>',
25
+ <% end %>
26
+ messaging: '<%= paypal_button_preference(:paypal_button_messaging, store: current_store) %>'
27
+ }
28
+ }
29
+
30
+ var button = new SolidusBraintree.createPaypalButton(document.querySelector("#paypal-button"), paypalOptions);
31
+ button.initialize();
32
+ </script>
@@ -0,0 +1,13 @@
1
+ <%= render "spree/shared/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 SolidusBraintree.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="<%= SolidusBraintree::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: <%= SolidusBraintree::Gateway.first.preferred_venmo_new_tab_support %>,
29
+ flow: '<%= SolidusBraintree::Gateway.first.preferred_paypal_flow %>'
30
+ };
31
+ var button = new SolidusBraintree.createVenmoButton(venmoButtonElement, venmoOptions);
32
+ button.initialize();
33
+ </script>
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ SolidusBraintree.configure do |config|
4
+ # TODO: Remember to change this with the actual preferences you have implemented!
5
+ # config.sample_preference = 'sample_value'
6
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusBraintree
4
+ module CountryMapper
5
+ extend ActiveSupport::Concern
6
+
7
+ USA_VARIANTS = [
8
+ "the united states of america",
9
+ "united states of america",
10
+ "the united states",
11
+ "united states",
12
+ "us of a",
13
+ "u.s.a.",
14
+ "usa",
15
+ "u.s.",
16
+ "us"
17
+ ].freeze
18
+
19
+ CANADA_VARIANTS = [
20
+ "canada",
21
+ "ca"
22
+ ].freeze
23
+
24
+ # Generates a hash mapping each variant of the country name to the same ISO
25
+ # ie: { "usa" => "US", "united states" => "US", "canada" => "CA", ... }
26
+ COUNTRY_MAP = {
27
+ USA_VARIANTS => "US",
28
+ CANADA_VARIANTS => "CA"
29
+ }.flat_map { |variants, iso| variants.map { |v| [v, iso] } }.to_h
30
+
31
+ included do
32
+ def iso_from_name(country_name)
33
+ COUNTRY_MAP[country_name.downcase.strip]
34
+ end
35
+ end
36
+ end
37
+ end