solidus_braintree 1.2.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (206) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +47 -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 +20 -10
  7. data/.rspec +1 -1
  8. data/.rubocop.yml +79 -0
  9. data/CHANGELOG.md +178 -18
  10. data/Gemfile +35 -17
  11. data/LICENSE +26 -0
  12. data/README.md +389 -24
  13. data/Rakefile +4 -19
  14. data/app/assets/config/solidus_braintree_manifest.js +1 -0
  15. data/app/assets/images/solidus_braintree/venmo/venmo_active_blue_button_280x48.svg +19 -0
  16. data/app/assets/images/solidus_braintree/venmo/venmo_active_blue_button_320x48.svg +19 -0
  17. data/app/assets/images/solidus_braintree/venmo/venmo_active_blue_button_375x48.svg +19 -0
  18. data/app/assets/images/solidus_braintree/venmo/venmo_active_white_button_280x48.svg +19 -0
  19. data/app/assets/images/solidus_braintree/venmo/venmo_active_white_button_320x48.svg +19 -0
  20. data/app/assets/images/solidus_braintree/venmo/venmo_active_white_button_375x48.svg +19 -0
  21. data/app/assets/images/solidus_braintree/venmo/venmo_blue_acceptance_mark.svg +15 -0
  22. data/app/assets/images/solidus_braintree/venmo/venmo_blue_button_280x48.svg +19 -0
  23. data/app/assets/images/solidus_braintree/venmo/venmo_blue_button_320x48.svg +19 -0
  24. data/app/assets/images/solidus_braintree/venmo/venmo_blue_button_375x48.svg +19 -0
  25. data/app/assets/images/solidus_braintree/venmo/venmo_blue_logo.svg +18 -0
  26. data/app/assets/images/solidus_braintree/venmo/venmo_white_acceptance_mark.svg +20 -0
  27. data/app/assets/images/solidus_braintree/venmo/venmo_white_button_280x48.svg +19 -0
  28. data/app/assets/images/solidus_braintree/venmo/venmo_white_button_320x48.svg +19 -0
  29. data/app/assets/images/solidus_braintree/venmo/venmo_white_button_375x48.svg +19 -0
  30. data/app/assets/images/solidus_braintree/venmo/venmo_white_logo.svg +18 -0
  31. data/app/assets/javascripts/solidus_braintree/apple_pay_button.js +179 -0
  32. data/app/assets/javascripts/solidus_braintree/checkout.js +108 -0
  33. data/app/assets/javascripts/solidus_braintree/client.js +239 -0
  34. data/app/assets/javascripts/solidus_braintree/constants.js +89 -0
  35. data/app/assets/javascripts/solidus_braintree/frontend.js +14 -0
  36. data/app/assets/javascripts/solidus_braintree/hosted_form.js +46 -0
  37. data/app/assets/javascripts/solidus_braintree/paypal_button.js +178 -0
  38. data/app/assets/javascripts/solidus_braintree/paypal_messaging.js +22 -0
  39. data/app/assets/javascripts/solidus_braintree/promise.js +20 -0
  40. data/app/assets/javascripts/solidus_braintree/venmo_button.js +86 -0
  41. data/app/assets/javascripts/spree/backend/solidus_braintree.js +96 -0
  42. data/app/assets/javascripts/spree/frontend/paypal_button.js +34 -0
  43. data/app/assets/javascripts/spree/frontend/solidus_braintree.js +1 -0
  44. data/app/assets/stylesheets/spree/backend/solidus_braintree.scss +28 -0
  45. data/app/assets/stylesheets/spree/frontend/solidus_braintree.scss +51 -0
  46. data/app/decorators/controllers/solidus_braintree/admin_payments_controller_decorator.rb +11 -0
  47. data/app/decorators/controllers/solidus_braintree/checkout_controller_decorator.rb +11 -0
  48. data/app/decorators/controllers/solidus_braintree/client_tokens_controller.rb +41 -0
  49. data/app/decorators/controllers/solidus_braintree/orders_controller_decorator.rb +11 -0
  50. data/app/decorators/models/solidus_braintree/spree/store_decorator.rb +20 -0
  51. data/app/decorators/models/solidus_braintree/spree/user_decorator.rb +13 -0
  52. data/app/helpers/solidus_braintree/braintree_admin_helper.rb +23 -0
  53. data/app/helpers/solidus_braintree/braintree_checkout_helper.rb +60 -0
  54. data/app/models/application_record.rb +5 -0
  55. data/app/models/solidus_braintree/address.rb +64 -0
  56. data/app/models/solidus_braintree/avs_result.rb +69 -0
  57. data/app/models/solidus_braintree/configuration.rb +39 -0
  58. data/app/models/solidus_braintree/customer.rb +8 -0
  59. data/app/models/solidus_braintree/gateway.rb +433 -0
  60. data/app/models/solidus_braintree/response.rb +80 -0
  61. data/app/models/solidus_braintree/source.rb +135 -0
  62. data/app/models/solidus_braintree/transaction.rb +31 -0
  63. data/app/models/solidus_braintree/transaction_address.rb +88 -0
  64. data/app/models/solidus_braintree/transaction_import.rb +98 -0
  65. data/app/overrides/spree/payments/payment/add_paypal_funding_source_to_payment.rb +9 -0
  66. data/app/views/spree/api/payments/source_views/_braintree.json.jbuilder +3 -0
  67. data/app/views/spree/checkout/existing_payment/_braintree.html.erb +10 -0
  68. data/app/views/spree/shared/_apple_pay_button.html.erb +27 -0
  69. data/app/views/spree/shared/_braintree_errors.html.erb +16 -0
  70. data/app/views/spree/shared/_braintree_head_scripts.html.erb +26 -0
  71. data/app/views/spree/shared/_braintree_hosted_fields.html.erb +43 -0
  72. data/app/views/spree/shared/_paypal_cart_button.html.erb +38 -0
  73. data/app/views/spree/shared/_paypal_messaging.html.erb +13 -0
  74. data/app/views/spree/shared/_venmo_button.html.erb +33 -0
  75. data/bin/console +4 -1
  76. data/bin/rails +5 -5
  77. data/bin/rails-engine +13 -0
  78. data/bin/rails-sandbox +16 -0
  79. data/bin/rake +7 -0
  80. data/bin/sandbox +103 -0
  81. data/bin/setup +5 -4
  82. data/config/locales/en.yml +94 -2
  83. data/config/locales/it.yml +56 -0
  84. data/config/routes.rb +12 -3
  85. data/db/migrate/20160830061749_create_solidus_paypal_braintree_sources.rb +16 -0
  86. data/db/migrate/20160906201711_create_solidus_paypal_braintree_customers.rb +13 -0
  87. data/db/migrate/20161114231422_create_solidus_paypal_braintree_configurations.rb +11 -0
  88. data/db/migrate/20161125172005_add_braintree_configuration_to_stores.rb +7 -0
  89. data/db/migrate/20170203191030_add_credit_card_to_braintree_configuration.rb +6 -0
  90. data/db/migrate/20170505193712_add_null_constraint_to_sources.rb +38 -0
  91. data/db/migrate/20170508085402_add_not_null_constraint_to_sources_payment_type.rb +14 -0
  92. data/db/migrate/20190705115327_add_paypal_button_preferences_to_braintree_configurations.rb +5 -0
  93. data/db/migrate/20190911141712_add_3d_secure_to_braintree_configuration.rb +5 -0
  94. data/db/migrate/20211222170950_add_paypal_funding_source_to_solidus_paypal_braintree_sources.rb +5 -0
  95. data/db/migrate/20220104150301_add_venmo_to_braintree_configuration.rb +5 -0
  96. data/db/migrate/20230109080950_rename_solidus_paypal_braintree_source_type.rb +31 -0
  97. data/lib/controllers/backend/solidus_braintree/configurations_controller.rb +48 -0
  98. data/lib/controllers/frontend/solidus_braintree/checkouts_controller.rb +31 -0
  99. data/lib/controllers/frontend/solidus_braintree/transactions_controller.rb +67 -0
  100. data/lib/generators/solidus_braintree/install/install_generator.rb +54 -18
  101. data/lib/generators/solidus_braintree/install/templates/initializer.rb +6 -0
  102. data/lib/solidus_braintree/country_mapper.rb +37 -0
  103. data/lib/solidus_braintree/engine.rb +55 -10
  104. data/lib/solidus_braintree/extension_configuration.rb +23 -0
  105. data/lib/solidus_braintree/request_protection.rb +21 -0
  106. data/lib/solidus_braintree/testing_support/factories.rb +53 -0
  107. data/lib/solidus_braintree/version.rb +3 -1
  108. data/lib/solidus_braintree.rb +14 -2
  109. data/lib/solidus_paypal_braintree.rb +6 -0
  110. data/lib/views/backend/solidus_braintree/configurations/list.html.erb +63 -0
  111. data/lib/views/backend/spree/admin/payments/source_forms/_braintree.html.erb +16 -0
  112. data/lib/views/backend/spree/admin/payments/source_views/_braintree.html.erb +39 -0
  113. data/lib/views/backend/spree/admin/shared/preference_fields/_preference_select.html.erb +13 -0
  114. data/lib/views/backend_v1.2/spree/admin/payments/source_forms/_braintree.html.erb +16 -0
  115. data/lib/views/backend_v2.4/spree/admin/shared/preference_fields/_hash.html.erb +12 -0
  116. data/lib/views/frontend/solidus_braintree/payments/_payment.html.erb +12 -0
  117. data/lib/views/frontend/spree/checkout/payment/_braintree.html.erb +23 -0
  118. data/lib/views/frontend/spree/shared/_paypal_checkout_button.html.erb +32 -0
  119. data/solidus_braintree.gemspec +39 -38
  120. data/spec/controllers/solidus_braintree/checkouts_controller_spec.rb +99 -0
  121. data/spec/controllers/solidus_braintree/client_tokens_controller_spec.rb +55 -0
  122. data/spec/controllers/solidus_braintree/configurations_controller_spec.rb +73 -0
  123. data/spec/controllers/solidus_braintree/transactions_controller_spec.rb +183 -0
  124. data/spec/features/backend/configuration_spec.rb +23 -0
  125. data/spec/features/backend/new_payment_spec.rb +137 -0
  126. data/spec/features/frontend/braintree_credit_card_checkout_spec.rb +191 -0
  127. data/spec/features/frontend/paypal_checkout_spec.rb +166 -0
  128. data/spec/features/frontend/venmo_checkout_spec.rb +194 -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/spree/orders/edit.html.erb +50 -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 +742 -0
  167. data/spec/models/solidus_braintree/response_spec.rb +280 -0
  168. data/spec/models/solidus_braintree/source_spec.rb +539 -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/spec_helper.rb +32 -0
  175. data/spec/support/capybara.rb +7 -0
  176. data/spec/support/gateway_helpers.rb +29 -0
  177. data/spec/support/order_ready_for_payment.rb +37 -0
  178. data/spec/support/vcr.rb +42 -0
  179. data/spec/support/views.rb +1 -0
  180. metadata +281 -228
  181. data/.travis.yml +0 -41
  182. data/LICENSE.txt +0 -21
  183. data/app/controllers/spree/api/braintree_client_token_controller.rb +0 -13
  184. data/app/helpers/braintree_view_helpers.rb +0 -20
  185. data/app/models/concerns/solidus_braintree/add_name_validation_concern.rb +0 -8
  186. data/app/models/concerns/solidus_braintree/inject_device_data_concern.rb +0 -18
  187. data/app/models/concerns/solidus_braintree/payment_braintree_nonce_concern.rb +0 -8
  188. data/app/models/concerns/solidus_braintree/permitted_attributes_concern.rb +0 -11
  189. data/app/models/concerns/solidus_braintree/skip_require_card_numbers_concern.rb +0 -14
  190. data/app/models/concerns/solidus_braintree/use_data_field_concern.rb +0 -23
  191. data/app/models/credit_card_decorator.rb +0 -3
  192. data/app/models/payment_decorator.rb +0 -2
  193. data/app/models/permitted_attributes_decorator.rb +0 -1
  194. data/app/models/solidus/gateway/braintree_gateway.rb +0 -306
  195. data/app/overrides/spree/checkout/_confirm/braintree_security.html.erb.deface +0 -9
  196. data/app/views/spree/admin/payments/source_forms/_braintree.html.erb +0 -38
  197. data/app/views/spree/admin/payments/source_views/_braintree.html.erb +0 -30
  198. data/app/views/spree/checkout/payment/_braintree.html.erb +0 -55
  199. data/app/views/spree/checkout/payment/_braintree_initialization.html.erb +0 -12
  200. data/config/initializers/braintree.rb +0 -1
  201. data/db/migrate/20150910170527_add_data_to_credit_card.rb +0 -5
  202. data/db/migrate/20160426221931_add_braintree_device_data_to_order.rb +0 -5
  203. data/lib/assets/javascripts/spree/backend/braintree/solidus_braintree.js +0 -59
  204. data/lib/assets/javascripts/spree/frontend/braintree/solidus_braintree.js +0 -144
  205. data/lib/assets/javascripts/vendor/braintree.js +0 -8
  206. data/lib/assets/stylesheets/spree/frontend/solidus_braintree.scss +0 -26
