solidus_paypal_braintree 0.4.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +44 -0
  3. data/.gem_release.yml +5 -0
  4. data/.github/stale.yml +17 -0
  5. data/.gitignore +19 -0
  6. data/.rspec +2 -0
  7. data/.rubocop.yml +76 -0
  8. data/CHANGELOG.md +327 -0
  9. data/Gemfile +38 -0
  10. data/LICENSE +2 -2
  11. data/README.md +170 -25
  12. data/Rakefile +4 -25
  13. data/app/assets/config/solidus_paypal_braintree_manifest.js +1 -0
  14. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_active_blue_button_280x48.svg +19 -0
  15. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_active_blue_button_320x48.svg +19 -0
  16. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_active_blue_button_375x48.svg +19 -0
  17. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_active_white_button_280x48.svg +19 -0
  18. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_active_white_button_320x48.svg +19 -0
  19. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_active_white_button_375x48.svg +19 -0
  20. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_blue_acceptance_mark.svg +15 -0
  21. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_blue_button_280x48.svg +19 -0
  22. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_blue_button_320x48.svg +19 -0
  23. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_blue_button_375x48.svg +19 -0
  24. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_blue_logo.svg +18 -0
  25. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_white_acceptance_mark.svg +20 -0
  26. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_white_button_280x48.svg +19 -0
  27. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_white_button_320x48.svg +19 -0
  28. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_white_button_375x48.svg +19 -0
  29. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_white_logo.svg +18 -0
  30. data/app/assets/javascripts/solidus_paypal_braintree/checkout.js +32 -3
  31. data/app/assets/javascripts/solidus_paypal_braintree/client.js +57 -4
  32. data/app/assets/javascripts/solidus_paypal_braintree/constants.js +27 -0
  33. data/app/assets/javascripts/solidus_paypal_braintree/frontend.js +2 -0
  34. data/app/assets/javascripts/solidus_paypal_braintree/hosted_form.js +15 -5
  35. data/app/assets/javascripts/solidus_paypal_braintree/paypal_button.js +71 -21
  36. data/app/assets/javascripts/solidus_paypal_braintree/paypal_messaging.js +22 -0
  37. data/app/assets/javascripts/solidus_paypal_braintree/venmo_button.js +86 -0
  38. data/app/assets/javascripts/spree/backend/solidus_paypal_braintree.js +2 -2
  39. data/app/assets/javascripts/spree/frontend/paypal_button.js +3 -3
  40. data/app/assets/stylesheets/spree/frontend/solidus_paypal_braintree.css +12 -0
  41. data/app/decorators/controllers/solidus_paypal_braintree/admin_payments_controller_decorator.rb +11 -0
  42. data/app/decorators/controllers/solidus_paypal_braintree/checkout_controller_decorator.rb +11 -0
  43. data/app/decorators/controllers/solidus_paypal_braintree/client_tokens_controller.rb +41 -0
  44. data/app/decorators/controllers/solidus_paypal_braintree/orders_controller_decorator.rb +11 -0
  45. data/app/decorators/models/solidus_paypal_braintree/spree/store_decorator.rb +20 -0
  46. data/app/decorators/models/solidus_paypal_braintree/spree/user_decorator.rb +13 -0
  47. data/app/helpers/solidus_paypal_braintree/braintree_admin_helper.rb +23 -0
  48. data/app/helpers/solidus_paypal_braintree/braintree_checkout_helper.rb +60 -0
  49. data/app/models/application_record.rb +2 -0
  50. data/app/models/solidus_paypal_braintree/address.rb +64 -0
  51. data/app/models/solidus_paypal_braintree/avs_result.rb +3 -0
  52. data/app/models/solidus_paypal_braintree/configuration.rb +39 -3
  53. data/app/models/solidus_paypal_braintree/customer.rb +7 -3
  54. data/app/models/solidus_paypal_braintree/gateway.rb +80 -21
  55. data/app/models/solidus_paypal_braintree/response.rb +3 -2
  56. data/app/models/solidus_paypal_braintree/source.rb +51 -8
  57. data/app/models/solidus_paypal_braintree/transaction.rb +5 -3
  58. data/app/models/solidus_paypal_braintree/transaction_address.rb +34 -12
  59. data/app/models/solidus_paypal_braintree/transaction_import.rb +17 -12
  60. data/app/overrides/spree/payments/payment/add_paypal_funding_source_to_payment.rb +9 -0
  61. data/app/views/spree/api/payments/source_views/_paypal_braintree.json.jbuilder +3 -0
  62. data/app/views/spree/checkout/existing_payment/_paypal_braintree.html.erb +10 -0
  63. data/app/views/spree/shared/_apple_pay_button.html.erb +2 -2
  64. data/app/views/spree/shared/_braintree_errors.html.erb +14 -17
  65. data/app/views/spree/shared/_braintree_hosted_fields.html.erb +24 -9
  66. data/app/views/spree/shared/_paypal_braintree_head_scripts.html.erb +13 -6
  67. data/app/views/spree/shared/_paypal_cart_button.html.erb +18 -2
  68. data/app/views/spree/shared/_paypal_messaging.html.erb +13 -0
  69. data/app/views/spree/shared/_venmo_button.html.erb +33 -0
  70. data/bin/console +17 -0
  71. data/bin/rails +15 -0
  72. data/bin/setup +8 -0
  73. data/config/locales/en.yml +44 -0
  74. data/config/locales/it.yml +53 -8
  75. data/config/routes.rb +2 -0
  76. data/db/migrate/20160906201711_create_solidus_paypal_braintree_customers.rb +3 -1
  77. data/db/migrate/20161125172005_add_braintree_configuration_to_stores.rb +5 -7
  78. data/db/migrate/20170505193712_add_null_constraint_to_sources.rb +3 -1
  79. data/db/migrate/20190705115327_add_paypal_button_preferences_to_braintree_configurations.rb +5 -0
  80. data/db/migrate/20190911141712_add_3d_secure_to_braintree_configuration.rb +5 -0
  81. data/db/migrate/20211222170950_add_paypal_funding_source_to_solidus_paypal_braintree_sources.rb +5 -0
  82. data/db/migrate/20220104150301_add_venmo_to_braintree_configuration.rb +5 -0
  83. data/lib/controllers/backend/solidus_paypal_braintree/configurations_controller.rb +23 -5
  84. data/lib/controllers/frontend/solidus_paypal_braintree/checkouts_controller.rb +25 -21
  85. data/lib/controllers/frontend/solidus_paypal_braintree/transactions_controller.rb +56 -51
  86. data/lib/generators/solidus_paypal_braintree/install/install_generator.rb +7 -5
  87. data/lib/solidus_paypal_braintree/country_mapper.rb +4 -2
  88. data/lib/solidus_paypal_braintree/engine.rb +17 -13
  89. data/lib/solidus_paypal_braintree/factories.rb +39 -4
  90. data/lib/solidus_paypal_braintree/request_protection.rb +3 -0
  91. data/lib/solidus_paypal_braintree/version.rb +3 -1
  92. data/lib/solidus_paypal_braintree.rb +4 -0
  93. data/lib/views/backend/solidus_paypal_braintree/configurations/list.html.erb +38 -5
  94. data/lib/views/backend/spree/admin/payments/source_forms/_paypal_braintree.html.erb +2 -2
  95. data/lib/views/backend/spree/admin/payments/source_views/_paypal_braintree.html.erb +7 -2
  96. data/lib/views/backend/spree/admin/shared/preference_fields/_preference_select.html.erb +13 -0
  97. data/lib/views/backend_v1.2/spree/admin/payments/source_forms/_paypal_braintree.html.erb +2 -2
  98. data/lib/views/frontend/solidus_paypal_braintree/payments/_payment.html.erb +12 -0
  99. data/lib/views/frontend/spree/checkout/payment/_paypal_braintree.html.erb +8 -2
  100. data/lib/views/frontend/spree/shared/_paypal_checkout_button.html.erb +32 -0
  101. data/solidus_paypal_braintree.gemspec +42 -0
  102. metadata +95 -188
  103. data/app/controllers/solidus_paypal_braintree/client_tokens_controller.rb +0 -22
  104. data/app/helpers/braintree_admin_helper.rb +0 -18
  105. data/app/models/spree/store_decorator.rb +0 -11
  106. data/app/views/spree/shared/_paypal_checkout_button.html.erb +0 -27
  107. data/config/initializers/braintree.rb +0 -1
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <svg width="126px" height="24px" viewBox="0 0 126 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
3
+ <!-- Generator: Sketch 46.1 (44463) - http://www.bohemiancoding.com/sketch -->
4
+ <title>blue_logosvg/</title>
5
+ <desc>Created with Sketch.</desc>
6
+ <defs></defs>
7
+ <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
8
+ <g id="blue_logo" fill="#3D95CE">
9
+ <g id="Group">
10
+ <path d="M21.2033583,0.0964593301 C22.0495843,1.49403336 22.4310921,2.93353679 22.4310921,4.75192551 C22.4310921,10.5516514 17.4799637,18.0859072 13.4615306,23.3763973 L4.28318255,23.3763973 L0.602153567,1.36628993 L8.63880252,0.603305315 L10.5850138,16.2649114 C12.4034764,13.3024803 14.6475506,8.6470141 14.6475506,5.47298073 C14.6475506,3.73562654 14.349905,2.55226174 13.8847522,1.57789215 L21.2033583,0.0964593301 L21.2033583,0.0964593301 Z" id="Shape"></path>
11
+ <path d="M31.6192168,9.7884495 C33.0981028,9.7884495 36.8212801,9.11193069 36.8212801,6.99590844 C36.8212801,5.97982672 36.1028027,5.47298073 35.2561421,5.47298073 C33.7748663,5.47298073 31.8310449,7.24922281 31.6192168,9.7884495 L31.6192168,9.7884495 Z M31.4497544,13.9792163 C31.4497544,16.5629794 32.8864919,17.5766714 34.7912066,17.5766714 C36.8653838,17.5766714 38.8513536,17.0698254 41.4326146,15.7580654 L40.460378,22.359881 C38.6416981,23.2484366 35.8073297,23.8413138 33.0561717,23.8413138 C26.0775769,23.8413138 23.5799608,19.6092694 23.5799608,14.318562 C23.5799608,7.46125954 27.6427148,0.180100866 36.0187232,0.180100866 C40.630275,0.180100866 43.2089289,2.76364671 43.2089289,6.36110177 C43.2093634,12.1606104 35.7656158,13.937287 31.4497544,13.9792163 L31.4497544,13.9792163 Z" id="Shape"></path>
12
+ <path d="M66.4016058,5.26137851 C66.4016058,6.1077874 66.2732054,7.33547136 66.1454568,8.13777835 L63.7338755,23.37618 L55.9084028,23.37618 L58.108156,9.4073917 C58.1498699,9.0285064 58.278053,8.26573904 58.278053,7.84253459 C58.278053,6.82645286 57.6432206,6.57292125 56.8799877,6.57292125 C55.8662545,6.57292125 54.8501315,7.03805509 54.1733679,7.377618 L51.6783589,23.3763973 L43.8087826,23.3763973 L47.403994,0.561810423 L54.2150817,0.561810423 L54.3013338,2.38280616 C55.9081856,1.32479503 58.0240766,0.180535368 61.0261694,0.180535368 C65.0035404,0.180100866 66.4016058,2.21248157 66.4016058,5.26137851 L66.4016058,5.26137851 Z" id="Shape"></path>
13
+ <path d="M89.6331722,2.67761541 C91.874422,1.07082892 93.9907475,0.180100866 96.9087609,0.180100866 C100.926977,0.180100866 102.324608,2.21248157 102.324608,5.26137851 C102.324608,6.1077874 102.196642,7.33547136 102.068893,8.13777835 L99.6601361,23.37618 L91.8324909,23.37618 L94.0741752,9.11214794 C94.1154545,8.73087288 94.2021411,8.26573904 94.2021411,7.97071253 C94.2021411,6.82667012 93.5670913,6.57292125 92.8040757,6.57292125 C91.8320564,6.57292125 90.8604715,6.9961257 90.1391698,7.377618 L87.6445953,23.3763973 L79.8189054,23.3763973 L82.0605897,9.11236519 C82.101869,8.73109013 82.1859485,8.26595629 82.1859485,7.97092978 C82.1859485,6.82688737 81.5506815,6.5731385 80.790273,6.5731385 C79.7743672,6.5731385 78.7604168,7.03827234 78.0836532,7.37783525 L75.5866889,23.3766145 L67.7197197,23.3766145 L71.3144966,0.562027674 L78.0423739,0.562027674 L78.2537674,2.46666494 C79.8189054,1.32522954 81.9330583,0.180969869 84.7672095,0.180969869 C87.2211564,0.180100866 88.827791,1.23832924 89.6331722,2.67761541 L89.6331722,2.67761541 Z" id="Shape"></path>
14
+ <path d="M117.898643,9.32375016 C117.898643,7.46125954 117.432838,6.19142894 116.038032,6.19142894 C112.949687,6.19142894 112.315506,11.6511574 112.315506,14.4441329 C112.315506,16.5629794 112.908408,17.8743049 114.30278,17.8743049 C117.221879,17.8743049 117.898643,12.1165085 117.898643,9.32375016 L117.898643,9.32375016 Z M104.36272,14.1069598 C104.36272,6.91226691 108.169107,0.180100866 116.926841,0.180100866 C123.525883,0.180100866 125.938116,4.07518945 125.938116,9.4514936 C125.938116,16.5627622 122.172791,23.9271279 113.203881,23.9271279 C106.562256,23.9271279 104.36272,19.5669055 104.36272,14.1069598 L104.36272,14.1069598 Z" id="Shape"></path>
15
+ </g>
16
+ </g>
17
+ </g>
18
+ </svg>
@@ -0,0 +1,20 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <svg width="48px" height="32px" viewBox="0 0 48 32" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
3
+ <!-- Generator: Sketch 46.1 (44463) - http://www.bohemiancoding.com/sketch -->
4
+ <title>white_venmo_acceptance_marksvg/</title>
5
+ <desc>Created with Sketch.</desc>
6
+ <defs>
7
+ <rect id="path-1" x="0" y="0" width="48" height="32" rx="3.2"></rect>
8
+ </defs>
9
+ <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
10
+ <g id="white_venmo_acceptance_mark">
11
+ <g id="Rectangle-115-+-Path-Copy">
12
+ <g id="Rectangle-115">
13
+ <use fill="#FFFFFF" fill-rule="evenodd" xlink:href="#path-1"></use>
14
+ <rect stroke="#EDEDED" stroke-width="1.2" x="0.6" y="0.6" width="46.8" height="30.8" rx="3.2"></rect>
15
+ </g>
16
+ <path d="M33.6,10.23957 C33.6,15.0228618 29.6080578,21.2366976 26.3681191,25.6 L18.9679002,25.6 L16,7.44728576 L22.4797022,6.81801842 L24.0488723,19.7348414 C25.5150427,17.2915927 27.3243705,13.4520228 27.3243705,10.8342563 C27.3243705,9.40138302 27.084388,8.42540945 26.7093497,7.62180353 L32.610116,6.4 C33.292402,7.55264145 33.6,8.73986394 33.6,10.23957 Z" id="Path" fill="#3D95CE"></path>
17
+ </g>
18
+ </g>
19
+ </g>
20
+ </svg>
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <svg width="280px" height="48px" viewBox="0 0 280 48" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
3
+ <!-- Generator: Sketch 46.1 (44463) - http://www.bohemiancoding.com/sketch -->
4
+ <title>svg/white_venmo_button_280x48</title>
5
+ <desc>Created with Sketch.</desc>
6
+ <defs></defs>
7
+ <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
8
+ <g id="white_venmo_button_280x48">
9
+ <rect id="Rectangle" fill="#FFFFFF" x="0" y="0" width="280" height="48" rx="4"></rect>
10
+ <g id="Group" transform="translate(98.000000, 16.000000)" fill="#3D95CE">
11
+ <path d="M14.1355722,0.0643062201 C14.6997229,0.996022242 14.9540614,1.95569119 14.9540614,3.16795034 C14.9540614,7.03443424 11.6533091,12.0572714 8.97435371,15.5842648 L2.85545503,15.5842648 L0.401435711,0.910859951 L5.75920168,0.402203543 L7.05667586,10.8432743 C8.26898429,8.86832019 9.76503373,5.76467606 9.76503373,3.64865382 C9.76503373,2.49041769 9.56660332,1.70150782 9.25650148,1.0519281 L14.1355722,0.0643062201 L14.1355722,0.0643062201 Z" id="Shape"></path>
12
+ <path d="M21.0794779,6.525633 C22.0654018,6.525633 24.5475201,6.07462046 24.5475201,4.66393896 C24.5475201,3.98655114 24.0685351,3.64865382 23.5040948,3.64865382 C22.5165776,3.64865382 21.2206966,4.83281521 21.0794779,6.525633 L21.0794779,6.525633 Z M20.9665029,9.31947756 C20.9665029,11.0419863 21.924328,11.7177809 23.1941378,11.7177809 C24.5769225,11.7177809 25.9009024,11.3798836 27.6217431,10.505377 L26.9735853,14.9065874 C25.7611321,15.4989577 23.8715531,15.8942092 22.0374478,15.8942092 C17.3850512,15.8942092 15.7199738,13.0728462 15.7199738,9.545708 C15.7199738,4.97417302 18.4284766,0.120067244 24.0124822,0.120067244 C27.08685,0.120067244 28.8059526,1.84243114 28.8059526,4.24073451 C28.8062423,8.10707358 23.8437439,9.29152463 20.9665029,9.31947756 L20.9665029,9.31947756 Z" id="Shape"></path>
13
+ <path d="M44.2677372,3.50758567 C44.2677372,4.07185827 44.1821369,4.89031424 44.0969712,5.42518557 L42.4892503,15.58412 L37.2722686,15.58412 L38.7387707,6.27159447 C38.7665799,6.01900427 38.8520354,5.51049269 38.8520354,5.22835639 C38.8520354,4.55096858 38.4288137,4.3819475 37.9199918,4.3819475 C37.2441697,4.3819475 36.5667543,4.69203673 36.1155786,4.918412 L34.4522393,15.5842648 L29.2058551,15.5842648 L31.6026627,0.374540282 L36.1433878,0.374540282 L36.2008892,1.58853744 C37.2721237,0.88319669 38.6827177,0.120356912 40.6841129,0.120356912 C43.3356936,0.120067244 44.2677372,1.47498771 44.2677372,3.50758567 L44.2677372,3.50758567 Z" id="Shape"></path>
14
+ <path d="M59.7554481,1.78507694 C61.2496147,0.713885943 62.6604983,0.120067244 64.6058406,0.120067244 C67.2846511,0.120067244 68.216405,1.47498771 68.216405,3.50758567 C68.216405,4.07185827 68.1310944,4.89031424 68.0459287,5.42518557 L66.4400908,15.58412 L61.2216606,15.58412 L62.7161168,6.07476529 C62.7436363,5.82058192 62.8014274,5.51049269 62.8014274,5.31380835 C62.8014274,4.55111341 62.3780609,4.3819475 61.8693838,4.3819475 C61.2213709,4.3819475 60.5736477,4.6640838 60.0927798,4.918412 L58.4297302,15.5842648 L53.2126036,15.5842648 L54.7070598,6.07491013 C54.7345794,5.82072676 54.7906323,5.51063753 54.7906323,5.31395319 C54.7906323,4.55125824 54.367121,4.38209233 53.860182,4.38209233 C53.1829115,4.38209233 52.5069445,4.69218156 52.0557688,4.91855683 L50.3911259,15.5844097 L45.1464798,15.5844097 L47.5429977,0.374685116 L52.0282492,0.374685116 L52.1691783,1.64444329 C53.2126036,0.883486357 54.6220389,0.12064658 56.511473,0.12064658 C58.1474376,0.120067244 59.2185273,0.825552826 59.7554481,1.78507694 L59.7554481,1.78507694 Z" id="Shape"></path>
15
+ <path d="M78.5990953,6.21583344 C78.5990953,4.97417302 78.288559,4.12761929 77.358688,4.12761929 C75.2997914,4.12761929 74.8770043,7.76743825 74.8770043,9.62942196 C74.8770043,11.0419863 75.2722719,11.9162033 76.2018532,11.9162033 C78.1479196,11.9162033 78.5990953,8.07767231 78.5990953,6.21583344 L78.5990953,6.21583344 Z M69.5751464,9.40463986 C69.5751464,4.60817794 72.1127383,0.120067244 77.9512273,0.120067244 C82.3505888,0.120067244 83.9587442,2.71679297 83.9587442,6.30099573 C83.9587442,11.0418415 81.4485271,15.9514186 75.4692539,15.9514186 C71.0415037,15.9514186 69.5751464,13.0446036 69.5751464,9.40463986 L69.5751464,9.40463986 Z" id="Shape"></path>
16
+ </g>
17
+ </g>
18
+ </g>
19
+ </svg>
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <svg width="320px" height="48px" viewBox="0 0 320 48" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
3
+ <!-- Generator: Sketch 46.1 (44463) - http://www.bohemiancoding.com/sketch -->
4
+ <title>svg/white_venmo_button_320x48</title>
5
+ <desc>Created with Sketch.</desc>
6
+ <defs></defs>
7
+ <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
8
+ <g id="white_venmo_button_320x48">
9
+ <rect id="Rectangle" fill="#FFFFFF" x="0" y="0" width="320" height="48" rx="4"></rect>
10
+ <g id="Group" transform="translate(118.000000, 16.000000)" fill="#3D95CE">
11
+ <path d="M14.1355722,0.0643062201 C14.6997229,0.996022242 14.9540614,1.95569119 14.9540614,3.16795034 C14.9540614,7.03443424 11.6533091,12.0572714 8.97435371,15.5842648 L2.85545503,15.5842648 L0.401435711,0.910859951 L5.75920168,0.402203543 L7.05667586,10.8432743 C8.26898429,8.86832019 9.76503373,5.76467606 9.76503373,3.64865382 C9.76503373,2.49041769 9.56660332,1.70150782 9.25650148,1.0519281 L14.1355722,0.0643062201 L14.1355722,0.0643062201 Z" id="Shape"></path>
12
+ <path d="M21.0794779,6.525633 C22.0654018,6.525633 24.5475201,6.07462046 24.5475201,4.66393896 C24.5475201,3.98655114 24.0685351,3.64865382 23.5040948,3.64865382 C22.5165776,3.64865382 21.2206966,4.83281521 21.0794779,6.525633 L21.0794779,6.525633 Z M20.9665029,9.31947756 C20.9665029,11.0419863 21.924328,11.7177809 23.1941378,11.7177809 C24.5769225,11.7177809 25.9009024,11.3798836 27.6217431,10.505377 L26.9735853,14.9065874 C25.7611321,15.4989577 23.8715531,15.8942092 22.0374478,15.8942092 C17.3850512,15.8942092 15.7199738,13.0728462 15.7199738,9.545708 C15.7199738,4.97417302 18.4284766,0.120067244 24.0124822,0.120067244 C27.08685,0.120067244 28.8059526,1.84243114 28.8059526,4.24073451 C28.8062423,8.10707358 23.8437439,9.29152463 20.9665029,9.31947756 L20.9665029,9.31947756 Z" id="Shape"></path>
13
+ <path d="M44.2677372,3.50758567 C44.2677372,4.07185827 44.1821369,4.89031424 44.0969712,5.42518557 L42.4892503,15.58412 L37.2722686,15.58412 L38.7387707,6.27159447 C38.7665799,6.01900427 38.8520354,5.51049269 38.8520354,5.22835639 C38.8520354,4.55096858 38.4288137,4.3819475 37.9199918,4.3819475 C37.2441697,4.3819475 36.5667543,4.69203673 36.1155786,4.918412 L34.4522393,15.5842648 L29.2058551,15.5842648 L31.6026627,0.374540282 L36.1433878,0.374540282 L36.2008892,1.58853744 C37.2721237,0.88319669 38.6827177,0.120356912 40.6841129,0.120356912 C43.3356936,0.120067244 44.2677372,1.47498771 44.2677372,3.50758567 L44.2677372,3.50758567 Z" id="Shape"></path>
14
+ <path d="M59.7554481,1.78507694 C61.2496147,0.713885943 62.6604983,0.120067244 64.6058406,0.120067244 C67.2846511,0.120067244 68.216405,1.47498771 68.216405,3.50758567 C68.216405,4.07185827 68.1310944,4.89031424 68.0459287,5.42518557 L66.4400908,15.58412 L61.2216606,15.58412 L62.7161168,6.07476529 C62.7436363,5.82058192 62.8014274,5.51049269 62.8014274,5.31380835 C62.8014274,4.55111341 62.3780609,4.3819475 61.8693838,4.3819475 C61.2213709,4.3819475 60.5736477,4.6640838 60.0927798,4.918412 L58.4297302,15.5842648 L53.2126036,15.5842648 L54.7070598,6.07491013 C54.7345794,5.82072676 54.7906323,5.51063753 54.7906323,5.31395319 C54.7906323,4.55125824 54.367121,4.38209233 53.860182,4.38209233 C53.1829115,4.38209233 52.5069445,4.69218156 52.0557688,4.91855683 L50.3911259,15.5844097 L45.1464798,15.5844097 L47.5429977,0.374685116 L52.0282492,0.374685116 L52.1691783,1.64444329 C53.2126036,0.883486357 54.6220389,0.12064658 56.511473,0.12064658 C58.1474376,0.120067244 59.2185273,0.825552826 59.7554481,1.78507694 L59.7554481,1.78507694 Z" id="Shape"></path>
15
+ <path d="M78.5990953,6.21583344 C78.5990953,4.97417302 78.288559,4.12761929 77.358688,4.12761929 C75.2997914,4.12761929 74.8770043,7.76743825 74.8770043,9.62942196 C74.8770043,11.0419863 75.2722719,11.9162033 76.2018532,11.9162033 C78.1479196,11.9162033 78.5990953,8.07767231 78.5990953,6.21583344 L78.5990953,6.21583344 Z M69.5751464,9.40463986 C69.5751464,4.60817794 72.1127383,0.120067244 77.9512273,0.120067244 C82.3505888,0.120067244 83.9587442,2.71679297 83.9587442,6.30099573 C83.9587442,11.0418415 81.4485271,15.9514186 75.4692539,15.9514186 C71.0415037,15.9514186 69.5751464,13.0446036 69.5751464,9.40463986 L69.5751464,9.40463986 Z" id="Shape"></path>
16
+ </g>
17
+ </g>
18
+ </g>
19
+ </svg>
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <svg width="375px" height="48px" viewBox="0 0 375 48" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
3
+ <!-- Generator: Sketch 46.1 (44463) - http://www.bohemiancoding.com/sketch -->
4
+ <title>svg/white_venmo_button_375x48</title>
5
+ <desc>Created with Sketch.</desc>
6
+ <defs></defs>
7
+ <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
8
+ <g id="white_venmo_button_375x48">
9
+ <rect id="Rectangle" fill="#FFFFFF" x="0" y="0" width="375" height="48" rx="4"></rect>
10
+ <g id="Group" transform="translate(146.000000, 16.000000)" fill="#3D95CE">
11
+ <path d="M14.1355722,0.0643062201 C14.6997229,0.996022242 14.9540614,1.95569119 14.9540614,3.16795034 C14.9540614,7.03443424 11.6533091,12.0572714 8.97435371,15.5842648 L2.85545503,15.5842648 L0.401435711,0.910859951 L5.75920168,0.402203543 L7.05667586,10.8432743 C8.26898429,8.86832019 9.76503373,5.76467606 9.76503373,3.64865382 C9.76503373,2.49041769 9.56660332,1.70150782 9.25650148,1.0519281 L14.1355722,0.0643062201 L14.1355722,0.0643062201 Z" id="Shape"></path>
12
+ <path d="M21.0794779,6.525633 C22.0654018,6.525633 24.5475201,6.07462046 24.5475201,4.66393896 C24.5475201,3.98655114 24.0685351,3.64865382 23.5040948,3.64865382 C22.5165776,3.64865382 21.2206966,4.83281521 21.0794779,6.525633 L21.0794779,6.525633 Z M20.9665029,9.31947756 C20.9665029,11.0419863 21.924328,11.7177809 23.1941378,11.7177809 C24.5769225,11.7177809 25.9009024,11.3798836 27.6217431,10.505377 L26.9735853,14.9065874 C25.7611321,15.4989577 23.8715531,15.8942092 22.0374478,15.8942092 C17.3850512,15.8942092 15.7199738,13.0728462 15.7199738,9.545708 C15.7199738,4.97417302 18.4284766,0.120067244 24.0124822,0.120067244 C27.08685,0.120067244 28.8059526,1.84243114 28.8059526,4.24073451 C28.8062423,8.10707358 23.8437439,9.29152463 20.9665029,9.31947756 L20.9665029,9.31947756 Z" id="Shape"></path>
13
+ <path d="M44.2677372,3.50758567 C44.2677372,4.07185827 44.1821369,4.89031424 44.0969712,5.42518557 L42.4892503,15.58412 L37.2722686,15.58412 L38.7387707,6.27159447 C38.7665799,6.01900427 38.8520354,5.51049269 38.8520354,5.22835639 C38.8520354,4.55096858 38.4288137,4.3819475 37.9199918,4.3819475 C37.2441697,4.3819475 36.5667543,4.69203673 36.1155786,4.918412 L34.4522393,15.5842648 L29.2058551,15.5842648 L31.6026627,0.374540282 L36.1433878,0.374540282 L36.2008892,1.58853744 C37.2721237,0.88319669 38.6827177,0.120356912 40.6841129,0.120356912 C43.3356936,0.120067244 44.2677372,1.47498771 44.2677372,3.50758567 L44.2677372,3.50758567 Z" id="Shape"></path>
14
+ <path d="M59.7554481,1.78507694 C61.2496147,0.713885943 62.6604983,0.120067244 64.6058406,0.120067244 C67.2846511,0.120067244 68.216405,1.47498771 68.216405,3.50758567 C68.216405,4.07185827 68.1310944,4.89031424 68.0459287,5.42518557 L66.4400908,15.58412 L61.2216606,15.58412 L62.7161168,6.07476529 C62.7436363,5.82058192 62.8014274,5.51049269 62.8014274,5.31380835 C62.8014274,4.55111341 62.3780609,4.3819475 61.8693838,4.3819475 C61.2213709,4.3819475 60.5736477,4.6640838 60.0927798,4.918412 L58.4297302,15.5842648 L53.2126036,15.5842648 L54.7070598,6.07491013 C54.7345794,5.82072676 54.7906323,5.51063753 54.7906323,5.31395319 C54.7906323,4.55125824 54.367121,4.38209233 53.860182,4.38209233 C53.1829115,4.38209233 52.5069445,4.69218156 52.0557688,4.91855683 L50.3911259,15.5844097 L45.1464798,15.5844097 L47.5429977,0.374685116 L52.0282492,0.374685116 L52.1691783,1.64444329 C53.2126036,0.883486357 54.6220389,0.12064658 56.511473,0.12064658 C58.1474376,0.120067244 59.2185273,0.825552826 59.7554481,1.78507694 L59.7554481,1.78507694 Z" id="Shape"></path>
15
+ <path d="M78.5990953,6.21583344 C78.5990953,4.97417302 78.288559,4.12761929 77.358688,4.12761929 C75.2997914,4.12761929 74.8770043,7.76743825 74.8770043,9.62942196 C74.8770043,11.0419863 75.2722719,11.9162033 76.2018532,11.9162033 C78.1479196,11.9162033 78.5990953,8.07767231 78.5990953,6.21583344 L78.5990953,6.21583344 Z M69.5751464,9.40463986 C69.5751464,4.60817794 72.1127383,0.120067244 77.9512273,0.120067244 C82.3505888,0.120067244 83.9587442,2.71679297 83.9587442,6.30099573 C83.9587442,11.0418415 81.4485271,15.9514186 75.4692539,15.9514186 C71.0415037,15.9514186 69.5751464,13.0446036 69.5751464,9.40463986 L69.5751464,9.40463986 Z" id="Shape"></path>
16
+ </g>
17
+ </g>
18
+ </g>
19
+ </svg>
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <svg width="126px" height="24px" viewBox="0 0 126 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
3
+ <!-- Generator: Sketch 46.1 (44463) - http://www.bohemiancoding.com/sketch -->
4
+ <title>white_logosvg/</title>
5
+ <desc>Created with Sketch.</desc>
6
+ <defs></defs>
7
+ <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
8
+ <g id="white_logo" fill="#FFFFFF">
9
+ <g id="Group">
10
+ <path d="M21.2033583,0.0964593301 C22.0495843,1.49403336 22.4310921,2.93353679 22.4310921,4.75192551 C22.4310921,10.5516514 17.4799637,18.0859072 13.4615306,23.3763973 L4.28318255,23.3763973 L0.602153567,1.36628993 L8.63880252,0.603305315 L10.5850138,16.2649114 C12.4034764,13.3024803 14.6475506,8.6470141 14.6475506,5.47298073 C14.6475506,3.73562654 14.349905,2.55226174 13.8847522,1.57789215 L21.2033583,0.0964593301 L21.2033583,0.0964593301 Z" id="Shape"></path>
11
+ <path d="M31.6192168,9.7884495 C33.0981028,9.7884495 36.8212801,9.11193069 36.8212801,6.99590844 C36.8212801,5.97982672 36.1028027,5.47298073 35.2561421,5.47298073 C33.7748663,5.47298073 31.8310449,7.24922281 31.6192168,9.7884495 L31.6192168,9.7884495 Z M31.4497544,13.9792163 C31.4497544,16.5629794 32.8864919,17.5766714 34.7912066,17.5766714 C36.8653838,17.5766714 38.8513536,17.0698254 41.4326146,15.7580654 L40.460378,22.359881 C38.6416981,23.2484366 35.8073297,23.8413138 33.0561717,23.8413138 C26.0775769,23.8413138 23.5799608,19.6092694 23.5799608,14.318562 C23.5799608,7.46125954 27.6427148,0.180100866 36.0187232,0.180100866 C40.630275,0.180100866 43.2089289,2.76364671 43.2089289,6.36110177 C43.2093634,12.1606104 35.7656158,13.937287 31.4497544,13.9792163 L31.4497544,13.9792163 Z" id="Shape"></path>
12
+ <path d="M66.4016058,5.26137851 C66.4016058,6.1077874 66.2732054,7.33547136 66.1454568,8.13777835 L63.7338755,23.37618 L55.9084028,23.37618 L58.108156,9.4073917 C58.1498699,9.0285064 58.278053,8.26573904 58.278053,7.84253459 C58.278053,6.82645286 57.6432206,6.57292125 56.8799877,6.57292125 C55.8662545,6.57292125 54.8501315,7.03805509 54.1733679,7.377618 L51.6783589,23.3763973 L43.8087826,23.3763973 L47.403994,0.561810423 L54.2150817,0.561810423 L54.3013338,2.38280616 C55.9081856,1.32479503 58.0240766,0.180535368 61.0261694,0.180535368 C65.0035404,0.180100866 66.4016058,2.21248157 66.4016058,5.26137851 L66.4016058,5.26137851 Z" id="Shape"></path>
13
+ <path d="M89.6331722,2.67761541 C91.874422,1.07082892 93.9907475,0.180100866 96.9087609,0.180100866 C100.926977,0.180100866 102.324608,2.21248157 102.324608,5.26137851 C102.324608,6.1077874 102.196642,7.33547136 102.068893,8.13777835 L99.6601361,23.37618 L91.8324909,23.37618 L94.0741752,9.11214794 C94.1154545,8.73087288 94.2021411,8.26573904 94.2021411,7.97071253 C94.2021411,6.82667012 93.5670913,6.57292125 92.8040757,6.57292125 C91.8320564,6.57292125 90.8604715,6.9961257 90.1391698,7.377618 L87.6445953,23.3763973 L79.8189054,23.3763973 L82.0605897,9.11236519 C82.101869,8.73109013 82.1859485,8.26595629 82.1859485,7.97092978 C82.1859485,6.82688737 81.5506815,6.5731385 80.790273,6.5731385 C79.7743672,6.5731385 78.7604168,7.03827234 78.0836532,7.37783525 L75.5866889,23.3766145 L67.7197197,23.3766145 L71.3144966,0.562027674 L78.0423739,0.562027674 L78.2537674,2.46666494 C79.8189054,1.32522954 81.9330583,0.180969869 84.7672095,0.180969869 C87.2211564,0.180100866 88.827791,1.23832924 89.6331722,2.67761541 L89.6331722,2.67761541 Z" id="Shape"></path>
14
+ <path d="M117.898643,9.32375016 C117.898643,7.46125954 117.432838,6.19142894 116.038032,6.19142894 C112.949687,6.19142894 112.315506,11.6511574 112.315506,14.4441329 C112.315506,16.5629794 112.908408,17.8743049 114.30278,17.8743049 C117.221879,17.8743049 117.898643,12.1165085 117.898643,9.32375016 L117.898643,9.32375016 Z M104.36272,14.1069598 C104.36272,6.91226691 108.169107,0.180100866 116.926841,0.180100866 C123.525883,0.180100866 125.938116,4.07518945 125.938116,9.4514936 C125.938116,16.5627622 122.172791,23.9271279 113.203881,23.9271279 C106.562256,23.9271279 104.36272,19.5669055 104.36272,14.1069598 L104.36272,14.1069598 Z" id="Shape"></path>
15
+ </g>
16
+ </g>
17
+ </g>
18
+ </svg>
@@ -15,11 +15,18 @@ $(function() {
15
15
  * https://github.com/rails/jquery-rails/blob/master/vendor/assets/javascripts/jquery_ujs.js#L517
16
16
  * The only way we can re-enable it is by delaying longer than that timeout
17
17
  * or stopping propagation so their submit handler doesn't run. */
18
- if ($.rails) {
18
+ if ($.rails && typeof $.rails.enableFormElement !== 'undefined') {
19
19
  setTimeout(function () {
20
20
  $.rails.enableFormElement($submitButton);
21
21
  $submitButton.attr("disabled", false).removeClass("disabled").addClass("primary");
22
22
  }, 100);
23
+ } else if (typeof Rails !== 'undefined' && typeof Rails.enableElement !== 'undefined') {
24
+ /* Indicates that we have rails-ujs instead of jquery-ujs. Rails-ujs was added to rails
25
+ * core in Rails 5.1.0 */
26
+ setTimeout(function () {
27
+ Rails.enableElement($submitButton[0]);
28
+ $submitButton.attr("disabled", false).removeClass("disabled").addClass("primary");
29
+ }, 100);
23
30
  } else {
24
31
  $submitButton.attr("disabled", false).removeClass("disabled").addClass("primary");
25
32
  }
@@ -37,16 +44,38 @@ $(function() {
37
44
  var $nonce = $("#payment_method_nonce", $field);
38
45
 
39
46
  if ($nonce.length > 0 && $nonce.val() === "") {
47
+ var client = braintreeForm._merchantConfigurationOptions._solidusClient;
48
+
40
49
  event.preventDefault();
41
50
  disableSubmit();
42
51
 
43
52
  braintreeForm.tokenize(function(error, payload) {
44
53
  if (error) {
45
54
  braintreeError(error);
46
- } else {
47
- $nonce.val(payload.nonce);
55
+ return;
56
+ }
57
+
58
+ $nonce.val(payload.nonce);
59
+
60
+ if (!client.useThreeDSecure) {
48
61
  $paymentForm.submit();
62
+ return;
63
+ }
64
+
65
+ threeDSecureOptions.nonce = payload.nonce;
66
+ threeDSecureOptions.bin = payload.details.bin;
67
+ threeDSecureOptions.onLookupComplete = function(data, next) {
68
+ next();
49
69
  }
70
+ client._threeDSecureInstance.verifyCard(threeDSecureOptions, function(error, response) {
71
+ if (error === null && (!response.liabilityShiftPossible || response.liabilityShifted)) {
72
+ $nonce.val(response.nonce);
73
+ $paymentForm.submit();
74
+ } else {
75
+ $nonce.val('');
76
+ braintreeError(error || { code: 'THREEDS_AUTHENTICATION_FAILED' });
77
+ }
78
+ });
50
79
  });
51
80
  }
52
81
  }
@@ -57,10 +57,16 @@ SolidusPaypalBraintree.Client = function(config) {
57
57
  this.useDataCollector = config.useDataCollector;
58
58
  this.usePaypal = config.usePaypal;
59
59
  this.useApplepay = config.useApplepay;
60
+ this.useVenmo = config.useVenmo;
61
+ this.flow = config.flow;
62
+ this.venmoNewTabSupported = config.newBrowserTabSupported
63
+ this.useThreeDSecure = config.useThreeDSecure;
60
64
 
61
65
  this._braintreeInstance = null;
62
66
  this._dataCollectorInstance = null;
63
67
  this._paypalInstance = null;
68
+ this._venmoInstance = null;
69
+ this._threeDSecureInstance = null;
64
70
  };
65
71
 
66
72
  /**
@@ -71,18 +77,26 @@ SolidusPaypalBraintree.Client.prototype.initialize = function() {
71
77
  var initializationPromise = this._fetchToken().
72
78
  then(this._createBraintreeInstance.bind(this));
73
79
 
74
- if(this.useDataCollector) {
80
+ if (this.useDataCollector) {
75
81
  initializationPromise = initializationPromise.then(this._createDataCollector.bind(this));
76
82
  }
77
83
 
78
- if(this.usePaypal) {
84
+ if (this.usePaypal) {
79
85
  initializationPromise = initializationPromise.then(this._createPaypal.bind(this));
80
86
  }
81
87
 
82
- if(this.useApplepay) {
88
+ if (this.useApplepay) {
83
89
  initializationPromise = initializationPromise.then(this._createApplepay.bind(this));
84
90
  }
85
91
 
92
+ if (this.useVenmo) {
93
+ initializationPromise = initializationPromise.then(this._createVenmo.bind(this));
94
+ }
95
+
96
+ if (this.useThreeDSecure) {
97
+ initializationPromise = initializationPromise.then(this._createThreeDSecure.bind(this));
98
+ }
99
+
86
100
  return initializationPromise.then(this._invokeReadyCallback.bind(this));
87
101
  };
88
102
 
@@ -110,6 +124,14 @@ SolidusPaypalBraintree.Client.prototype.getApplepayInstance = function() {
110
124
  return this._applepayInstance;
111
125
  };
112
126
 
127
+ /**
128
+ * Returns the braintree Venmo instance
129
+ * @returns {external:"braintree.Venmo"} The Braintree Venmo that was initialized by this class
130
+ **/
131
+ SolidusPaypalBraintree.Client.prototype.getVenmoInstance = function() {
132
+ return this._venmoInstance;
133
+ };
134
+
113
135
  /**
114
136
  * Returns the braintree dataCollector instance
115
137
  * @returns {external:"braintree.DataCollector"} The braintree dataCollector that was initialized by this class
@@ -173,7 +195,9 @@ SolidusPaypalBraintree.Client.prototype._createPaypal = function() {
173
195
  }]).then(function (paypalInstance) {
174
196
  this._paypalInstance = paypalInstance;
175
197
  return paypalInstance;
176
- }.bind(this));
198
+ }.bind(this), function(error) {
199
+ console.error(error.name + ':', error.message);
200
+ });
177
201
  };
178
202
 
179
203
  SolidusPaypalBraintree.Client.prototype._createApplepay = function() {
@@ -184,3 +208,32 @@ SolidusPaypalBraintree.Client.prototype._createApplepay = function() {
184
208
  return applePayInstance;
185
209
  }.bind(this));
186
210
  };
211
+
212
+ SolidusPaypalBraintree.Client.prototype._createVenmo = function() {
213
+ return SolidusPaypalBraintree.PromiseShim.convertBraintreePromise(braintree.venmo.create, [{
214
+ client: this._braintreeInstance,
215
+ allowDesktop: true,
216
+ paymentMethodUsage: this.flow === 'vault' ? 'multi_use' : 'single_use',
217
+ allowNewBrowserTab: this.venmoNewTabSupported
218
+ }]).then(function (venmoInstance) {
219
+ // Verify browser support before proceeding.
220
+ if (!venmoInstance.isBrowserSupported()) {
221
+ console.log('Browser does not support Venmo');
222
+ return;
223
+ }
224
+
225
+ this._venmoInstance = venmoInstance;
226
+ return venmoInstance;
227
+ }.bind(this));
228
+ };
229
+
230
+ SolidusPaypalBraintree.Client.prototype._createThreeDSecure = function() {
231
+ return SolidusPaypalBraintree.PromiseShim.convertBraintreePromise(braintree.threeDSecure.create, [{
232
+ client: this._braintreeInstance,
233
+ version: 2
234
+ }]).then(function (threeDSecureInstance) {
235
+ this._threeDSecureInstance = threeDSecureInstance;
236
+ }.bind(this), function(error) {
237
+ console.log(error);
238
+ });
239
+ };
@@ -26,8 +26,16 @@ SolidusPaypalBraintree = {
26
26
  return SolidusPaypalBraintree.PaypalButton;
27
27
  },
28
28
 
29
+ paypalMessaging: function() {
30
+ return SolidusPaypalBraintree.PaypalMessaging;
31
+ },
32
+
29
33
  applepayButton: function() {
30
34
  return SolidusPaypalBraintree.ApplepayButton;
35
+ },
36
+
37
+ venmoButton: function() {
38
+ return SolidusPaypalBraintree.VenmoButton;
31
39
  }
32
40
  }
33
41
  },
@@ -51,12 +59,31 @@ SolidusPaypalBraintree = {
51
59
  return SolidusPaypalBraintree._factory(SolidusPaypalBraintree.config.classes.paypalButton(), arguments);
52
60
  },
53
61
 
62
+ createPaypalMessaging: function() {
63
+ return SolidusPaypalBraintree._factory(SolidusPaypalBraintree.config.classes.paypalMessaging(), arguments);
64
+ },
65
+
54
66
  createApplePayButton: function() {
55
67
  return SolidusPaypalBraintree._factory(SolidusPaypalBraintree.config.classes.applepayButton(), arguments);
56
68
  },
57
69
 
70
+ createVenmoButton: function() {
71
+ return SolidusPaypalBraintree._factory(SolidusPaypalBraintree.config.classes.venmoButton(), arguments);
72
+ },
73
+
58
74
  _factory: function(klass, args) {
59
75
  var normalizedArgs = Array.prototype.slice.call(args);
60
76
  return new (Function.prototype.bind.apply(klass, [null].concat(normalizedArgs)));
61
77
  }
62
78
  };
79
+
80
+ BraintreeError = {
81
+ DEFAULT: "Something bad happened!",
82
+
83
+ getErrorFromSlug: function(slug) {
84
+ error = BraintreeError.DEFAULT
85
+ if (slug in BraintreeError)
86
+ error = BraintreeError[slug]
87
+ return error
88
+ }
89
+ }
@@ -9,4 +9,6 @@
9
9
  //= require solidus_paypal_braintree/client
10
10
  //= require solidus_paypal_braintree/hosted_form
11
11
  //= require solidus_paypal_braintree/paypal_button
12
+ //= require solidus_paypal_braintree/paypal_messaging
12
13
  //= require solidus_paypal_braintree/apple_pay_button
14
+ //= require solidus_paypal_braintree/venmo_button
@@ -4,7 +4,11 @@ SolidusPaypalBraintree.HostedForm = function(paymentMethodId) {
4
4
  };
5
5
 
6
6
  SolidusPaypalBraintree.HostedForm.prototype.initialize = function() {
7
- this.client = SolidusPaypalBraintree.createClient({paymentMethodId: this.paymentMethodId});
7
+ this.client = SolidusPaypalBraintree.createClient({
8
+ paymentMethodId: this.paymentMethodId,
9
+ useThreeDSecure: (typeof(window.threeDSecureOptions) !== 'undefined'),
10
+ });
11
+
8
12
  return this.client.initialize().
9
13
  then(this._createHostedFields.bind(this));
10
14
  };
@@ -15,21 +19,27 @@ SolidusPaypalBraintree.HostedForm.prototype._createHostedFields = function () {
15
19
  }
16
20
 
17
21
  var opts = {
22
+ _solidusClient: this.client,
18
23
  client: this.client.getBraintreeInstance(),
19
24
 
20
25
  fields: {
21
26
  number: {
22
- selector: "#card_number" + this.paymentMethodId
27
+ selector: "#card_number" + this.paymentMethodId,
28
+ placeholder: placeholder_text["number"]
23
29
  },
24
30
 
25
31
  cvv: {
26
- selector: "#card_code" + this.paymentMethodId
32
+ selector: "#card_code" + this.paymentMethodId,
33
+ placeholder: placeholder_text["cvv"]
27
34
  },
28
35
 
29
36
  expirationDate: {
30
- selector: "#card_expiry" + this.paymentMethodId
37
+ selector: "#card_expiry" + this.paymentMethodId,
38
+ placeholder: placeholder_text["expirationDate"]
31
39
  }
32
- }
40
+ },
41
+
42
+ styles: credit_card_fields_style
33
43
  };
34
44
 
35
45
  return SolidusPaypalBraintree.PromiseShim.convertBraintreePromise(braintree.hostedFields.create, [opts]);
@@ -7,11 +7,25 @@
7
7
  SolidusPaypalBraintree.PaypalButton = function(element, paypalOptions, options) {
8
8
  this._element = element;
9
9
  this._paypalOptions = paypalOptions || {};
10
+
11
+ this.locale = paypalOptions['locale'] || "en_US";
12
+ this.style = paypalOptions['style'] || {};
13
+ delete paypalOptions['locale'];
14
+ delete paypalOptions['style'];
15
+
10
16
  this._options = options || {};
11
17
  this._client = null;
12
18
  this._environment = this._paypalOptions.environment || 'sandbox';
13
19
  delete this._paypalOptions.environment;
14
20
 
21
+ this._buyerCountry = this._paypalOptions.buyerCountry;
22
+ delete paypalOptions['buyerCountry'];
23
+
24
+ this._enabledFunding = [];
25
+
26
+ if (paypalOptions['venmoFunding']) this._enabledFunding.push('venmo');
27
+ delete paypalOptions['venmoFunding'];
28
+
15
29
  if(!this._element) {
16
30
  throw new Error("Element for the paypal button must be present on the page");
17
31
  }
@@ -26,7 +40,10 @@ SolidusPaypalBraintree.PaypalButton = function(element, paypalOptions, options)
26
40
  * See {@link https://braintree.github.io/braintree-web/3.9.0/PayPal.html#tokenize}
27
41
  */
28
42
  SolidusPaypalBraintree.PaypalButton.prototype.initialize = function() {
29
- this._client = new SolidusPaypalBraintree.createClient({useDataCollector: true, usePaypal: true});
43
+ this._client = new SolidusPaypalBraintree.createClient({
44
+ useDataCollector: this._paypalOptions.useDataCollector,
45
+ usePaypal: true
46
+ });
30
47
 
31
48
  return this._client.initialize().then(this.initializeCallback.bind(this));
32
49
  };
@@ -34,17 +51,38 @@ SolidusPaypalBraintree.PaypalButton.prototype.initialize = function() {
34
51
  SolidusPaypalBraintree.PaypalButton.prototype.initializeCallback = function() {
35
52
  this._paymentMethodId = this._client.paymentMethodId;
36
53
 
37
- paypal.Button.render({
38
- env: this._environment,
54
+ var args = {
55
+ "client-id": this._environment === "sandbox" ? "sb" : null,
56
+ currency: this._paypalOptions.currency,
57
+ commit: true,
58
+ vault: this._paypalOptions.flow == "vault",
59
+ components: this.style['messaging'] == "true" && this._paypalOptions.flow != "vault" ? "buttons,messages" : "buttons",
60
+ intent: this._paypalOptions.flow == "vault" ? "tokenize" : "authorize"
61
+ };
62
+
63
+ if (this._environment === "sandbox" && this._buyerCountry) {
64
+ args["buyer-country"] = this._buyerCountry
65
+ }
66
+ if (this._enabledFunding.length !== 0) {
67
+ args["enable-funding"] = this._enabledFunding.join(',');
68
+ }
39
69
 
40
- payment: function () {
41
- return this._client.getPaypalInstance().createPayment(this._paypalOptions);
42
- }.bind(this),
70
+ this._client.getPaypalInstance().loadPayPalSDK(args).then(() => {
71
+ var create_method = this._paypalOptions.flow == "vault" ? "createBillingAgreement" : "createOrder"
43
72
 
44
- onAuthorize: function (data, actions) {
45
- return this._client.getPaypalInstance().tokenizePayment(data, this._tokenizeCallback.bind(this));
46
- }.bind(this)
47
- }, this._element);
73
+ var render_config = {
74
+ style: this.style,
75
+ onClick: (data) => { SolidusPaypalBraintree.fundingSource = data.fundingSource },
76
+ [create_method]: function () {
77
+ return this._client.getPaypalInstance().createPayment(this._paypalOptions);
78
+ }.bind(this),
79
+ onApprove: function (data, actions) {
80
+ return this._client.getPaypalInstance().tokenizePayment(data, this._tokenizeCallback.bind(this));
81
+ }.bind(this)
82
+ };
83
+
84
+ paypal.Buttons(render_config).render(this._element);
85
+ })
48
86
  };
49
87
 
50
88
  /**
@@ -70,7 +108,22 @@ SolidusPaypalBraintree.PaypalButton.prototype._tokenizeCallback = function(token
70
108
  window.location.href = response.redirectUrl;
71
109
  },
72
110
  error: function(xhr) {
73
- console.error("Error submitting transaction");
111
+ var errorText = BraintreeError.DEFAULT;
112
+
113
+ if (xhr.responseJSON && xhr.responseJSON.errors) {
114
+ var errors = [];
115
+ $.each(xhr.responseJSON.errors, function(key, values) {
116
+ $.each(values, function(index, value) {
117
+ errors.push(key + " " + value)
118
+ });
119
+ });
120
+
121
+ if (errors.length > 0)
122
+ errorText = errors.join(", ");
123
+ }
124
+
125
+ console.error("Error submitting transaction: " + errorText);
126
+ SolidusPaypalBraintree.showError(errorText);
74
127
  },
75
128
  });
76
129
  };
@@ -90,6 +143,7 @@ SolidusPaypalBraintree.PaypalButton.prototype._transactionParams = function(payl
90
143
  "phone" : payload.details.phone,
91
144
  "nonce" : payload.nonce,
92
145
  "payment_type" : payload.type,
146
+ "paypal_funding_source": SolidusPaypalBraintree.fundingSource,
93
147
  "address_attributes" : this._addressParams(payload)
94
148
  }
95
149
  };
@@ -102,22 +156,18 @@ SolidusPaypalBraintree.PaypalButton.prototype._transactionParams = function(payl
102
156
  * @param {object} payload - The payload returned by Braintree after tokenization
103
157
  */
104
158
  SolidusPaypalBraintree.PaypalButton.prototype._addressParams = function(payload) {
105
- var first_name, last_name;
159
+ var name;
106
160
  var payload_address = payload.details.shippingAddress || payload.details.billingAddress;
161
+ if (!payload_address) return {};
107
162
 
108
163
  if (payload_address.recipientName) {
109
- first_name = payload_address.recipientName.split(" ")[0];
110
- last_name = payload_address.recipientName.split(" ")[1];
111
- }
112
-
113
- if (!first_name || !last_name) {
114
- first_name = payload.details.firstName;
115
- last_name = payload.details.lastName;
164
+ name = payload_address.recipientName
165
+ } else {
166
+ name = payload.details.firstName + " " + payload.details.lastName;
116
167
  }
117
168
 
118
169
  return {
119
- "first_name" : first_name,
120
- "last_name" : last_name,
170
+ "name" : name,
121
171
  "address_line_1" : payload_address.line1,
122
172
  "address_line_2" : payload_address.line2,
123
173
  "city" : payload_address.city,
@@ -0,0 +1,22 @@
1
+ //= require solidus_paypal_braintree/constants
2
+
3
+ SolidusPaypalBraintree.PaypalMessaging = function(paypalOptions) {
4
+ this._paypalOptions = paypalOptions || {};
5
+
6
+ this._client = null;
7
+ };
8
+
9
+ SolidusPaypalBraintree.PaypalMessaging.prototype.initialize = function() {
10
+ this._client = new SolidusPaypalBraintree.createClient({usePaypal: true});
11
+
12
+ return this._client.initialize().then(this.initializeCallback.bind(this));
13
+ };
14
+
15
+ SolidusPaypalBraintree.PaypalMessaging.prototype.initializeCallback = function() {
16
+ this._paymentMethodId = this._client.paymentMethodId;
17
+
18
+ this._client.getPaypalInstance().loadPayPalSDK({
19
+ currency: this._paypalOptions.currency,
20
+ components: "messages"
21
+ })
22
+ };