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
data/README.md CHANGED
@@ -1,51 +1,416 @@
1
- # Solidus Braintree
1
+ # SolidusBraintree
2
2
 
3
- [![Build Status](https://travis-ci.org/solidusio/solidus_braintree.svg?branch=master)](https://travis-ci.org/solidusio/solidus_braintree)
3
+ [![CircleCI](https://circleci.com/gh/solidusio/solidus_braintree.svg?style=shield)](https://circleci.com/gh/solidusio/solidus_braintree)
4
+ [![codecov](https://codecov.io/gh/solidusio/solidus_braintree/branch/master/graph/badge.svg)](https://codecov.io/gh/solidusio/solidus_braintree)
4
5
 
5
- `solidus_braintree` is a gem that adds [Braintree v.zero](https://www.braintreepayments.com/v-zero) support to the [solidus](http://solidus.io/) E-commerce platform.
6
+ `solidus_braintree` is an extension that adds support for using [Braintree](https://www.braintreepayments.com) as a payment source in your [Solidus](https://solidus.io/) store. It uses Braintree's [JavaScript v3 SDK](https://braintree.github.io/braintree-web/current/) to support the following Braintree payment method types:
6
7
 
7
- It provides support for credit card and Paypal payment methods via the `Spree::CreditCard`
8
-
9
- It will add the braintree-drop-in form for payment methods in the payment form of spree/backend. Spree front-end is currently unsupported.
8
+ * [Apple Pay](https://developer.paypal.com/braintree/docs/guides/apple-pay/overview)
9
+ * [Venmo](https://developer.paypal.com/braintree/docs/guides/venmo/overview)
10
+ * [PayPal Checkout](https://developer.paypal.com/braintree/docs/guides/paypal/overview/javascript/v3)
11
+ * [Credit Cards](https://developer.paypal.com/braintree/docs/guides/credit-cards/overview) via [Hosted Forms](https://developer.paypal.com/braintree/docs/guides/hosted-fields/overview)
10
12
 
11
13
  ## Installation
12
14
 
13
- Add this line to your solidus application's Gemfile:
15
+ Add solidus_braintree to your Gemfile:
16
+
17
+ ```ruby
18
+ gem 'solidus_braintree'
19
+ ```
20
+
21
+ Bundle your dependencies and run the installation generator:
22
+
23
+ ```shell
24
+ bundle
25
+ bundle exec rails g solidus_braintree:install
26
+ ```
27
+
28
+ ## Upgrading (including migration from SolidusPaypalBraintree)
29
+
30
+ See https://github.com/solidusio/solidus_braintree/wiki/Upgrading.
31
+
32
+ ## Compatibility
33
+
34
+ Here are the versions of SolidusBraintree and their compatible Solidus and frontend versions:
35
+
36
+ | Version | Maintenance Status | Frontend | Branch |
37
+ |----------------------|-----------------------------|------------------------|----------|
38
+ | SolidusBraintree 3.0 | New features | SolidusStarterFrontend | [master] |
39
+ | SolidusBraintree 2.0 | Security patches, bug fixes | SolidusFrontend | [v2.x] |
40
+ | SolidusBraintree 1.2 | Deprecated | SolidusFrontend | [v1.x] |
41
+
42
+ [v1.x]: https://github.com/solidusio/solidus_braintree/tree/v1.x
43
+ [v2.x]: https://github.com/solidusio/solidus_braintree/tree/v2.x
44
+ [master]: https://github.com/solidusio/solidus_braintree/tree/master
45
+
46
+ ## Basic Setup
47
+
48
+ ### Retrieve Braintree account details
49
+ You'll need the following account details:
50
+ - `Merchant ID`
51
+ - `Public key`
52
+ - `Private key`
53
+
54
+ These values can be obtained by logging in to your Braintree account, going
55
+ to `Account -> My User` and clicking `View Authorizations` in the **API Keys,
56
+ Tokenization Keys, Encryption Keys** section.
57
+
58
+ ### Create a new payment method
59
+ Payment methods can accept preferences either directly entered in admin, or from a static source in code. For most projects we recommend using a static source, so that sensitive account credentials are not stored in the database.
60
+
61
+ 1. Set static preferences in an initializer
62
+ ```ruby
63
+ # config/initializers/spree.rb
64
+ Rails.application.config.to_prepare do
65
+ Spree::Config.static_model_preferences.add(
66
+ SolidusBraintree::Gateway,
67
+ 'braintree_credentials', {
68
+ environment: Rails.env.production? ? 'production' : 'sandbox',
69
+ merchant_id: ENV['BRAINTREE_MERCHANT_ID'],
70
+ public_key: ENV['BRAINTREE_PUBLIC_KEY'],
71
+ private_key: ENV['BRAINTREE_PRIVATE_KEY'],
72
+ paypal_flow: 'vault', # 'checkout' is accepted too
73
+ use_data_collector: true # Fingerprint the user's browser when using Paypal
74
+ }
75
+ )
76
+ end
77
+ ```
78
+ Other optional preferences are discussed below.
79
+
80
+ 2. Visit `/admin/payment_methods/new`
81
+
82
+ 3. Set `provider` to SolidusBraintree::Gateway
83
+
84
+ 4. Click "Save"
85
+
86
+ 5. Choose `braintree_credentials` from the `Preference Source` select
87
+
88
+ 6. Click `Update` to save
89
+
90
+ Alternatively, create a payment method from the Rails console with:
91
+ ```ruby
92
+ SolidusBraintree::Gateway.new(
93
+ name: "Braintree",
94
+ preference_source: "braintree_credentials"
95
+ ).save
96
+ ```
97
+
98
+ ### Configure payment types
99
+ Your payment method can accept payments in three ways: through Paypal, through ApplePay, or with credit card details entered directly by the customer. By default all are disabled for all your site's stores. Before proceeding to checkout, ensure you've created a Braintree configuration for your store:
100
+
101
+ 1. Visit /solidus_braintree/configurations/list
102
+
103
+ 2. Check the payment types you'd like to accept. If your site has multiple stores, there'll be a set of checkboxes for each.
104
+
105
+ 3. Click `Save changes` to save
106
+
107
+ Or from the console:
108
+ ```ruby
109
+ Spree::Store.all.each do |store|
110
+ store.create_braintree_configuration(
111
+ credit_card: true,
112
+ paypal: true,
113
+ apple_pay: true,
114
+ venmo: true
115
+ )
116
+ end
117
+ ```
118
+
119
+ 4. If your site uses an unmodified Solidus Starter Frontend, it should now be ready to take payments. See below for more information on configuring Paypal and ApplePay.
120
+
121
+ 5. Typical Solidus sites will have customized frontend code, and may require some additional work. Use `lib/views/frontend/spree/checkout/payment/_braintree.html.erb` and `app/assets/javascripts/solidus_braintree/checkout.js` as models.
122
+
123
+ ## Apple Pay
124
+ ### Developing with Apple Pay
125
+ You'll need the following:
126
+ - A device running iOS 10+.
127
+ - An Apple Pay sandbox account. You can check out Apple's [documentation](https://developer.apple.com/support/apple-pay-sandbox/) for additional help in performing this step.
128
+ - A site served via HTTPS. To set this up for development we recommend setting up a reverse proxy server. There are [lots of guides](https://www.google.ca/search?q=nginx+reverse+proxy+ssl+localhost) on how this can be achieved.
129
+ - A Braintree sandbox account with Apple Pay enabled (`Settings>Processing`) and configured (`Settings>Processing>Options`) with your Apple Merchant ID and the HTTPS domain for your site.
130
+ - A sandbox user logged in to your device, with a [test card](https://developer.apple.com/support/apple-pay-sandbox/) in its Wallet
131
+
132
+ ### Enabling Apple Pay for custom frontends
133
+ The following is a relatively bare-bones implementation to enable Apple Pay on the frontend:
134
+
135
+ ```html
136
+ <% if current_store.braintree_configuration.apple_pay? %>
137
+ <script src="https://js.braintreegateway.com/web/3.84.0/js/apple-pay.min.js"></script>
138
+
139
+ <button id="apple-pay-button" class="apple-pay-button"></button>
140
+
141
+ <script>
142
+ var applePayButtonElement = document.getElementById('apple-pay-button');
143
+ var applePayOptions = {
144
+ paymentMethodId: <%= id %>,
145
+ storeName: "<%= current_store.name %>",
146
+ orderEmail: "<%= current_order.email %>",
147
+ amount: "<%= current_order.total %>",
148
+ shippingContact: {
149
+ emailAddress: '<%= current_order.email %>',
150
+ givenName: '<%= address.firstname %>',
151
+ familyName: '<%= address.lastname %>',
152
+ phoneNumber: '<%= address.phone %>',
153
+ addressLines: ['<%= address.address1 %>','<%= address.address2 %>'],
154
+ locality: '<%= address.city %>',
155
+ administrativeArea: '<%= address.state.name %>',
156
+ postalCode: '<%= address.zipcode %>',
157
+ country: '<%= address.country.name %>',
158
+ countryCode: '<%= address.country.iso %>'
159
+ }
160
+ };
161
+ var button = new SolidusBraintree.createApplePayButton(applePayButtonElement, applePayOptions);
162
+ button.initialize();
163
+ </script>
164
+ <% end %>
165
+ ```
166
+
167
+ ### Further Apple Pay information
168
+ Braintree has some [excellent documentation](https://developers.braintreepayments.com/guides/apple-pay/configuration/javascript/v3) on what you'll need to do to get Apple Pay up and running.
169
+
170
+ For additional information check out [Apple's documentation](https://developer.apple.com/reference/applepayjs/) and [Braintree's documentation](https://developers.braintreepayments.com/guides/apple-pay/client-side/javascript/v3).
171
+
172
+ ## Venmo
173
+ There are two ways for users to use Venmo for payments:
174
+ 1. Braintree's native Venmo integration, which supports vaulting of payment sources. [See more.](#Braintree's-Venmo)
175
+ 2. Through the PayPal buttons when using checkout flow, therefore doesn't support vaulting. [See more.](#PayPal-financing-options)
176
+
177
+ ### PayPal's Venmo financing option
178
+ To add Venmo for PayPal, [see here](#paypal-venmo)
179
+
180
+ ### Braintree's Venmo
181
+ #### Note
182
+ - Only available as a financing option on the checkout page; Venmo currently does not support shipping callbacks so it cannot be on the cart page.
183
+ - Currently available to US merchants and buyers and there are also other prequisites.
184
+ - https://developer.paypal.com/docs/business/checkout/pay-with-venmo/#eligibility
185
+ - https://developer.paypal.com/braintree/articles/guides/payment-methods/venmo#availability
186
+
187
+ #### Integration:
188
+ 1. Enable Venmo in your [Braintree account](https://developer.paypal.com/braintree/articles/guides/payment-methods/venmo#setup)
189
+ 2. Enable Venmo in your [store's Braintree configuration](#configure-payment-types).
190
+ 3. Ensure your Braintree API credentials are in the Braintree payment method.
191
+ 4. Set your Braintree payment method's preference of `preferred_venmo_new_tab_support` to `false` if your store cannot handle Venmo returning a user to a new tab after payment. This may be because your website is a single-page applicaiton (SPA). On mobile, the user may be returned to the same store tab if their browser supports it, otherwise a new tab will be created (unless you have this preference as `false`).
192
+
193
+ By default your default Venmo business account will be used. If you want to use a non-default profile, override
194
+ the `SolidusBraintree::Gateway` `#venmo_business_profile_id` method with its id.
195
+
196
+ #### Testing
197
+ Test the following scenarios:
198
+ - Ensure the Venmo checkout button opens a modal with a QR code and is closeable.
199
+ - Do a full transaction
200
+ - Ensure that you can also save the payment source in the user wallet.
201
+ - Ensure the saved Venmo wallet payment source loads in the partial correctly.
202
+ - Ensure the saved Venmo payment source can be reused for another order.
203
+ - Test doing transactions on the admin
204
+ - Testing voiding and refunding Venmo transactions
205
+
206
+ You'll need the Venmo app in order to fully test the integration. However, if you are outside of the US, this is not an option. You can fake the tokenization by:
207
+ - Altering the `venmo_button.js` file to call the `handleVenmoSuccess` function instead of tokenizing; or
208
+ - Manually doing its steps:
209
+ 1. Update the #venmo_payment_method_nonce hidden input value to "fake-venmo-account-nonce".
210
+ 2. Remove the disabled attributes from the venmo-fields inputs.
211
+ 3. If you have hosted fields on the page (`credit_card` enabled in Braintree configuration), remove it's submit button listener:
212
+ `$('#checkout_form_payment').off('submit');`
213
+
214
+ [More information](https://developer.paypal.com/braintree/articles/guides/payment-methods/venmo#availability)
215
+
216
+ #### Customization:
217
+ In your [store's Braintree configuration](#configure-payment-types), you can customize the Venmo checkout button's color and width.
218
+
219
+ Note, other images such as Venmo's full logo and shortened "V" logo are included in the assets.
14
220
 
221
+ Ensure that you follow [Venmo's guidelines](https://developer.paypal.com/braintree/docs/files/venmo-merchant-integration-guidelines.pdf) when making other style changes, otherwise failing to comply can lead to an interruption of your Venmo service.
222
+
223
+ ## PayPal
224
+
225
+ A default checkout view is provided that will display PayPal as a payment option.
226
+ It will only be displayed if the `SolidusBraintree::Gateway` payment
227
+ method is configured to display on the frontend and PayPal is enabled in the
228
+ store's configuration.
229
+
230
+ You can find button configuration options in
231
+ `/solidus_braintree/configurations/list` if you want to change the color,
232
+ shape, layout, and a few other options. For more information check out
233
+ [PayPal's documentation](https://developer.paypal.com/docs/platforms/checkout/reference/style-guide/#layout).
234
+
235
+ Keep in mind that:
236
+ - `paypal_button_tagline` does not work when the `paypal_button_layout` is set to `vertical`, and will be ignored; and
237
+ - `paypal_button_layout` of `horizontal` limits financing options/buttons to 2, where as `vertical` is 4.
238
+ Other available financing options after the limit will not be rendered in the PayPal's iframe DOM.
239
+
240
+ The checkout view
241
+ [initializes the PayPal button](/lib/views/frontend/spree/checkout/payment/_braintree.html.erb)
242
+ using the
243
+ [Vault flow](https://developers.braintreepayments.com/guides/paypal/overview/javascript/v3),
244
+ which allows the source to be reused. Please note that PayPal messaging is disabled with vault flow. If you want, you can use [Checkout with PayPal](https://developers.braintreepayments.com/guides/paypal/checkout-with-paypal/javascript/v3)
245
+ instead, which doesn't allow you to reuse sources but allows your customers to pay with their PayPal
246
+ balance and with PayPal financing options ([see setup instructions](#create-a-new-payment-method)). More information about other [financing options below](#paypal-financing-options).
247
+
248
+ If you are creating your own checkout view or would like to customize the
249
+ [options that get passed to tokenize](https://braintree.github.io/braintree-web/3.6.3/PayPal.html#tokenize)
250
+ , you can initialize your own using the `CreatePaypalButton` JS object:
251
+
252
+ ```javascript
253
+ var paypalOptions = {
254
+ // your configuration options here
255
+ }
256
+
257
+ var button = new SolidusBraintree.createPaypalButton(document.querySelector("#your-button-id"), paypalOptions);
258
+
259
+ button.initialize();
260
+ ```
261
+
262
+ ### Express checkout from the cart
263
+
264
+ A PayPal button can also be included on the cart view to enable express checkouts:
265
+ ```ruby
266
+ render "spree/shared/paypal_cart_button"
267
+ ```
268
+
269
+ ### PayPal financing options
270
+ When using 'checkout' `paypal flow` and not 'vault'. Your customers can have different finance options such as
271
+ - paylater
272
+ - Venmo
273
+
274
+ #### PayPal Venmo
275
+ Venmo is currently available to US merchants and buyers. There are also other [prequisites](https://developer.paypal.com/docs/business/checkout/pay-with-venmo/#eligibility).
276
+
277
+ By default, the extension and Braintree will try to render a Venmo button to buyers when prequisites are met and you have enabled it in your Braintree account).
278
+
279
+ Set the SolidusBraintree `PaymentMethod` `enable_venmo_funding` preference to:
280
+ - `enabled`, available as a PayPal funding option (if other prequisites are met); or
281
+ - `disabled` (default).
282
+
283
+ Note, Venmo is currently only available as a financing option on the checkout page; Venmo currently does not support shipping callbacks so it cannot be on the cart page.
284
+
285
+ [_As Venmo is only available in the US, you may want to mock your location for testing_](#mocking-your-buyer-country)
286
+
287
+ ### PayPal Financing Messaging
288
+
289
+ PayPal offers an [on-site messaging component](https://www.paypal.com/us/webapps/mpp/on-site-messaging) to notify the customer that there are financing options available. This component is included in both the cart and checkout partials, but is disabled by default. To enable this option, you'll need to use the `checkout` flow, and set the `paypal button messaging` option to `true` in your Braintree configuration.
290
+
291
+ You can also include this view partial to implement this messaging component anywhere - for instance, on the product page:
15
292
  ```ruby
16
- gem "solidus_braintree"
293
+ render "spree/shared/paypal_messaging, options: {total: @product.price, placement: "product", currency: 'USD'}"
17
294
  ```
18
295
 
19
- And then execute:
296
+ While we provide the messaging component on the payment buttons for cart and checkout, you're expected to move these to where they make the most sense for your frontend. PayPal recommends keeping the messaging directly below wherever the order or product total is located.
20
297
 
21
- $ bundle
22
- $ bundle exec rails g solidus_braintree:install
298
+ #### PayPal configuration
23
299
 
300
+ If your store requires the [phone number into user addresses](https://github.com/solidusio/solidus/blob/859143f3f061de79cc1b385234599422b8ae8e21/core/app/models/spree/address.rb#L151-L153)
301
+ you'll need to configure PayPal to return the phone back when it returns the
302
+ address used by the user:
24
303
 
25
- ## Fraud detection
304
+ 1. Log into your PayPal account
305
+ 2. Hover over the user in the Navbar to get the dropdown
306
+ 3. Click on Account Settings
307
+ 4. In the left panel under Products & Services, click Website Payments
308
+ 5. Click Update for Website Preferences
309
+ 6. Set Contact Telephone to `On (Required Field)` or `On (Optional Field)`
26
310
 
27
- This gem has support for the advanced fraud tools flow from Braintree, to activate
28
- fully the associated Braintree account must enable advanced fraud tools in the
29
- Control Panel.
311
+ Using the option `Off` will not make the address valid and will raise a
312
+ validation error.
30
313
 
31
- ## Usage
314
+ #### Disabling the data collector
32
315
 
33
- This gem extends your solidus application by adding a `POST /api/payment_client_token` endpoint to you application to generate Braintree payment client token. This endpoint requires an authentication token in your request header.
316
+ For fraud prevention, PayPal recommends using a data collector to collect device
317
+ information, which we've included by default. You're able to turn off the PayPal
318
+ data collector on the payment method preferences if you desire. If you use
319
+ static preferences, add `use_data_collector: false` to your initializer.
34
320
 
35
- It creates a new `PaymentMethod` class called `Solidus::Gateway::BraintreeGateway`. You can configure this payment method in the admin and add your Braintree public/private keys and merchant id. The admin will render a Braintree dropin container when prompting you to create an order payment.
321
+ ## Credit cards
36
322
 
37
- It adds a json or text `data` field on `Spree::CreditCard` for storing additional information received from Braintree for addtional payment methods.
323
+ ### Hosted Fields Styling
324
+ You can style the Braintree credit card fields by using the `credit_card_fields_style` preference on the payment method. The `credit_card_fields_style` will be passed to the `style` key when initializing the credit card fields. You can find more information about styling hosted fields can be found [here.](https://developers.braintreepayments.com/guides/hosted-fields/styling/javascript/v3)
325
+
326
+ You can also use the `placeholder_text` preference on the payment method to set the placeholder text you'd like to use for each of the hosted fields. You'll pass the field name in as the key, and the placeholder text you'd like to use as the value. For example:
327
+ ```ruby
328
+ { number: "Enter card number", cvv: "Enter CVV", expirationDate: "mm/yy" }
329
+ ```
330
+
331
+ ### 3D Secure
332
+
333
+ This gem supports [3D Secure 2](https://developers.braintreepayments.com/guides/3d-secure/overview),
334
+ which satisfies the [Strong Customer Authentication (SCA)](https://www.braintreepayments.com/blog/getting-up-to-speed-on-psd2-regulation-2/)
335
+ requirements introduced by PSD2.
336
+
337
+ 3D Secure can be enabled from Solidus Admin -> Braintree (left-side menu) ->
338
+ tick _3D Secure_ checkbox.
339
+
340
+ Once enabled, you can use the following card numbers to test 3DS 2 on your
341
+ client side in sandbox:
342
+ https://developers.braintreepayments.com/guides/3d-secure/migration/javascript/v3#client-side-sandbox-testing.
343
+
344
+ ## Optional configuration
345
+
346
+ ### Accepting multiple currencies
347
+ The payment method also provides an optional preference `merchant_currency_map`.
348
+ This preference allows users to provide different Merchant Account Ids for
349
+ different currencies. If you only plan to accept payment in one currency, the
350
+ defaut Merchant Account Id will be used and you can omit this option.
351
+ An example of setting this preference can be found
352
+ [here](https://github.com/solidusio/solidus_braintree/blob/bf5fe0e154d38f7c498f1c54450bb4de7608ff04/spec/support/gateway_helpers.rb#L11-L13).
353
+
354
+ In addition to this, you can also specify different PayPal accounts for each
355
+ currency by using the `paypal_payee_email_map` preference. If you only want
356
+ to use one PayPal account for all currencies, then you can ignore this option.
357
+ You can find an example of setting this preference [here](https://github.com/solidusio/solidus_braintree/blob/bf5fe0e154d38f7c498f1c54450bb4de7608ff04/spec/support/gateway_helpers.rb#L14-L16).
358
+
359
+ ### Default store configuration
360
+ The migrations for this gem will add a default configuration to all stores that
361
+ has each payment type disabled. It also adds a `before_create` callback to
362
+ `Spree::Store` that builds a default configuration. You can customize the
363
+ default configuration that gets created by overriding the private
364
+ `build_default_configuration` method on `Spree::Store`.
365
+
366
+ ## Testing
367
+
368
+ To run the specs it is required to set the Braintree test account data in these environment variables:
369
+ `BRAINTREE_PUBLIC_KEY`, `BRAINTREE_PRIVATE_KEY`, `BRAINTREE_MERCHANT_ID` and `BRAINTREE_PAYPAL_PAYEE_EMAIL`
370
+
371
+ First bundle your dependencies, then run `rake`. `rake` will default to building the dummy app if it does not exist, then it will run specs, and [Rubocop](https://github.com/bbatsov/rubocop) static code analysis. The dummy app can be regenerated by using `rake test_app`.
372
+
373
+ ```shell
374
+ bundle
375
+ bundle exec rake
376
+ ```
377
+
378
+ When testing your applications integration with this extension you may use it's factories.
379
+ Simply add this require statement to your spec_helper:
380
+
381
+ ```ruby
382
+ require 'solidus_braintree/factories'
383
+ ```
38
384
 
39
385
  ## Development
40
386
 
41
- After checking out the repo, run `bin/setup` to install dependencies. To run tests, first generate a test app by running `rake test_app`. Then, run `rake rspec` which will run the test suite. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
387
+ ### Mocking your buyer country
388
+ PayPal looks at the buyer's IP geolocation to determine what funding sources should be available to them. Because for example, Venmo is currently only available to US buyers. Because of this, you may want to pretend that you are from US so you can check if Venmo is correctly integrated for these customers. To do this, set the payment method's preference of `force_buyer_country` to "US". See more information about preferences above.
389
+
390
+ This preference has no effect on production.
391
+
392
+ ### Running the sandbox
393
+
394
+ To run this extension in a sandboxed Solidus application, you can run `bin/sandbox`. The path for
395
+ the sandbox app is `./sandbox` and `bin/rails` will forward any Rails commands to
396
+ `sandbox/bin/rails`.
397
+
398
+ Here's an example:
399
+
400
+ ```
401
+ $ bin/rails server
402
+ => Booting Puma
403
+ => Rails 7.0.4 application starting in development
404
+ * Listening on tcp://127.0.0.1:3000
405
+ Use Ctrl-C to stop
406
+ ```
407
+
42
408
 
43
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
409
+ ### Releasing new versions
44
410
 
45
- ## Contributing
411
+ Please refer to the dedicated [page](https://github.com/solidusio/solidus/wiki/How-to-release-extensions) on Solidus wiki.
46
412
 
47
- Bug reports and pull requests are welcome on GitHub at https://github.com/solidusio/solidus_braintree.
48
413
 
49
414
  ## License
50
415
 
51
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
416
+ Copyright (c) 2016-2020 Stembolt and others contributors, released under the New BSD License
data/Rakefile CHANGED
@@ -1,21 +1,11 @@
1
- require "rspec/core/rake_task"
2
- require 'spree/testing_support/extension_rake'
1
+ # frozen_string_literal: true
3
2
 
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- require 'bundler'
7
- Bundler::GemHelper.install_tasks
3
+ require 'solidus_dev_support/rake_tasks'
4
+ SolidusDevSupport::RakeTasks.install
8
5
 
9
6
  task :default do
10
- if Dir["spec/dummy"].empty?
11
- Rake::Task[:test_app].invoke
12
- Dir.chdir("../../")
7
+ require 'bundler'
8
+ Bundler.with_unbundled_env do
9
+ sh 'bin/rspec'
13
10
  end
14
- Rake::Task[:spec].invoke
15
- end
16
-
17
- desc "Generates a dummy app for testing"
18
- task :test_app do
19
- ENV['LIB_NAME'] = 'solidus_braintree'
20
- Rake::Task['extension:test_app'].invoke
21
11
  end
File without changes