@@ -1,4 +1,96 @@
1
1
  en:
2
+ activerecord:
3
+ models:
4
+ solidus_braintree/gateway: Braintree
5
+ attributes:
6
+ solidus_braintree/configuration:
7
+ paypal: PayPal
8
+ apple_pay: Apple Pay
9
+ credit_card: Credit Card
10
+ three_d_secure: 3D Secure
11
+ venmo: Venmo
12
+ spree:
13
+ admin:
14
+ tab:
15
+ braintree: Braintree
16
+ client_sdk_enabled: Client SDK enabled?
17
+ environment: Environment
18
+ merchant_currency_map: Merchant currency map
19
+ merchant_id: Merchant ID
20
+ paypal_payee_email_map: Paypal payee email map
21
+ private_key: Private key
22
+ public_key: Public key
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'
2
27
  solidus_braintree:
3
- paypal_header_html: <h5>Checkout with</h5>
4
- creditcard_header_html: <p class="or">or</p><h5>Enter a credit card:</h5>
28
+ braintree: Braintree
29
+ nonce: Nonce
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."
47
+ payment_type:
48
+ label: Payment Type
49
+ apple_pay_card: Apple Pay
50
+ credit_card: Credit Card
51
+ pay_pal_account: PayPal
52
+ venmo_account: Venmo
53
+ configurations:
54
+ title: Braintree Configurations
55
+ tab: Braintree
56
+ update_success: Successfully updated Braintree configurations.
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_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_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,5 +1,14 @@
1
- Spree::Core::Engine.routes.draw do
2
- namespace :api, defaults: { format: 'json' } do
3
- resource :payment_client_token, only: [:create], controller: 'braintree_client_token'
1
+ # frozen_string_literal: true
2
+
3
+ SolidusBraintree::Engine.routes.draw do
4
+ resource :checkout, only: [:update, :edit]
5
+ resource :client_token, only: [:create], format: :json
6
+ resource :transactions, only: [:create]
7
+
8
+ resources :configurations do
9
+ collection do
10
+ get :list
11
+ post :update
12
+ end
4
13
  end
