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.
- checksums.yaml +4 -4
- data/.circleci/config.yml +78 -0
- data/.gem_release.yml +5 -0
- data/.github/stale.yml +1 -0
- data/.github_changelog_generator +2 -0
- data/.gitignore +21 -10
- data/.rspec +1 -1
- data/.rubocop.yml +86 -0
- data/CHANGELOG.md +186 -18
- data/Gemfile +35 -17
- data/LICENSE +26 -0
- data/README.md +389 -24
- data/Rakefile +6 -16
- data/app/assets/config/solidus_braintree_manifest.js +0 -0
- data/app/assets/javascripts/spree/backend/solidus_braintree/client.js +239 -0
- data/app/assets/javascripts/spree/backend/solidus_braintree/constants.js +89 -0
- data/app/assets/javascripts/spree/backend/solidus_braintree/hosted_form.js +46 -0
- data/app/assets/javascripts/spree/backend/solidus_braintree/promise.js +20 -0
- data/app/assets/javascripts/spree/backend/solidus_braintree.js +96 -0
- data/app/assets/stylesheets/spree/backend/solidus_braintree.scss +28 -0
- data/app/decorators/controllers/solidus_braintree/admin_payments_controller_decorator.rb +11 -0
- data/app/decorators/controllers/solidus_braintree/client_tokens_controller.rb +41 -0
- data/app/decorators/models/solidus_braintree/spree/store_decorator.rb +20 -0
- data/app/decorators/models/solidus_braintree/spree/user_decorator.rb +13 -0
- data/app/helpers/solidus_braintree/braintree_admin_helper.rb +23 -0
- data/app/models/application_record.rb +5 -0
- data/app/models/solidus_braintree/address.rb +64 -0
- data/app/models/solidus_braintree/avs_result.rb +69 -0
- data/app/models/solidus_braintree/configuration.rb +39 -0
- data/app/models/solidus_braintree/customer.rb +8 -0
- data/app/models/solidus_braintree/gateway.rb +437 -0
- data/app/models/solidus_braintree/response.rb +80 -0
- data/app/models/solidus_braintree/source.rb +140 -0
- data/app/models/solidus_braintree/transaction.rb +31 -0
- data/app/models/solidus_braintree/transaction_address.rb +88 -0
- data/app/models/solidus_braintree/transaction_import.rb +98 -0
- data/app/views/spree/api/payments/source_views/_braintree.json.jbuilder +3 -0
- data/bin/console +4 -1
- data/bin/dummy-app +37 -0
- data/bin/rails +5 -5
- data/bin/rails-dummy-app +17 -0
- data/bin/rails-engine +13 -0
- data/bin/rails-sandbox +16 -0
- data/bin/rake +7 -0
- data/bin/rspec +11 -0
- data/bin/sandbox +61 -0
- data/bin/setup +5 -4
- data/config/locales/en.yml +94 -2
- data/config/locales/it.yml +56 -0
- data/config/routes.rb +12 -3
- data/db/migrate/20160830061749_create_solidus_paypal_braintree_sources.rb +16 -0
- data/db/migrate/20160906201711_create_solidus_paypal_braintree_customers.rb +13 -0
- data/db/migrate/20161114231422_create_solidus_paypal_braintree_configurations.rb +11 -0
- data/db/migrate/20161125172005_add_braintree_configuration_to_stores.rb +7 -0
- data/db/migrate/20170203191030_add_credit_card_to_braintree_configuration.rb +6 -0
- data/db/migrate/20170505193712_add_null_constraint_to_sources.rb +38 -0
- data/db/migrate/20170508085402_add_not_null_constraint_to_sources_payment_type.rb +14 -0
- data/db/migrate/20190705115327_add_paypal_button_preferences_to_braintree_configurations.rb +5 -0
- data/db/migrate/20190911141712_add_3d_secure_to_braintree_configuration.rb +5 -0
- data/db/migrate/20211222170950_add_paypal_funding_source_to_solidus_paypal_braintree_sources.rb +5 -0
- data/db/migrate/20220104150301_add_venmo_to_braintree_configuration.rb +5 -0
- data/db/migrate/20230109080950_rename_solidus_paypal_braintree_source_type.rb +31 -0
- data/db/migrate/20230210104310_add_device_data_to_braintree_sources.rb +5 -0
- data/lib/controllers/backend/solidus_braintree/configurations_controller.rb +48 -0
- data/lib/generators/solidus_braintree/install/install_generator.rb +155 -19
- data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_active_blue_button_280x48.svg +19 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_active_blue_button_320x48.svg +19 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_active_blue_button_375x48.svg +19 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_active_white_button_280x48.svg +19 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_active_white_button_320x48.svg +19 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_active_white_button_375x48.svg +19 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_blue_acceptance_mark.svg +15 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_blue_button_280x48.svg +19 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_blue_button_320x48.svg +19 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_blue_button_375x48.svg +19 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_blue_logo.svg +18 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_white_acceptance_mark.svg +20 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_white_button_280x48.svg +19 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_white_button_320x48.svg +19 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_white_button_375x48.svg +19 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/images/solidus_braintree/venmo/venmo_white_logo.svg +18 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/paypal_button.js +34 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/ajax.js +13 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/apple_pay_button.js +179 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/checkout.js +113 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/client.js +239 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/constants.js +89 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/frontend.js +15 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/hosted_form.js +48 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/paypal_button.js +178 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/paypal_messaging.js +22 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/promise.js +20 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/venmo_button.js +86 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree.js +1 -0
- data/lib/generators/solidus_braintree/install/templates/app/assets/stylesheets/spree/frontend/solidus_braintree.scss +62 -0
- data/lib/generators/solidus_braintree/install/templates/app/controllers/solidus_braintree/checkouts_controller.rb +31 -0
- data/lib/generators/solidus_braintree/install/templates/app/controllers/solidus_braintree/transactions_controller.rb +67 -0
- data/lib/generators/solidus_braintree/install/templates/app/helpers/solidus_braintree/braintree_checkout_helper.rb +60 -0
- data/lib/generators/solidus_braintree/install/templates/app/views/checkouts/existing_payment/_braintree.html.erb +2 -0
- data/lib/generators/solidus_braintree/install/templates/app/views/checkouts/payment/_braintree.html.erb +23 -0
- data/lib/generators/solidus_braintree/install/templates/app/views/payments/_braintree_payment_details.html.erb +9 -0
- data/lib/generators/solidus_braintree/install/templates/app/views/spree/shared/_apple_pay_button.html.erb +27 -0
- data/lib/generators/solidus_braintree/install/templates/app/views/spree/shared/_braintree_errors.html.erb +16 -0
- data/lib/generators/solidus_braintree/install/templates/app/views/spree/shared/_braintree_head_scripts.html.erb +26 -0
- data/lib/generators/solidus_braintree/install/templates/app/views/spree/shared/_braintree_hosted_fields.html.erb +40 -0
- data/lib/generators/solidus_braintree/install/templates/app/views/spree/shared/_paypal_cart_button.html.erb +38 -0
- data/lib/generators/solidus_braintree/install/templates/app/views/spree/shared/_paypal_checkout_button.html.erb +32 -0
- data/lib/generators/solidus_braintree/install/templates/app/views/spree/shared/_paypal_messaging.html.erb +13 -0
- data/lib/generators/solidus_braintree/install/templates/app/views/spree/shared/_venmo_button.html.erb +33 -0
- data/lib/generators/solidus_braintree/install/templates/config/initializers/solidus_braintree.rb +6 -0
- data/lib/solidus_braintree/country_mapper.rb +37 -0
- data/lib/solidus_braintree/engine.rb +61 -11
- data/lib/solidus_braintree/extension_configuration.rb +23 -0
- data/lib/solidus_braintree/request_protection.rb +21 -0
- data/lib/solidus_braintree/version.rb +3 -1
- data/lib/solidus_braintree.rb +14 -2
- data/lib/solidus_paypal_braintree.rb +6 -0
- data/lib/views/backend/solidus_braintree/configurations/list.html.erb +63 -0
- data/lib/views/backend/spree/admin/payments/source_forms/_braintree.html.erb +16 -0
- data/lib/views/backend/spree/admin/payments/source_views/_braintree.html.erb +39 -0
- data/lib/views/backend/spree/admin/shared/preference_fields/_preference_select.html.erb +13 -0
- data/lib/views/backend_v1.2/spree/admin/payments/source_forms/_braintree.html.erb +16 -0
- data/lib/views/backend_v2.4/spree/admin/shared/preference_fields/_hash.html.erb +12 -0
- data/solidus_braintree.gemspec +37 -38
- data/spec/controllers/solidus_braintree/checkouts_controller_spec.rb +99 -0
- data/spec/controllers/solidus_braintree/client_tokens_controller_spec.rb +55 -0
- data/spec/controllers/solidus_braintree/configurations_controller_spec.rb +73 -0
- data/spec/controllers/solidus_braintree/transactions_controller_spec.rb +183 -0
- data/spec/fixtures/cassettes/admin/invalid_credit_card.yml +63 -0
- data/spec/fixtures/cassettes/admin/resubmit_credit_card.yml +352 -0
- data/spec/fixtures/cassettes/admin/valid_credit_card.yml +412 -0
- data/spec/fixtures/cassettes/braintree/create_profile.yml +71 -0
- data/spec/fixtures/cassettes/braintree/generate_token.yml +63 -0
- data/spec/fixtures/cassettes/braintree/token.yml +63 -0
- data/spec/fixtures/cassettes/checkout/invalid_credit_card.yml +63 -0
- data/spec/fixtures/cassettes/checkout/resubmit_credit_card.yml +216 -0
- data/spec/fixtures/cassettes/checkout/update.yml +71 -0
- data/spec/fixtures/cassettes/checkout/valid_credit_card.yml +171 -0
- data/spec/fixtures/cassettes/checkout/valid_venmo_transaction.yml +599 -0
- data/spec/fixtures/cassettes/gateway/authorize/credit_card/address.yml +86 -0
- data/spec/fixtures/cassettes/gateway/authorize/merchant_account/EUR.yml +154 -0
- data/spec/fixtures/cassettes/gateway/authorize/paypal/EUR.yml +90 -0
- data/spec/fixtures/cassettes/gateway/authorize/paypal/address.yml +90 -0
- data/spec/fixtures/cassettes/gateway/authorize.yml +86 -0
- data/spec/fixtures/cassettes/gateway/authorized_transaction.yml +73 -0
- data/spec/fixtures/cassettes/gateway/cancel/missing.yml +63 -0
- data/spec/fixtures/cassettes/gateway/cancel/refunds.yml +272 -0
- data/spec/fixtures/cassettes/gateway/cancel/void.yml +201 -0
- data/spec/fixtures/cassettes/gateway/capture.yml +141 -0
- data/spec/fixtures/cassettes/gateway/complete.yml +157 -0
- data/spec/fixtures/cassettes/gateway/credit.yml +208 -0
- data/spec/fixtures/cassettes/gateway/customer.yml +79 -0
- data/spec/fixtures/cassettes/gateway/purchase.yml +87 -0
- data/spec/fixtures/cassettes/gateway/settled_transaction.yml +140 -0
- data/spec/fixtures/cassettes/gateway/void.yml +137 -0
- data/spec/fixtures/cassettes/source/bin.yml +295 -0
- data/spec/fixtures/cassettes/source/card_type.yml +267 -0
- data/spec/fixtures/cassettes/source/last4.yml +267 -0
- data/spec/fixtures/cassettes/transaction/import/valid/capture.yml +224 -0
- data/spec/fixtures/cassettes/transaction/import/valid.yml +71 -0
- data/spec/fixtures/views/carts/_cart_footer.html.erb +18 -0
- data/spec/helpers/solidus_braintree/braintree_admin_helper_spec.rb +17 -0
- data/spec/helpers/solidus_braintree/braintree_checkout_helper_spec.rb +70 -0
- data/spec/models/solidus_braintree/address_spec.rb +71 -0
- data/spec/models/solidus_braintree/avs_result_spec.rb +317 -0
- data/spec/models/solidus_braintree/gateway_spec.rb +774 -0
- data/spec/models/solidus_braintree/response_spec.rb +280 -0
- data/spec/models/solidus_braintree/source_spec.rb +555 -0
- data/spec/models/solidus_braintree/transaction_address_spec.rb +235 -0
- data/spec/models/solidus_braintree/transaction_import_spec.rb +302 -0
- data/spec/models/solidus_braintree/transaction_spec.rb +86 -0
- data/spec/models/spree/store_spec.rb +14 -0
- data/spec/requests/spree/api/orders_controller_spec.rb +36 -0
- data/spec/solidus_braintree_helper.rb +7 -0
- data/spec/support/solidus_braintree/capybara.rb +7 -0
- data/spec/support/solidus_braintree/factories.rb +55 -0
- data/spec/support/solidus_braintree/gateway_helpers.rb +29 -0
- data/spec/support/solidus_braintree/order_ready_for_payment.rb +44 -0
- data/spec/support/solidus_braintree/order_walkthrough.rb +87 -0
- data/spec/support/solidus_braintree/vcr.rb +42 -0
- data/spec/support/solidus_braintree/with_prepended_view_fixtures.rb +19 -0
- data/spec/system/backend/configuration_spec.rb +23 -0
- data/spec/system/backend/new_payment_spec.rb +136 -0
- data/spec/system/frontend/braintree_credit_card_checkout_spec.rb +199 -0
- data/spec/system/frontend/paypal_checkout_spec.rb +169 -0
- data/spec/system/frontend/venmo_checkout_spec.rb +193 -0
- metadata +289 -255
- data/.travis.yml +0 -41
- data/LICENSE.txt +0 -21
- data/app/controllers/spree/api/braintree_client_token_controller.rb +0 -13
- data/app/helpers/braintree_view_helpers.rb +0 -20
- data/app/models/concerns/solidus_braintree/add_name_validation_concern.rb +0 -8
- data/app/models/concerns/solidus_braintree/inject_device_data_concern.rb +0 -18
- data/app/models/concerns/solidus_braintree/payment_braintree_nonce_concern.rb +0 -8
- data/app/models/concerns/solidus_braintree/permitted_attributes_concern.rb +0 -11
- data/app/models/concerns/solidus_braintree/skip_require_card_numbers_concern.rb +0 -14
- data/app/models/concerns/solidus_braintree/use_data_field_concern.rb +0 -23
- data/app/models/credit_card_decorator.rb +0 -3
- data/app/models/payment_decorator.rb +0 -2
- data/app/models/permitted_attributes_decorator.rb +0 -1
- data/app/models/solidus/gateway/braintree_gateway.rb +0 -306
- data/app/overrides/spree/checkout/_confirm/braintree_security.html.erb.deface +0 -9
- data/app/views/spree/admin/payments/source_forms/_braintree.html.erb +0 -38
- data/app/views/spree/admin/payments/source_views/_braintree.html.erb +0 -30
- data/app/views/spree/checkout/payment/_braintree.html.erb +0 -55
- data/app/views/spree/checkout/payment/_braintree_initialization.html.erb +0 -12
- data/config/initializers/braintree.rb +0 -1
- data/db/migrate/20150910170527_add_data_to_credit_card.rb +0 -5
- data/db/migrate/20160426221931_add_braintree_device_data_to_order.rb +0 -5
- data/lib/assets/javascripts/spree/backend/braintree/solidus_braintree.js +0 -59
- data/lib/assets/javascripts/spree/frontend/braintree/solidus_braintree.js +0 -144
- data/lib/assets/javascripts/vendor/braintree.js +0 -8
- data/lib/assets/stylesheets/spree/frontend/solidus_braintree.scss +0 -26
@@ -0,0 +1,86 @@
|
|
1
|
+
//= require spree/frontend/solidus_braintree/constants
|
2
|
+
/**
|
3
|
+
* Constructor for Venmo button object
|
4
|
+
* @constructor
|
5
|
+
* @param {object} element - The DOM element of your Venmo button
|
6
|
+
*/
|
7
|
+
SolidusBraintree.VenmoButton = function(element, venmoOptions) {
|
8
|
+
this._element = element;
|
9
|
+
this._client = null;
|
10
|
+
this._venmoOptions = venmoOptions || {};
|
11
|
+
|
12
|
+
if(!this._element) {
|
13
|
+
throw new Error("Element for the Venmo button must be present on the page");
|
14
|
+
}
|
15
|
+
};
|
16
|
+
|
17
|
+
/**
|
18
|
+
* Creates the Venmo session using the provided options and enables the button
|
19
|
+
*
|
20
|
+
* @param {object} options - The options passed to tokenize when constructing
|
21
|
+
* the Venmo instance
|
22
|
+
*
|
23
|
+
* See {@link https://braintree.github.io/braintree-web/3.84.0/module-braintree-web_venmo.html#.create}
|
24
|
+
*/
|
25
|
+
SolidusBraintree.VenmoButton.prototype.initialize = function() {
|
26
|
+
this._client = new SolidusBraintree.createClient({
|
27
|
+
useVenmo: true,
|
28
|
+
newBrowserTabSupported: this._venmoOptions.newBrowserTabSupported,
|
29
|
+
flow: this._venmoOptions.flow
|
30
|
+
});
|
31
|
+
|
32
|
+
return this._client.initialize().then(this.initializeCallback.bind(this));
|
33
|
+
};
|
34
|
+
|
35
|
+
SolidusBraintree.VenmoButton.prototype.initializeCallback = function() {
|
36
|
+
this._venmoInstance = this._client.getVenmoInstance();
|
37
|
+
|
38
|
+
this._element.classList.add('visible');
|
39
|
+
|
40
|
+
// Check if tokenization results already exist. This occurs when your
|
41
|
+
// checkout page is relaunched in a new tab.
|
42
|
+
if (!this._venmoOptions.newBrowserTabSupported && this._venmoInstance.hasTokenizationResult()) {
|
43
|
+
this.tokenize();
|
44
|
+
}
|
45
|
+
|
46
|
+
this._element.addEventListener('click', function(event) {
|
47
|
+
event.preventDefault();
|
48
|
+
this._element.disabled = true;
|
49
|
+
this.initializeVenmoSession();
|
50
|
+
}.bind(this), false);
|
51
|
+
};
|
52
|
+
|
53
|
+
SolidusBraintree.VenmoButton.prototype.initializeVenmoSession = function() {
|
54
|
+
this.tokenize();
|
55
|
+
};
|
56
|
+
|
57
|
+
SolidusBraintree.VenmoButton.prototype.tokenize = function() {
|
58
|
+
var venmoButton = this._element;
|
59
|
+
this._venmoInstance.tokenize().then(handleVenmoSuccess).catch(handleVenmoError).then(function () {
|
60
|
+
venmoButton.removeAttribute('disabled');
|
61
|
+
});
|
62
|
+
};
|
63
|
+
|
64
|
+
function handleVenmoSuccess(payload) {
|
65
|
+
var $paymentForm = $("#checkout_form_payment");
|
66
|
+
var $nonceField = $("#venmo_payment_method_nonce", $paymentForm);
|
67
|
+
|
68
|
+
// Disable hostedFields' and enable Venmo's inputs as they use the same fields.
|
69
|
+
// Otherwise, they will clash. (Disabled inputs are not used on form submission)
|
70
|
+
$('.hosted-fields input').each(function(_index, input) {
|
71
|
+
input.disabled = true;
|
72
|
+
});
|
73
|
+
$('.venmo-fields input').each(function(_index, input) {
|
74
|
+
input.removeAttribute('disabled');
|
75
|
+
});
|
76
|
+
|
77
|
+
// remove hostedFields submit listener, otherwise empty credit card errors occur
|
78
|
+
$paymentForm.off('submit');
|
79
|
+
|
80
|
+
$nonceField.val(payload.nonce);
|
81
|
+
$paymentForm.submit();
|
82
|
+
}
|
83
|
+
|
84
|
+
function handleVenmoError(error) {
|
85
|
+
SolidusBraintree.config.braintreeErrorHandle(error);
|
86
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
//= require spree/frontend/solidus_braintree/frontend
|
@@ -0,0 +1,62 @@
|
|
1
|
+
/*
|
2
|
+
Placeholder manifest file.
|
3
|
+
the installer will append this file to the app vendored assets here: 'vendor/assets/stylesheets/spree/frontend/all.css'
|
4
|
+
*/
|
5
|
+
|
6
|
+
.braintree-hosted-fields .input {
|
7
|
+
border: 1px solid #d9d9db;
|
8
|
+
border-radius: 3px;
|
9
|
+
color: #5498DA;
|
10
|
+
height: 30px;
|
11
|
+
padding: 5px 10px;
|
12
|
+
}
|
13
|
+
|
14
|
+
.paypal-button-widget .paypal-button:hover {
|
15
|
+
background: transparent;
|
16
|
+
}
|
17
|
+
|
18
|
+
.apple-pay-button {
|
19
|
+
-webkit-appearance: -apple-pay-button;
|
20
|
+
-apple-pay-button-type: buy;
|
21
|
+
visibility: hidden;
|
22
|
+
display: inline-block;
|
23
|
+
min-height: 30px;
|
24
|
+
border: 1px solid black;
|
25
|
+
background-image: -webkit-named-image(apple-pay-logo-black);
|
26
|
+
background-size: 100% calc(60% + 2px);
|
27
|
+
background-repeat: no-repeat;
|
28
|
+
background-color: white;
|
29
|
+
background-position: 50% 50%;
|
30
|
+
border-radius: 5px;
|
31
|
+
padding: 0;
|
32
|
+
margin: 5px auto;
|
33
|
+
transition: background-color .15s;
|
34
|
+
width: auto;
|
35
|
+
}
|
36
|
+
|
37
|
+
.apple-pay-button.visible {
|
38
|
+
visibility: visible;
|
39
|
+
}
|
40
|
+
|
41
|
+
.venmo-button {
|
42
|
+
visibility: hidden;
|
43
|
+
border: none;
|
44
|
+
height: 48px;
|
45
|
+
background-color: transparent;
|
46
|
+
background-repeat: no-repeat;
|
47
|
+
}
|
48
|
+
|
49
|
+
.venmo-button.visible {
|
50
|
+
visibility: visible;
|
51
|
+
}
|
52
|
+
|
53
|
+
/*
|
54
|
+
WORKAROUND: Do not allow buttons in disabled payment-step to be clickable. Note
|
55
|
+
that it's still possible to trigger the PayPal button iframe by tabbing to it
|
56
|
+
and hitting enter.
|
57
|
+
*/
|
58
|
+
fieldset.payment-step__details:disabled {
|
59
|
+
#apple-pay-button, #paypal-button iframe, #venmo-button {
|
60
|
+
pointer-events: none;
|
61
|
+
}
|
62
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusBraintree
|
4
|
+
class CheckoutsController < CheckoutsController
|
5
|
+
PERMITTED_PAYMENT_PARAMS = [
|
6
|
+
:payment_method_id,
|
7
|
+
{ source_attributes: [
|
8
|
+
:nonce,
|
9
|
+
:payment_type
|
10
|
+
] }
|
11
|
+
].freeze
|
12
|
+
|
13
|
+
def update
|
14
|
+
@payment = ::Spree::PaymentCreate.new(@order, payment_params).build
|
15
|
+
|
16
|
+
if @payment.save
|
17
|
+
render plain: "ok"
|
18
|
+
else
|
19
|
+
render plain: "not-ok"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def payment_params
|
24
|
+
params.
|
25
|
+
require(:order).
|
26
|
+
require(:payments_attributes).
|
27
|
+
first.
|
28
|
+
permit(PERMITTED_PAYMENT_PARAMS)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusBraintree
|
4
|
+
class TransactionsController < StoreController
|
5
|
+
class InvalidImportError < StandardError; end
|
6
|
+
|
7
|
+
PERMITTED_BRAINTREE_TRANSACTION_PARAMS = [
|
8
|
+
:nonce,
|
9
|
+
:payment_type,
|
10
|
+
:paypal_funding_source,
|
11
|
+
:phone,
|
12
|
+
:email,
|
13
|
+
{ address_attributes: [
|
14
|
+
:country_code, :country_name, :name, :city, :zip, :state_code,
|
15
|
+
:address_line_1, :address_line_2, :first_name, :last_name
|
16
|
+
] }
|
17
|
+
].freeze
|
18
|
+
|
19
|
+
def create
|
20
|
+
transaction = SolidusBraintree::Transaction.new transaction_params
|
21
|
+
import = SolidusBraintree::TransactionImport.new(current_order, transaction)
|
22
|
+
restart_checkout = params[:options] && params[:options][:restart_checkout] == "true"
|
23
|
+
|
24
|
+
respond_to do |format|
|
25
|
+
if import.valid?
|
26
|
+
import.import!(import_state, restart_checkout: restart_checkout)
|
27
|
+
|
28
|
+
format.html { redirect_to redirect_url(import) }
|
29
|
+
format.json { render json: { redirectUrl: redirect_url(import) } }
|
30
|
+
else
|
31
|
+
status = 422
|
32
|
+
format.html { import_error(import) }
|
33
|
+
format.json { render json: { errors: import.errors, status: status }, status: status }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def import_state
|
41
|
+
params[:state] || 'confirm'
|
42
|
+
end
|
43
|
+
|
44
|
+
def import_error(import)
|
45
|
+
raise InvalidImportError,
|
46
|
+
"Import invalid: #{import.errors.full_messages.join(', ')}"
|
47
|
+
end
|
48
|
+
|
49
|
+
def redirect_url(import)
|
50
|
+
if import.order.complete?
|
51
|
+
main_app.order_url(import.order)
|
52
|
+
else
|
53
|
+
main_app.checkout_state_url(import.order.state)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def transaction_params
|
58
|
+
params.require(:transaction)
|
59
|
+
.permit(PERMITTED_BRAINTREE_TRANSACTION_PARAMS)
|
60
|
+
.merge({ payment_method: payment_method })
|
61
|
+
end
|
62
|
+
|
63
|
+
def payment_method
|
64
|
+
SolidusBraintree::Gateway.find(params[:payment_method_id])
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusBraintree
|
4
|
+
module BraintreeCheckoutHelper
|
5
|
+
def braintree_3ds_options_for(order)
|
6
|
+
ship_address = SolidusBraintree::Address.new(order.ship_address)
|
7
|
+
bill_address = SolidusBraintree::Address.new(order.bill_address)
|
8
|
+
{
|
9
|
+
nonce: nil, # populated after tokenization
|
10
|
+
bin: nil, # populated after tokenization
|
11
|
+
onLookupComplete: nil, # populated after tokenization
|
12
|
+
amount: order.total,
|
13
|
+
email: order.email,
|
14
|
+
billingAddress: {
|
15
|
+
givenName: bill_address.firstname,
|
16
|
+
surname: bill_address.lastname,
|
17
|
+
phoneNumber: bill_address.phone,
|
18
|
+
streetAddress: bill_address.address1,
|
19
|
+
extendedAddress: bill_address.address2,
|
20
|
+
locality: bill_address.city,
|
21
|
+
region: bill_address.state&.abbr,
|
22
|
+
postalCode: bill_address.zipcode,
|
23
|
+
countryCodeAlpha2: bill_address.country&.iso,
|
24
|
+
},
|
25
|
+
additionalInformation: {
|
26
|
+
shippingGivenName: ship_address.firstname,
|
27
|
+
shippingSurname: ship_address.lastname,
|
28
|
+
shippingPhone: ship_address.phone,
|
29
|
+
shippingAddress: {
|
30
|
+
streedAddress: ship_address.address1,
|
31
|
+
extendedAddress: ship_address.address2,
|
32
|
+
locality: ship_address.city,
|
33
|
+
region: ship_address.state&.abbr,
|
34
|
+
postalCode: ship_address.zipcode,
|
35
|
+
countryCodeAlpha2: ship_address.country&.iso,
|
36
|
+
}
|
37
|
+
}
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
def paypal_button_preference(key, store:)
|
42
|
+
store.braintree_configuration.preferences[key]
|
43
|
+
end
|
44
|
+
|
45
|
+
def venmo_button_style(store)
|
46
|
+
configuration = store.braintree_configuration
|
47
|
+
color = configuration.preferred_venmo_button_color
|
48
|
+
width = configuration.preferred_venmo_button_width
|
49
|
+
|
50
|
+
{ width: width, color: color }
|
51
|
+
end
|
52
|
+
|
53
|
+
def venmo_button_asset_url(style, active: false)
|
54
|
+
prefix = 'solidus_braintree/venmo/venmo_'
|
55
|
+
active_string = active ? 'active_' : ''
|
56
|
+
path = "#{prefix}#{active_string}#{style[:color]}_button_#{style[:width]}x48.svg"
|
57
|
+
asset_path(path)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<% id = payment_method.id %>
|
2
|
+
|
3
|
+
<%= render "spree/shared/braintree_head_scripts" %>
|
4
|
+
|
5
|
+
<% if current_store.braintree_configuration.paypal? %>
|
6
|
+
<%= render "spree/shared/paypal_checkout_button" %>
|
7
|
+
<% end %>
|
8
|
+
|
9
|
+
<% if current_store.braintree_configuration.credit_card? %>
|
10
|
+
<fieldset class="braintree-hosted-fields" data-braintree-hosted-fields data-id="<%= id %>" data-use-data-collector="<%= SolidusBraintree::Gateway.first.preferred_use_data_collector %>">
|
11
|
+
<%= render "spree/shared/braintree_hosted_fields", payment_method: payment_method %>
|
12
|
+
</fieldset>
|
13
|
+
<% end %>
|
14
|
+
|
15
|
+
<% if current_store.braintree_configuration.apple_pay? %>
|
16
|
+
<%= render "spree/shared/apple_pay_button", id: id %>
|
17
|
+
<% end %>
|
18
|
+
|
19
|
+
<% if current_store.braintree_configuration.venmo? %>
|
20
|
+
<%= render "spree/shared/venmo_button", payment_method: payment_method %>
|
21
|
+
<% end %>
|
22
|
+
|
23
|
+
<%= render "spree/shared/braintree_errors" %>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<%= payment.source.try(:display_payment_type) %>
|
2
|
+
|
3
|
+
<% if payment.source.try(:paypal?) %>
|
4
|
+
<% if payment.source.respond_to?(:paypal_funding_source) && payment.source.paypal_funding_source.present? %>
|
5
|
+
<%= t('spree.paypal_funding', funding: payment.source.display_paypal_funding_source) %>
|
6
|
+
<% end %>
|
7
|
+
<% elsif payment.source.try(:venmo?) %>
|
8
|
+
<%= payment.source.source_description %>
|
9
|
+
<% end %>
|
@@ -0,0 +1,27 @@
|
|
1
|
+
<% address = SolidusBraintree::Address.new(current_order.ship_address) %>
|
2
|
+
|
3
|
+
<button id="apple-pay-button" class="apple-pay-button"></button>
|
4
|
+
|
5
|
+
<script>
|
6
|
+
var applePayButtonElement = document.getElementById('apple-pay-button');
|
7
|
+
var applePayOptions = {
|
8
|
+
paymentMethodId: <%= id %>,
|
9
|
+
storeName: "<%= current_store.name %>",
|
10
|
+
orderEmail: "<%= current_order.email %>",
|
11
|
+
amount: "<%= current_order.total %>",
|
12
|
+
shippingContact: {
|
13
|
+
emailAddress: '<%= current_order.email %>',
|
14
|
+
givenName: '<%= address.firstname %>',
|
15
|
+
familyName: '<%= address.lastname %>',
|
16
|
+
phoneNumber: '<%= address.phone %>',
|
17
|
+
addressLines: ['<%= address.address1 %>','<%= address.address2 %>'],
|
18
|
+
locality: '<%= address.city %>',
|
19
|
+
administrativeArea: '<%= address.state.name %>',
|
20
|
+
postalCode: '<%= address.zipcode %>',
|
21
|
+
country: '<%= address.country.name %>',
|
22
|
+
countryCode: '<%= address.country.iso %>'
|
23
|
+
}
|
24
|
+
};
|
25
|
+
var button = new SolidusBraintree.createApplePayButton(applePayButtonElement, applePayOptions);
|
26
|
+
button.initialize();
|
27
|
+
</script>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<script type="text/javascript">
|
2
|
+
BraintreeError.DEFAULT = "<%= I18n.t('solidus_braintree.errors.default_error')%>"
|
3
|
+
BraintreeError.PAYPAL_POPUP_CLOSED = "<%= I18n.t('solidus_braintree.errors.paypal_popup_closed') %>"
|
4
|
+
BraintreeError.HOSTED_FIELDS_FIELDS_EMPTY = "<%= I18n.t('solidus_braintree.errors.empty_fields')%>"
|
5
|
+
BraintreeError.HOSTED_FIELDS_FIELDS_INVALID = "<%= I18n.t('solidus_braintree.errors.invalid_fields')%>"
|
6
|
+
BraintreeError.HOSTED_FIELDS_FAILED_TOKENIZATION = "<%= I18n.t('solidus_braintree.errors.invalid_card')%>"
|
7
|
+
BraintreeError.HOSTED_FIELDS_TOKENIZATION_NETWORK_ERROR = "<%= I18n.t('solidus_braintree.errors.network_error')%>"
|
8
|
+
BraintreeError.HOSTED_FIELDS_FIELD_DUPLICATE_IFRAME = "<%= I18n.t('solidus_braintree.errors.duplicate_iframe')%>"
|
9
|
+
BraintreeError.HOSTED_FIELDS_TOKENIZATION_FAIL_ON_DUPLICATE = "<%= I18n.t('solidus_braintree.errors.fail_on_duplicate')%>"
|
10
|
+
BraintreeError.HOSTED_FIELDS_TOKENIZATION_CVV_VERIFICATION_FAILED = "<%= I18n.t('solidus_braintree.errors.cvv_verification_failed')%>"
|
11
|
+
BraintreeError.THREEDS_AUTHENTICATION_FAILED = "<%= t('solidus_braintree.errors.threeds.authentication_failed') %>";
|
12
|
+
BraintreeError.THREEDS_CARDINAL_SDK_ERROR = "<%= t('solidus_braintree.errors.threeds.authentication_failed') %>";
|
13
|
+
BraintreeError.VENMO_CANCELED = "<%= t('solidus_braintree.errors.venmo.canceled') %>";
|
14
|
+
BraintreeError.VENMO_DESKTOP_CANCELED = "<%= t('solidus_braintree.errors.venmo.desktop_canceled') %>";
|
15
|
+
BraintreeError.VENMO_APP_CANCELED = "<%= t('solidus_braintree.errors.venmo.app_canceled') %>";
|
16
|
+
</script>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<% content_for :head do %>
|
2
|
+
<script src="https://js.braintreegateway.com/web/3.84.0/js/client.min.js"></script>
|
3
|
+
<script src="https://js.braintreegateway.com/web/3.84.0/js/data-collector.min.js"></script>
|
4
|
+
|
5
|
+
<% if current_store.braintree_configuration.paypal? %>
|
6
|
+
<script src="https://js.braintreegateway.com/web/3.84.0/js/paypal-checkout.min.js"></script>
|
7
|
+
<% end %>
|
8
|
+
|
9
|
+
<% if current_store.braintree_configuration.credit_card? %>
|
10
|
+
<script src="https://js.braintreegateway.com/web/3.84.0/js/hosted-fields.min.js"></script>
|
11
|
+
|
12
|
+
<% if current_store.braintree_configuration.three_d_secure? %>
|
13
|
+
<script src="https://js.braintreegateway.com/web/3.84.0/js/three-d-secure.min.js"></script>
|
14
|
+
<% end %>
|
15
|
+
<% end %>
|
16
|
+
|
17
|
+
<% if current_store.braintree_configuration.apple_pay? %>
|
18
|
+
<script src="https://js.braintreegateway.com/web/3.84.0/js/apple-pay.min.js"></script>
|
19
|
+
<% end %>
|
20
|
+
|
21
|
+
<% if current_store.braintree_configuration.venmo? %>
|
22
|
+
<script src="https://js.braintreegateway.com/web/3.84.0/js/venmo.min.js"></script>
|
23
|
+
<% end %>
|
24
|
+
|
25
|
+
<%= javascript_include_tag "spree/frontend/solidus_braintree/checkout" %>
|
26
|
+
<% end %>
|
@@ -0,0 +1,40 @@
|
|
1
|
+
<% if defined?(id) && !defined?(payment_method) %>
|
2
|
+
<% payment_method = Spree::PaymentMethod.find(id) %>
|
3
|
+
<% Spree::Deprecation.warn(
|
4
|
+
"passing id to _braintree_hosted_fields.html.erb is deprecated. Please pass the payment_method directly.",
|
5
|
+
caller
|
6
|
+
) %>
|
7
|
+
<% end %>
|
8
|
+
|
9
|
+
<% prefix = "payment_source[#{payment_method.id}]" %>
|
10
|
+
|
11
|
+
<div class="hosted-fields">
|
12
|
+
<div class="field" data-hook="card_number">
|
13
|
+
<%= label_tag "card_number#{payment_method.id}", Spree::CreditCard.human_attribute_name(:number), class: "required" %>
|
14
|
+
<div class="input" id="card_number<%= payment_method.id %>"></div>
|
15
|
+
</div>
|
16
|
+
|
17
|
+
<div class="field" data-hook="card_expiration">
|
18
|
+
<%= label_tag "card_expiry#{payment_method.id}", Spree::CreditCard.human_attribute_name(:expiration), class: "required" %>
|
19
|
+
<div class="input" id="card_expiry<%= payment_method.id %>"></div>
|
20
|
+
</div>
|
21
|
+
|
22
|
+
<div class="field" data-hook="card_code">
|
23
|
+
<%= label_tag "card_code#{payment_method.id}", Spree::CreditCard.human_attribute_name(:card_code), class: "required" %>
|
24
|
+
<div class="input" id="card_code<%= payment_method.id %>"></div>
|
25
|
+
</div>
|
26
|
+
|
27
|
+
<div class="clear"></div>
|
28
|
+
<input type="hidden" name="<%= prefix %>[payment_type]" value="<%= SolidusBraintree::Source::CREDIT_CARD %>">
|
29
|
+
<input type="hidden" id="payment_method_nonce" name="<%= prefix %>[nonce]">
|
30
|
+
<input type="hidden" id="device_data" name="<%= prefix %>[device_data]">
|
31
|
+
</div>
|
32
|
+
|
33
|
+
|
34
|
+
<script>
|
35
|
+
<% if current_store.braintree_configuration.three_d_secure? %>
|
36
|
+
var threeDSecureOptions = <%= raw braintree_3ds_options_for(current_order).to_json %>;
|
37
|
+
<% end -%>
|
38
|
+
var credit_card_fields_style = <%= raw payment_method.preferred_credit_card_fields_style.to_json %>
|
39
|
+
var placeholder_text = <%= raw payment_method.preferred_placeholder_text.to_json %>
|
40
|
+
</script>
|
@@ -0,0 +1,38 @@
|
|
1
|
+
<%= render "spree/shared/braintree_head_scripts" %>
|
2
|
+
|
3
|
+
<div id="paypal-button"></div>
|
4
|
+
<div data-pp-message data-pp-placement="payment" data-pp-amount="<%= current_order.total %>"></div>
|
5
|
+
|
6
|
+
<script>
|
7
|
+
var paypalOptions = {
|
8
|
+
flow: '<%= SolidusBraintree::Gateway.first.preferred_paypal_flow %>',
|
9
|
+
amount: '<%= current_order.total %>',
|
10
|
+
currency: '<%= current_order.currency %>',
|
11
|
+
enableShippingAddress: true,
|
12
|
+
buyerCountry: '<%= SolidusBraintree::Gateway.first.preferred_force_buyer_country %>',
|
13
|
+
environment: '<%= Rails.env.production? ? "production" : "sandbox" %>',
|
14
|
+
locale: '<%= paypal_button_preference(:paypal_button_locale, store: current_store) %>',
|
15
|
+
useDataCollector: <%= SolidusBraintree::Gateway.first.preferred_use_data_collector %>,
|
16
|
+
style: {
|
17
|
+
color: '<%= paypal_button_preference(:paypal_button_color, store: current_store) %>',
|
18
|
+
shape: '<%= paypal_button_preference(:paypal_button_shape, store: current_store) %>',
|
19
|
+
label: '<%= paypal_button_preference(:paypal_button_label, store: current_store) %>',
|
20
|
+
layout: '<%= paypal_button_preference(:paypal_button_layout, store: current_store) %>',
|
21
|
+
<% if paypal_button_preference(:paypal_button_layout, store: current_store) == "horizontal" %>
|
22
|
+
tagline: '<%= paypal_button_preference(:paypal_button_tagline, store: current_store) %>',
|
23
|
+
<% end %>
|
24
|
+
messaging: '<%= paypal_button_preference(:paypal_button_messaging, store: current_store) %>'
|
25
|
+
}
|
26
|
+
}
|
27
|
+
var options = {
|
28
|
+
restart_checkout: true
|
29
|
+
}
|
30
|
+
|
31
|
+
var button = new SolidusBraintree.createPaypalButton(
|
32
|
+
document.querySelector("#paypal-button"),
|
33
|
+
paypalOptions,
|
34
|
+
options
|
35
|
+
)
|
36
|
+
|
37
|
+
button.initialize();
|
38
|
+
</script>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<div id="paypal-button"></div>
|
2
|
+
<div data-pp-message data-pp-placement="payment" data-pp-amount="<%= @order.total %>"></div>
|
3
|
+
|
4
|
+
<script>
|
5
|
+
var address = <%= sanitize SolidusBraintree::Address.new(current_order.ship_address).to_json %>
|
6
|
+
|
7
|
+
var paypalOptions = {
|
8
|
+
flow: '<%= SolidusBraintree::Gateway.first.preferred_paypal_flow %>',
|
9
|
+
amount: '<%= current_order.total %>',
|
10
|
+
currency: '<%= current_order.currency %>',
|
11
|
+
enableShippingAddress: true,
|
12
|
+
venmoFunding: <%= SolidusBraintree::Gateway.first.preferred_enable_venmo_funding %>,
|
13
|
+
buyerCountry: '<%= SolidusBraintree::Gateway.first.preferred_force_buyer_country %>',
|
14
|
+
shippingAddressOverride: address,
|
15
|
+
shippingAddressEditable: false,
|
16
|
+
environment: '<%= Rails.env.production? ? "production" : "sandbox" %>',
|
17
|
+
locale: '<%= paypal_button_preference(:paypal_button_locale, store: current_store) %>',
|
18
|
+
style: {
|
19
|
+
color: '<%= paypal_button_preference(:paypal_button_color, store: current_store) %>',
|
20
|
+
shape: '<%= paypal_button_preference(:paypal_button_shape, store: current_store) %>',
|
21
|
+
label: '<%= paypal_button_preference(:paypal_button_label, store: current_store) %>',
|
22
|
+
layout: '<%= paypal_button_preference(:paypal_button_layout, store: current_store) %>',
|
23
|
+
<% if paypal_button_preference(:paypal_button_layout, store: current_store) == "horizontal" %>
|
24
|
+
tagline: '<%= paypal_button_preference(:paypal_button_tagline, store: current_store) %>',
|
25
|
+
<% end %>
|
26
|
+
messaging: '<%= paypal_button_preference(:paypal_button_messaging, store: current_store) %>'
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
var button = new SolidusBraintree.createPaypalButton(document.querySelector("#paypal-button"), paypalOptions);
|
31
|
+
button.initialize();
|
32
|
+
</script>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<%= render "spree/shared/braintree_head_scripts" %>
|
2
|
+
|
3
|
+
<div data-pp-message data-pp-placement="<%= options[:placement] %>" data-pp-amount="<%= options[:total] %>"></div>
|
4
|
+
|
5
|
+
<script>
|
6
|
+
var message = new SolidusBraintree.createPaypalMessaging(
|
7
|
+
{
|
8
|
+
currency: "<%= options[:currency] %>"
|
9
|
+
}
|
10
|
+
)
|
11
|
+
|
12
|
+
message.initialize();
|
13
|
+
</script>
|
@@ -0,0 +1,33 @@
|
|
1
|
+
<%= button_tag '', id: 'venmo-button', class: 'venmo-button', type: 'button' %>
|
2
|
+
|
3
|
+
<% store = Spree::Store.default %>
|
4
|
+
<% style = venmo_button_style(store) %>
|
5
|
+
|
6
|
+
<style>
|
7
|
+
.venmo-button {
|
8
|
+
width: <%= style[:width] %>px;
|
9
|
+
background-image: url('<%= venmo_button_asset_url(style)%>');
|
10
|
+
}
|
11
|
+
.venmo-button:active, .venmo-button:hover {
|
12
|
+
background-color: transparent !important;
|
13
|
+
background-image: url('<%= venmo_button_asset_url(style, active: true)%>') !important;
|
14
|
+
}
|
15
|
+
</style>
|
16
|
+
|
17
|
+
<% prefix = "payment_source[#{payment_method.id}]" %>
|
18
|
+
|
19
|
+
<div class="venmo-fields">
|
20
|
+
<div class="clear"></div>
|
21
|
+
<input disabled type="hidden" name="<%= prefix %>[payment_type]" value="<%= SolidusBraintree::Source::VENMO %>">
|
22
|
+
<input disabled type="hidden" id="venmo_payment_method_nonce" name="<%= prefix %>[nonce]">
|
23
|
+
</div>
|
24
|
+
|
25
|
+
<script>
|
26
|
+
var venmoButtonElement = document.getElementById('venmo-button');
|
27
|
+
var venmoOptions = {
|
28
|
+
newBrowserTabSupported: <%= SolidusBraintree::Gateway.first.preferred_venmo_new_tab_support %>,
|
29
|
+
flow: '<%= SolidusBraintree::Gateway.first.preferred_paypal_flow %>'
|
30
|
+
};
|
31
|
+
var button = new SolidusBraintree.createVenmoButton(venmoButtonElement, venmoOptions);
|
32
|
+
button.initialize();
|
33
|
+
</script>
|
@@ -0,0 +1,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
|