5
14
  end
@@ -0,0 +1,16 @@
1
+ class CreateSolidusPaypalBraintreeSources < SolidusSupport::Migration[4.2]
2
+ def change
3
+ create_table :solidus_paypal_braintree_sources do |t|
4
+ t.string :nonce
5
+ t.string :token
6
+ t.string :payment_type
7
+ t.integer :user_id, index: true
8
+ t.references :customer, index: true
9
+ t.references :payment_method, index: true
10
+
11
+ t.timestamps null: false
12
+ end
13
+
14
+ add_foreign_key :solidus_paypal_braintree_sources, :spree_payment_methods, column: :payment_method_id
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ class CreateSolidusPaypalBraintreeCustomers < SolidusSupport::Migration[4.2]
2
+ def change
3
+ create_table :solidus_paypal_braintree_customers do |t|
4
+ t.references :user
5
+ t.string :braintree_customer_id
6
+
7
+ t.timestamps
8
+ end
9
+
10
+ add_index :solidus_paypal_braintree_customers, :user_id, unique: true, name: "index_braintree_customers_on_user_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
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ class CreateSolidusPaypalBraintreeConfigurations < SolidusSupport::Migration[4.2]
2
+ def change
3
+ create_table :solidus_paypal_braintree_configurations do |t|
4
+ t.boolean :paypal, null: false, default: false
5
+ t.boolean :apple_pay, null: false, default: false
6
+ t.integer :store_id, null: false, index: true, foreign_key: { references: :spree_stores }
7
+
8
+ t.timestamps null: false
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ class AddBraintreeConfigurationToStores < SolidusSupport::Migration[4.2]
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
7
+ end
@@ -0,0 +1,6 @@
1
+ class AddCreditCardToBraintreeConfiguration < SolidusSupport::Migration[4.2]
2
+ def change
3
+ add_column :solidus_paypal_braintree_configurations, :credit_card,
4
+ :boolean, null: false, default: false
5
+ end
6
+ end
@@ -0,0 +1,38 @@
1
+ class AddNullConstraintToSources < SolidusSupport::Migration[4.2]
2
+ class SpreePayment < ActiveRecord::Base
3
+ end
4
+
5
+ class SolidusPaypalBraintreeSource < ActiveRecord::Base
6
+ end
7
+
8
+ def up
9
+ payments = SpreePayment.arel_table
10
+ sources = SolidusPaypalBraintreeSource.arel_table
11
+ join_sources = payments.join(sources).on(
12
+ payments[:source_id].eq(sources[:id]).and(
13
+ payments[:source_type].eq("SolidusPaypalBraintree::Source")
14
+ ).and(
15
+ sources[:payment_method_id].eq(nil)
16
+ )
17
+ ).join_sources
18
+
19
+ count = SpreePayment.joins(join_sources).count
20
+ Rails.logger.info("Updating #{count} problematic sources")
21
+
22
+ SpreePayment.joins(join_sources).find_each do |payment|
23
+ Rails.logger.info("Updating source #{payment.source_id} with payment method id #{payment.payment_method_id}")
24
+ SolidusPaypalBraintreeSource.where(id: payment.source_id).update_all(
25
+ payment_method_id: payment.payment_method_id
26
+ )
27
+ end
28
+
29
+ # We use a foreign key constraint on the model,
30
+ # but it doesnt make sense to have this model exist without a payment method
31
+ # as two of its methods delegate to the payment method.
32
+ change_column_null(:solidus_paypal_braintree_sources, :payment_method_id, false)
33
+ end
34
+
35
+ def down
36
+ change_column_null(:solidus_paypal_braintree_sources, :payment_method_id, true)
37
+ end
38
+ end
@@ -0,0 +1,14 @@
1
+ class AddNotNullConstraintToSourcesPaymentType < SolidusSupport::Migration[4.2]
2
+ class SolidusPaypalBraintreeSource < ActiveRecord::Base
3
+ end
4
+
5
+ def change
6
+ reversible do |dir|
7
+ dir.up do
8
+ SolidusPaypalBraintreeSource.where(payment_type: nil).
9
+ update_all(payment_type: 'CreditCard')
10
+ end
11
+ end
12
+ change_column_null(:solidus_paypal_braintree_sources, :payment_type, false)
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ class AddPaypalButtonPreferencesToBraintreeConfigurations < ActiveRecord::Migration[5.1]
2
+ def change
3
+ add_column :solidus_paypal_braintree_configurations, :preferences, :text
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class Add3dSecureToBraintreeConfiguration < SolidusSupport::Migration[4.2]
2
+ def change
3
+ add_column :solidus_paypal_braintree_configurations, :three_d_secure, :boolean, null: false, default: false
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddPaypalFundingSourceToSolidusPaypalBraintreeSources < ActiveRecord::Migration[5.0]
2
+ def change
3
+ add_column :solidus_paypal_braintree_sources, :paypal_funding_source, :integer
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddVenmoToBraintreeConfiguration < ActiveRecord::Migration[5.0]
2
+ def change
3
+ add_column :solidus_paypal_braintree_configurations, :venmo, :boolean, null: false, default: false
4
+ end
5
+ end
@@ -0,0 +1,31 @@
1
+ class RenameSolidusPaypalBraintreeSourceType < ActiveRecord::Migration[6.1]
2
+ # This is based on the best practices recommended in
3
+ # https://github.com/ankane/strong_migrations#backfilling-data on how to
4
+ # safely update a table.
5
+
6
+ disable_ddl_transaction!
7
+
8
+ def up
9
+ Spree::Payment.unscoped
10
+ .where(source_type: 'SolidusPaypalBraintree::Source').in_batches do |relation|
11
+ relation.update_all("source_type = 'SolidusBraintree::Source'")
12
+ sleep(0.01)
13
+ end
14
+
15
+ Spree::WalletPaymentSource.unscoped
16
+ .where(payment_source_type: 'SolidusPaypalBraintree::Source').in_batches do |relation|
17
+ relation.update_all("payment_source_type = 'SolidusBraintree::Source'")
18
+ sleep(0.01)
19
+ end
20
+
21
+ Spree::PaymentMethod.unscoped
22
+ .where('type = ?', 'SolidusPaypalBraintree::Gateway').in_batches do |relation|
23
+ relation.update_all("type = 'SolidusBraintree::Gateway'")
24
+ sleep(0.01)
25
+ end
26
+ end
27
+
28
+ def down
29
+ raise ActiveRecord::IrreversibleMigration
30
+ end
31
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusBraintree
4
+ class ConfigurationsController < ::Spree::Admin::BaseController
5
+ helper ::Spree::Core::Engine.routes.url_helpers
6
+
7
+ def list
8
+ authorize! :list, SolidusBraintree::Configuration
9
+
10
+ @configurations = ::Spree::Store.all.map { |s| s.braintree_configuration || s.create_braintree_configuration }
11
+ end
12
+
13
+ def update
14
+ authorize! :update, SolidusBraintree::Configuration
15
+
16
+ params = configurations_params[:configuration_fields]
17
+ results = SolidusBraintree::Configuration.update(params.keys, params.values)
18
+ if results.all?(&:valid?)
19
+ flash[:success] = t('update_success', scope: 'solidus_braintree.configurations')
20
+ else
21
+ flash[:error] = t('update_error', scope: 'solidus_braintree.configurations')
22
+ end
23
+ redirect_to action: :list
24
+ end
25
+
26
+ private
27
+
28
+ def configurations_params
29
+ params.require(:configurations).
30
+ permit(configuration_fields: [
31
+ :paypal,
32
+ :apple_pay,
33
+ :venmo,
34
+ :credit_card,
35
+ :three_d_secure,
36
+ :preferred_paypal_button_locale,
37
+ :preferred_paypal_button_color,
38
+ :preferred_paypal_button_shape,
39
+ :preferred_paypal_button_label,
40
+ :preferred_paypal_button_tagline,
41
+ :preferred_paypal_button_layout,
42
+ :preferred_paypal_button_messaging,
43
+ :preferred_venmo_button_color,
44
+ :preferred_venmo_button_width
45
+ ])
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusBraintree
4
+ class CheckoutsController < ::Spree::CheckoutController
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 < ::Spree::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
+ spree.order_url(import.order)
52
+ else
53
+ spree.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
@@ -1,36 +1,72 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SolidusBraintree
2
4
  module Generators
3
5
  class InstallGenerator < Rails::Generators::Base
4
6
  class_option :auto_run_migrations, type: :boolean, default: false
7
+ source_root File.expand_path('templates', __dir__)
8
+
9
+ def setup_initializer
10
+ legacy_initializer_pathname =
11
+ Pathname.new(destination_root).join('config/initializers/solidus_paypal_braintree.rb')
12
+
13
+ if legacy_initializer_pathname.exist?
14
+ legacy_initializer_pathname.rename('config/initializers/solidus_braintree.rb')
15
+
16
+ gsub_file 'config/initializers/solidus_braintree.rb',
17
+ "SolidusPaypalBraintree.configure do |config|\n",
18
+ "SolidusBraintree.configure do |config|\n"
19
+ else
20
+ template 'initializer.rb', 'config/initializers/solidus_braintree.rb'
21
+ end
22
+ end
23
+
24
+ def setup_javascripts
25
+ gsub_file 'vendor/assets/javascripts/spree/frontend/all.js',
26
+ "//= require spree/frontend/solidus_paypal_braintree\n", ''
27
+
28
+ append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/solidus_braintree\n"
5
29
 
6
- def add_javascripts
7
- append_file "vendor/assets/javascripts/spree/frontend/all.js", "//= require spree/frontend/braintree/solidus_braintree\n"
8
- append_file "vendor/assets/javascripts/spree/backend/all.js", "//= require spree/backend/braintree/solidus_braintree\n"
30
+ gsub_file 'vendor/assets/javascripts/spree/backend/all.js',
31
+ "//= require spree/backend/solidus_paypal_braintree\n", ''
32
+
33
+ append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/solidus_braintree\n"
9
34
  end
10
35
 
11
- def add_stylesheets
12
- inject_into_file "vendor/assets/stylesheets/spree/frontend/all.css", " *= require spree/frontend/solidus_braintree\n", before: '*/', verbose: true
36
+ def setup_stylesheets
37
+ gsub_file 'vendor/assets/stylesheets/spree/frontend/all.css',
38
+ " *= require spree/frontend/solidus_paypal_braintree\n", ''
39
+
40
+ inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css',
41
+ " *= require spree/frontend/solidus_braintree\n", before: %r{\*/}, verbose: true
42
+
43
+ gsub_file 'vendor/assets/stylesheets/spree/backend/all.css',
44
+ " *= require spree/backend/solidus_paypal_braintree\n", ''
45
+
46
+ inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css',
47
+ " *= require spree/backend/solidus_braintree\n", before: %r{\*/}, verbose: true
13
48
  end
14
49
 
15
50
  def add_migrations
16
- run 'bundle exec rake railties:install:migrations FROM=solidus_braintree'
51
+ rake 'railties:install:migrations FROM=solidus_braintree'
17
52
  end
18
53
 
19
- def run_migrations
20
- if running_migrations?
21
- run 'bundle exec rake db:migrate'
22
- else
23
- puts "Skiping rake db:migrate, don't forget to run it!"
24
- end
54
+ def mount_engine
55
+ gsub_file 'config/routes.rb',
56
+ "mount SolidusPaypalBraintree::Engine, at: '/solidus_paypal_braintree'\n", ''
57
+
58
+ route "mount SolidusBraintree::Engine, at: '/solidus_braintree'"
25
59
  end
26
60
 
27
- private
61
+ def run_migrations
62
+ run_migrations = options[:auto_run_migrations] ||
63
+ ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]'))
28
64
 
29
- def running_migrations?
30
- options.auto_run_migrations? || begin
31
- response = ask 'Would you like to run the migrations now? [Y/n]'
32
- ['', 'y'].include? response.downcase
33
- end
65
+ if run_migrations
66
+ rake 'db:migrate'
67
+ else
68
+ puts 'Skipping bin/rails db:migrate, don\'t forget to run it!' # rubocop:disable Rails/Output
69
+ end
34
70
  end
35
71
  end
36
72
  end
@@ -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