solidus_braintree 2.0.0 → 3.0.1
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 +42 -9
- data/.gitignore +1 -0
- data/.rubocop.yml +8 -1
- data/CHANGELOG.md +1 -189
- data/OLD_CHANGELOG.md +199 -0
- data/Rakefile +7 -1
- data/app/assets/config/solidus_braintree_manifest.js +0 -1
- data/app/assets/javascripts/spree/backend/solidus_braintree.js +4 -4
- data/app/models/solidus_braintree/gateway.rb +5 -1
- data/app/models/solidus_braintree/response.rb +1 -1
- data/app/models/solidus_braintree/source.rb +5 -0
- data/app/models/solidus_braintree/transaction.rb +1 -1
- data/app/models/solidus_braintree/transaction_import.rb +1 -0
- data/bin/dummy-app +37 -0
- data/bin/rails-dummy-app +17 -0
- data/bin/rspec +11 -0
- data/bin/sandbox +20 -62
- data/db/migrate/20230210104310_add_device_data_to_braintree_sources.rb +5 -0
- data/lib/generators/solidus_braintree/install/install_generator.rb +134 -34
- data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/javascripts/spree/frontend/paypal_button.js +1 -1
- data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/ajax.js +13 -0
- data/{app/assets/javascripts → lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend}/solidus_braintree/apple_pay_button.js +2 -2
- data/{app/assets/javascripts → lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend}/solidus_braintree/checkout.js +10 -5
- 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/{app/assets/javascripts → lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend}/solidus_braintree/paypal_button.js +4 -3
- data/{app/assets/javascripts → lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend}/solidus_braintree/paypal_messaging.js +1 -1
- data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree/promise.js +20 -0
- data/{app/assets/javascripts → lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend}/solidus_braintree/venmo_button.js +1 -1
- data/lib/generators/solidus_braintree/install/templates/app/assets/javascripts/spree/frontend/solidus_braintree.js +1 -0
- data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/stylesheets/spree/frontend/solidus_braintree.scss +11 -0
- data/lib/{controllers/frontend → generators/solidus_braintree/install/templates/app/controllers}/solidus_braintree/checkouts_controller.rb +1 -1
- data/lib/{controllers/frontend → generators/solidus_braintree/install/templates/app/controllers}/solidus_braintree/transactions_controller.rb +5 -4
- data/lib/generators/solidus_braintree/install/templates/app/views/checkouts/existing_payment/_braintree.html.erb +2 -0
- data/lib/{views/frontend/spree/checkout → generators/solidus_braintree/install/templates/app/views/checkouts}/payment/_braintree.html.erb +1 -1
- data/lib/{views/frontend/solidus_braintree/payments/_payment.html.erb → generators/solidus_braintree/install/templates/app/views/payments/_braintree_payment_details.html.erb} +0 -3
- data/{app → lib/generators/solidus_braintree/install/templates/app}/views/spree/shared/_apple_pay_button.html.erb +1 -1
- data/{app → lib/generators/solidus_braintree/install/templates/app}/views/spree/shared/_braintree_head_scripts.html.erb +1 -1
- data/{app → lib/generators/solidus_braintree/install/templates/app}/views/spree/shared/_braintree_hosted_fields.html.erb +1 -4
- data/lib/{views/frontend → generators/solidus_braintree/install/templates/app/views}/spree/shared/_paypal_checkout_button.html.erb +1 -0
- data/lib/solidus_braintree/engine.rb +15 -10
- data/lib/solidus_braintree/version.rb +1 -1
- data/solidus_braintree.gemspec +4 -8
- data/spec/controllers/solidus_braintree/checkouts_controller_spec.rb +2 -2
- data/spec/controllers/solidus_braintree/client_tokens_controller_spec.rb +2 -2
- data/spec/controllers/solidus_braintree/configurations_controller_spec.rb +2 -2
- data/spec/controllers/solidus_braintree/transactions_controller_spec.rb +3 -3
- data/spec/fixtures/views/carts/_cart_footer.html.erb +18 -0
- data/spec/helpers/solidus_braintree/braintree_admin_helper_spec.rb +1 -1
- data/spec/helpers/solidus_braintree/braintree_checkout_helper_spec.rb +1 -1
- data/spec/models/solidus_braintree/address_spec.rb +1 -1
- data/spec/models/solidus_braintree/avs_result_spec.rb +1 -1
- data/spec/models/solidus_braintree/gateway_spec.rb +35 -3
- data/spec/models/solidus_braintree/response_spec.rb +1 -1
- data/spec/models/solidus_braintree/source_spec.rb +17 -1
- data/spec/models/solidus_braintree/transaction_address_spec.rb +2 -2
- data/spec/models/solidus_braintree/transaction_import_spec.rb +2 -2
- data/spec/models/solidus_braintree/transaction_spec.rb +2 -2
- data/spec/models/spree/store_spec.rb +2 -2
- data/spec/requests/spree/api/orders_controller_spec.rb +2 -2
- data/spec/solidus_braintree_helper.rb +7 -0
- data/{lib/solidus_braintree/testing_support → spec/support/solidus_braintree}/factories.rb +17 -15
- data/spec/support/{order_ready_for_payment.rb → solidus_braintree/order_ready_for_payment.rb} +9 -2
- data/spec/support/solidus_braintree/order_walkthrough.rb +87 -0
- data/spec/support/solidus_braintree/with_prepended_view_fixtures.rb +19 -0
- data/spec/{features → system}/backend/configuration_spec.rb +2 -2
- data/spec/{features → system}/backend/new_payment_spec.rb +3 -4
- data/spec/{features → system}/frontend/braintree_credit_card_checkout_spec.rb +23 -15
- data/spec/{features → system}/frontend/paypal_checkout_spec.rb +6 -3
- data/spec/{features → system}/frontend/venmo_checkout_spec.rb +8 -9
- metadata +95 -114
- data/app/assets/javascripts/solidus_braintree/frontend.js +0 -14
- data/app/assets/javascripts/spree/frontend/solidus_braintree.js +0 -1
- data/app/decorators/controllers/solidus_braintree/checkout_controller_decorator.rb +0 -11
- data/app/decorators/controllers/solidus_braintree/orders_controller_decorator.rb +0 -11
- data/app/overrides/spree/payments/payment/add_paypal_funding_source_to_payment.rb +0 -9
- data/app/views/spree/checkout/existing_payment/_braintree.html.erb +0 -10
- data/spec/fixtures/views/spree/orders/edit.html.erb +0 -50
- data/spec/spec_helper.rb +0 -32
- data/spec/support/views.rb +0 -1
- /data/app/assets/javascripts/{solidus_braintree → spree/backend/solidus_braintree}/client.js +0 -0
- /data/app/assets/javascripts/{solidus_braintree → spree/backend/solidus_braintree}/constants.js +0 -0
- /data/app/assets/javascripts/{solidus_braintree → spree/backend/solidus_braintree}/hosted_form.js +0 -0
- /data/app/assets/javascripts/{solidus_braintree → spree/backend/solidus_braintree}/promise.js +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_active_blue_button_280x48.svg +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_active_blue_button_320x48.svg +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_active_blue_button_375x48.svg +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_active_white_button_280x48.svg +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_active_white_button_320x48.svg +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_active_white_button_375x48.svg +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_blue_acceptance_mark.svg +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_blue_button_280x48.svg +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_blue_button_320x48.svg +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_blue_button_375x48.svg +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_blue_logo.svg +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_white_acceptance_mark.svg +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_white_button_280x48.svg +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_white_button_320x48.svg +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_white_button_375x48.svg +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/assets/images/solidus_braintree/venmo/venmo_white_logo.svg +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/helpers/solidus_braintree/braintree_checkout_helper.rb +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/views/spree/shared/_braintree_errors.html.erb +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/views/spree/shared/_paypal_cart_button.html.erb +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/views/spree/shared/_paypal_messaging.html.erb +0 -0
- /data/{app → lib/generators/solidus_braintree/install/templates/app}/views/spree/shared/_venmo_button.html.erb +0 -0
- /data/lib/generators/solidus_braintree/install/templates/{initializer.rb → config/initializers/solidus_braintree.rb} +0 -0
- /data/spec/support/{capybara.rb → solidus_braintree/capybara.rb} +0 -0
- /data/spec/support/{gateway_helpers.rb → solidus_braintree/gateway_helpers.rb} +0 -0
- /data/spec/support/{vcr.rb → solidus_braintree/vcr.rb} +0 -0
@@ -0,0 +1,239 @@
|
|
1
|
+
/**
|
2
|
+
* Braintree client interface
|
3
|
+
* @external "braintree.Client"
|
4
|
+
* @see {@link https://braintree.github.io/braintree-web/current/Client.html|Braintree Client Docs}
|
5
|
+
**/
|
6
|
+
|
7
|
+
/**
|
8
|
+
* Braintree paypal interface
|
9
|
+
* @external "braintree.PayPal"
|
10
|
+
* @see {@link https://braintree.github.io/braintree-web/current/PayPal.html|Braintree Paypal Docs}
|
11
|
+
**/
|
12
|
+
|
13
|
+
/**
|
14
|
+
* Braintree paypal interface
|
15
|
+
* @external "braintree.ApplePay"
|
16
|
+
* @see {@link https://braintree.github.io/braintree-web/current/ApplePay.html|Braintree Apple Pay Docs}
|
17
|
+
**/
|
18
|
+
|
19
|
+
/**
|
20
|
+
* Braintree dataCollector interface
|
21
|
+
* @external "braintree.DataCollector"
|
22
|
+
* @see {@link https://braintree.github.io/braintree-web/current/DataCollector.html|Braintree DataCollector Docs}
|
23
|
+
**/
|
24
|
+
|
25
|
+
/**
|
26
|
+
* jQuery.Deferred interface
|
27
|
+
*
|
28
|
+
* We use this for our promises because ES6 promises are non standard, and because jquery 1/2
|
29
|
+
* promises do not play nicely with them.
|
30
|
+
* @external "jQuery.Deferred"
|
31
|
+
* @see {@link https://api.jquery.com/category/deferred-object/|jQuery Deferred Documentation}
|
32
|
+
**/
|
33
|
+
|
34
|
+
/**
|
35
|
+
* Represents a wrapper around the braintree js library.
|
36
|
+
*
|
37
|
+
* This class is responsible for fetching tokens from a solidus store and using them
|
38
|
+
* to manage a braintree client. It takes a number of options as capabilities for the client
|
39
|
+
* depending on if you want to use use the data collector or paypal.
|
40
|
+
*
|
41
|
+
* We use this class mostly to hide the token operations for users.
|
42
|
+
*
|
43
|
+
* After creating the class, a call should be made to initialize before using it.
|
44
|
+
* @see initialize
|
45
|
+
*
|
46
|
+
* @constructor
|
47
|
+
* @param {Object} config Initalization options for the client
|
48
|
+
* @param {Boolean} config.useDataCollector Use data collector capabilities for the braintree client
|
49
|
+
* @param {Boolean} config.usePaypal Use Paypal capabilities for the braintree client
|
50
|
+
* @param {requestCallback} config.readyCallback A callback to be invoked when the client is ready to go.
|
51
|
+
* @param {Number} config.paymentMethodId A number indicating a specific payment method to be preferrred.
|
52
|
+
*
|
53
|
+
**/
|
54
|
+
SolidusBraintree.Client = function(config) {
|
55
|
+
this.paymentMethodId = config.paymentMethodId;
|
56
|
+
this.readyCallback = config.readyCallback;
|
57
|
+
this.useDataCollector = config.useDataCollector;
|
58
|
+
this.usePaypal = config.usePaypal;
|
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;
|
64
|
+
|
65
|
+
this._braintreeInstance = null;
|
66
|
+
this._dataCollectorInstance = null;
|
67
|
+
this._paypalInstance = null;
|
68
|
+
this._venmoInstance = null;
|
69
|
+
this._threeDSecureInstance = null;
|
70
|
+
};
|
71
|
+
|
72
|
+
/**
|
73
|
+
* Fetches a client token from the backend and initializes the braintree client.
|
74
|
+
* @returns {external:"jQuery.Deferred"} Promise to be invoked after initialization is complete
|
75
|
+
**/
|
76
|
+
SolidusBraintree.Client.prototype.initialize = function() {
|
77
|
+
var initializationPromise = this._fetchToken().
|
78
|
+
then(this._createBraintreeInstance.bind(this));
|
79
|
+
|
80
|
+
if (this.useDataCollector) {
|
81
|
+
initializationPromise = initializationPromise.then(this._createDataCollector.bind(this));
|
82
|
+
}
|
83
|
+
|
84
|
+
if (this.usePaypal) {
|
85
|
+
initializationPromise = initializationPromise.then(this._createPaypal.bind(this));
|
86
|
+
}
|
87
|
+
|
88
|
+
if (this.useApplepay) {
|
89
|
+
initializationPromise = initializationPromise.then(this._createApplepay.bind(this));
|
90
|
+
}
|
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
|
+
|
100
|
+
return initializationPromise.then(this._invokeReadyCallback.bind(this));
|
101
|
+
};
|
102
|
+
|
103
|
+
/**
|
104
|
+
* Returns the braintree client instance
|
105
|
+
* @returns {external:"braintree.Client"} The braintree client that was initialized by this class
|
106
|
+
**/
|
107
|
+
SolidusBraintree.Client.prototype.getBraintreeInstance = function() {
|
108
|
+
return this._braintreeInstance;
|
109
|
+
};
|
110
|
+
|
111
|
+
/**
|
112
|
+
* Returns the braintree paypal instance
|
113
|
+
* @returns {external:"braintree.PayPal"} The braintree paypal that was initialized by this class
|
114
|
+
**/
|
115
|
+
SolidusBraintree.Client.prototype.getPaypalInstance = function() {
|
116
|
+
return this._paypalInstance;
|
117
|
+
};
|
118
|
+
|
119
|
+
/**
|
120
|
+
* Returns the braintree Apple Pay instance
|
121
|
+
* @returns {external:"braintree.ApplePay"} The Braintree Apple Pay that was initialized by this class
|
122
|
+
**/
|
123
|
+
SolidusBraintree.Client.prototype.getApplepayInstance = function() {
|
124
|
+
return this._applepayInstance;
|
125
|
+
};
|
126
|
+
|
127
|
+
/**
|
128
|
+
* Returns the braintree Venmo instance
|
129
|
+
* @returns {external:"braintree.Venmo"} The Braintree Venmo that was initialized by this class
|
130
|
+
**/
|
131
|
+
SolidusBraintree.Client.prototype.getVenmoInstance = function() {
|
132
|
+
return this._venmoInstance;
|
133
|
+
};
|
134
|
+
|
135
|
+
/**
|
136
|
+
* Returns the braintree dataCollector instance
|
137
|
+
* @returns {external:"braintree.DataCollector"} The braintree dataCollector that was initialized by this class
|
138
|
+
**/
|
139
|
+
SolidusBraintree.Client.prototype.getDataCollectorInstance = function() {
|
140
|
+
return this._dataCollectorInstance;
|
141
|
+
};
|
142
|
+
|
143
|
+
|
144
|
+
SolidusBraintree.Client.prototype._fetchToken = function() {
|
145
|
+
var payload = {
|
146
|
+
dataType: 'json',
|
147
|
+
type: 'POST',
|
148
|
+
url: SolidusBraintree.config.paths.clientTokens,
|
149
|
+
error: function(xhr) {
|
150
|
+
console.error("Error fetching braintree token");
|
151
|
+
}
|
152
|
+
};
|
153
|
+
|
154
|
+
if (this.paymentMethodId) {
|
155
|
+
payload.data = {
|
156
|
+
payment_method_id: this.paymentMethodId
|
157
|
+
};
|
158
|
+
}
|
159
|
+
|
160
|
+
return SolidusBraintree.ajax(payload);
|
161
|
+
};
|
162
|
+
|
163
|
+
SolidusBraintree.Client.prototype._createBraintreeInstance = function(tokenResponse) {
|
164
|
+
this.paymentMethodId = tokenResponse.payment_method_id;
|
165
|
+
|
166
|
+
return SolidusBraintree.PromiseShim.convertBraintreePromise(braintree.client.create, [{
|
167
|
+
authorization: tokenResponse.client_token
|
168
|
+
}]).then(function (clientInstance) {
|
169
|
+
this._braintreeInstance = clientInstance;
|
170
|
+
return clientInstance;
|
171
|
+
}.bind(this));
|
172
|
+
};
|
173
|
+
|
174
|
+
SolidusBraintree.Client.prototype._invokeReadyCallback = function() {
|
175
|
+
if(this.readyCallback) {
|
176
|
+
this.readyCallback(this._braintreeInstance);
|
177
|
+
}
|
178
|
+
|
179
|
+
return this;
|
180
|
+
};
|
181
|
+
|
182
|
+
SolidusBraintree.Client.prototype._createDataCollector = function() {
|
183
|
+
return SolidusBraintree.PromiseShim.convertBraintreePromise(braintree.dataCollector.create, [{
|
184
|
+
client: this._braintreeInstance,
|
185
|
+
paypal: !!this.usePaypal
|
186
|
+
}]).then(function (dataCollectorInstance) {
|
187
|
+
this._dataCollectorInstance = dataCollectorInstance;
|
188
|
+
return dataCollectorInstance;
|
189
|
+
}.bind(this));
|
190
|
+
};
|
191
|
+
|
192
|
+
SolidusBraintree.Client.prototype._createPaypal = function() {
|
193
|
+
return SolidusBraintree.PromiseShim.convertBraintreePromise(braintree.paypalCheckout.create, [{
|
194
|
+
client: this._braintreeInstance
|
195
|
+
}]).then(function (paypalInstance) {
|
196
|
+
this._paypalInstance = paypalInstance;
|
197
|
+
return paypalInstance;
|
198
|
+
}.bind(this), function(error) {
|
199
|
+
console.error(error.name + ':', error.message);
|
200
|
+
});
|
201
|
+
};
|
202
|
+
|
203
|
+
SolidusBraintree.Client.prototype._createApplepay = function() {
|
204
|
+
return SolidusBraintree.PromiseShim.convertBraintreePromise(braintree.applePay.create, [{
|
205
|
+
client: this._braintreeInstance
|
206
|
+
}]).then(function (applePayInstance) {
|
207
|
+
this._applepayInstance = applePayInstance;
|
208
|
+
return applePayInstance;
|
209
|
+
}.bind(this));
|
210
|
+
};
|
211
|
+
|
212
|
+
SolidusBraintree.Client.prototype._createVenmo = function() {
|
213
|
+
return SolidusBraintree.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
|
+
SolidusBraintree.Client.prototype._createThreeDSecure = function() {
|
231
|
+
return SolidusBraintree.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
|
+
};
|
@@ -0,0 +1,89 @@
|
|
1
|
+
SolidusBraintree = {
|
2
|
+
APPLE_PAY_API_VERSION: 1,
|
3
|
+
|
4
|
+
config: {
|
5
|
+
paths: {
|
6
|
+
clientTokens: Solidus.pathFor('solidus_braintree/client_token'),
|
7
|
+
transactions: Solidus.pathFor('solidus_braintree/transactions')
|
8
|
+
},
|
9
|
+
|
10
|
+
// Override to provide your own error messages.
|
11
|
+
braintreeErrorHandle: function(braintreeError) {
|
12
|
+
BraintreeError.getErrorFromSlug(braintreeError.code);
|
13
|
+
SolidusBraintree.showError(error);
|
14
|
+
},
|
15
|
+
|
16
|
+
classes: {
|
17
|
+
hostedForm: function() {
|
18
|
+
return SolidusBraintree.HostedForm;
|
19
|
+
},
|
20
|
+
|
21
|
+
client: function() {
|
22
|
+
return SolidusBraintree.Client;
|
23
|
+
},
|
24
|
+
|
25
|
+
paypalButton: function() {
|
26
|
+
return SolidusBraintree.PaypalButton;
|
27
|
+
},
|
28
|
+
|
29
|
+
paypalMessaging: function() {
|
30
|
+
return SolidusBraintree.PaypalMessaging;
|
31
|
+
},
|
32
|
+
|
33
|
+
applepayButton: function() {
|
34
|
+
return SolidusBraintree.ApplepayButton;
|
35
|
+
},
|
36
|
+
|
37
|
+
venmoButton: function() {
|
38
|
+
return SolidusBraintree.VenmoButton;
|
39
|
+
}
|
40
|
+
}
|
41
|
+
},
|
42
|
+
|
43
|
+
showError: function(error) {
|
44
|
+
var $contentContainer = $("main");
|
45
|
+
var $flash = $("<div class='flash error'>" + error + "</div>");
|
46
|
+
$contentContainer.before($flash);
|
47
|
+
$flash.show().delay(5000).fadeOut(500);
|
48
|
+
},
|
49
|
+
|
50
|
+
createHostedForm: function() {
|
51
|
+
return SolidusBraintree._factory(SolidusBraintree.config.classes.hostedForm(), arguments);
|
52
|
+
},
|
53
|
+
|
54
|
+
createClient: function() {
|
55
|
+
return SolidusBraintree._factory(SolidusBraintree.config.classes.client(), arguments);
|
56
|
+
},
|
57
|
+
|
58
|
+
createPaypalButton: function() {
|
59
|
+
return SolidusBraintree._factory(SolidusBraintree.config.classes.paypalButton(), arguments);
|
60
|
+
},
|
61
|
+
|
62
|
+
createPaypalMessaging: function() {
|
63
|
+
return SolidusBraintree._factory(SolidusBraintree.config.classes.paypalMessaging(), arguments);
|
64
|
+
},
|
65
|
+
|
66
|
+
createApplePayButton: function() {
|
67
|
+
return SolidusBraintree._factory(SolidusBraintree.config.classes.applepayButton(), arguments);
|
68
|
+
},
|
69
|
+
|
70
|
+
createVenmoButton: function() {
|
71
|
+
return SolidusBraintree._factory(SolidusBraintree.config.classes.venmoButton(), arguments);
|
72
|
+
},
|
73
|
+
|
74
|
+
_factory: function(klass, args) {
|
75
|
+
var normalizedArgs = Array.prototype.slice.call(args);
|
76
|
+
return new (Function.prototype.bind.apply(klass, [null].concat(normalizedArgs)));
|
77
|
+
}
|
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
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into including all the files listed below.
|
2
|
+
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
|
3
|
+
// be included in the compiled file accessible from http://example.com/assets/application.js
|
4
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
5
|
+
// the compiled file.
|
6
|
+
//
|
7
|
+
//= require spree/frontend/solidus_braintree/constants
|
8
|
+
//= require spree/frontend/solidus_braintree/ajax
|
9
|
+
//= require spree/frontend/solidus_braintree/promise
|
10
|
+
//= require spree/frontend/solidus_braintree/client
|
11
|
+
//= require spree/frontend/solidus_braintree/hosted_form
|
12
|
+
//= require spree/frontend/solidus_braintree/paypal_button
|
13
|
+
//= require spree/frontend/solidus_braintree/paypal_messaging
|
14
|
+
//= require spree/frontend/solidus_braintree/apple_pay_button
|
15
|
+
//= require spree/frontend/solidus_braintree/venmo_button
|
@@ -0,0 +1,48 @@
|
|
1
|
+
SolidusBraintree.HostedForm = function(paymentMethodId, useDataCollector) {
|
2
|
+
this.paymentMethodId = paymentMethodId;
|
3
|
+
this.useDataCollector = useDataCollector;
|
4
|
+
this.client = null;
|
5
|
+
};
|
6
|
+
|
7
|
+
SolidusBraintree.HostedForm.prototype.initialize = function() {
|
8
|
+
this.client = SolidusBraintree.createClient({
|
9
|
+
paymentMethodId: this.paymentMethodId,
|
10
|
+
useThreeDSecure: (typeof(window.threeDSecureOptions) !== 'undefined'),
|
11
|
+
useDataCollector: this.useDataCollector,
|
12
|
+
});
|
13
|
+
|
14
|
+
return this.client.initialize().
|
15
|
+
then(this._createHostedFields.bind(this));
|
16
|
+
};
|
17
|
+
|
18
|
+
SolidusBraintree.HostedForm.prototype._createHostedFields = function () {
|
19
|
+
if (!this.client) {
|
20
|
+
throw new Error("Client not initialized, please call initialize first!");
|
21
|
+
}
|
22
|
+
|
23
|
+
var opts = {
|
24
|
+
_solidusClient: this.client,
|
25
|
+
client: this.client.getBraintreeInstance(),
|
26
|
+
|
27
|
+
fields: {
|
28
|
+
number: {
|
29
|
+
selector: "#card_number" + this.paymentMethodId,
|
30
|
+
placeholder: placeholder_text["number"]
|
31
|
+
},
|
32
|
+
|
33
|
+
cvv: {
|
34
|
+
selector: "#card_code" + this.paymentMethodId,
|
35
|
+
placeholder: placeholder_text["cvv"]
|
36
|
+
},
|
37
|
+
|
38
|
+
expirationDate: {
|
39
|
+
selector: "#card_expiry" + this.paymentMethodId,
|
40
|
+
placeholder: placeholder_text["expirationDate"]
|
41
|
+
}
|
42
|
+
},
|
43
|
+
|
44
|
+
styles: credit_card_fields_style
|
45
|
+
};
|
46
|
+
|
47
|
+
return SolidusBraintree.PromiseShim.convertBraintreePromise(braintree.hostedFields.create, [opts]);
|
48
|
+
};
|
@@ -1,4 +1,4 @@
|
|
1
|
-
//= require solidus_braintree/constants
|
1
|
+
//= require spree/frontend/solidus_braintree/constants
|
2
2
|
/**
|
3
3
|
* Constructor for PayPal button object
|
4
4
|
* @constructor
|
@@ -99,7 +99,7 @@ SolidusBraintree.PaypalButton.prototype._tokenizeCallback = function(tokenizeErr
|
|
99
99
|
|
100
100
|
var params = this._transactionParams(payload);
|
101
101
|
|
102
|
-
return
|
102
|
+
return SolidusBraintree.ajax({
|
103
103
|
url: SolidusBraintree.config.paths.transactions,
|
104
104
|
type: 'POST',
|
105
105
|
dataType: 'json',
|
@@ -144,7 +144,8 @@ SolidusBraintree.PaypalButton.prototype._transactionParams = function(payload) {
|
|
144
144
|
"nonce" : payload.nonce,
|
145
145
|
"payment_type" : payload.type,
|
146
146
|
"paypal_funding_source": SolidusBraintree.fundingSource,
|
147
|
-
"address_attributes" : this._addressParams(payload)
|
147
|
+
"address_attributes" : this._addressParams(payload),
|
148
|
+
"device_data": this._client._dataCollectorInstance.deviceData
|
148
149
|
}
|
149
150
|
};
|
150
151
|
};
|
@@ -0,0 +1,20 @@
|
|
1
|
+
SolidusBraintree.PromiseShim = {
|
2
|
+
convertBraintreePromise: function(fn, args, context) {
|
3
|
+
var jqPromise = $.Deferred();
|
4
|
+
|
5
|
+
args = args || [];
|
6
|
+
context = context || this;
|
7
|
+
|
8
|
+
args = args.concat(function(error, data) {
|
9
|
+
if (error) {
|
10
|
+
jqPromise.reject(error);
|
11
|
+
} else {
|
12
|
+
jqPromise.resolve(data);
|
13
|
+
}
|
14
|
+
});
|
15
|
+
|
16
|
+
fn.apply(context, args);
|
17
|
+
|
18
|
+
return jqPromise.promise();
|
19
|
+
}
|
20
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
//= require spree/frontend/solidus_braintree/frontend
|
@@ -49,3 +49,14 @@ the installer will append this file to the app vendored assets here: 'vendor/ass
|
|
49
49
|
.venmo-button.visible {
|
50
50
|
visibility: visible;
|
51
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
|
+
}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module SolidusBraintree
|
4
|
-
class TransactionsController <
|
4
|
+
class TransactionsController < StoreController
|
5
5
|
class InvalidImportError < StandardError; end
|
6
6
|
|
7
7
|
PERMITTED_BRAINTREE_TRANSACTION_PARAMS = [
|
@@ -13,7 +13,8 @@ module SolidusBraintree
|
|
13
13
|
{ address_attributes: [
|
14
14
|
:country_code, :country_name, :name, :city, :zip, :state_code,
|
15
15
|
:address_line_1, :address_line_2, :first_name, :last_name
|
16
|
-
] }
|
16
|
+
] },
|
17
|
+
:device_data
|
17
18
|
].freeze
|
18
19
|
|
19
20
|
def create
|
@@ -48,9 +49,9 @@ module SolidusBraintree
|
|
48
49
|
|
49
50
|
def redirect_url(import)
|
50
51
|
if import.order.complete?
|
51
|
-
|
52
|
+
main_app.order_url(import.order)
|
52
53
|
else
|
53
|
-
|
54
|
+
main_app.checkout_state_url(import.order.state)
|
54
55
|
end
|
55
56
|
end
|
56
57
|
|
@@ -7,7 +7,7 @@
|
|
7
7
|
<% end %>
|
8
8
|
|
9
9
|
<% if current_store.braintree_configuration.credit_card? %>
|
10
|
-
<fieldset class="braintree-hosted-fields" data-braintree-hosted-fields data-id="<%= id %>">
|
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
11
|
<%= render "spree/shared/braintree_hosted_fields", payment_method: payment_method %>
|
12
12
|
</fieldset>
|
13
13
|
<% end %>
|
@@ -1,12 +1,9 @@
|
|
1
|
-
<br />
|
2
1
|
<%= payment.source.try(:display_payment_type) %>
|
3
2
|
|
4
3
|
<% if payment.source.try(:paypal?) %>
|
5
4
|
<% if payment.source.respond_to?(:paypal_funding_source) && payment.source.paypal_funding_source.present? %>
|
6
|
-
<br />
|
7
5
|
<%= t('spree.paypal_funding', funding: payment.source.display_paypal_funding_source) %>
|
8
6
|
<% end %>
|
9
7
|
<% elsif payment.source.try(:venmo?) %>
|
10
|
-
<br />
|
11
8
|
<%= payment.source.source_description %>
|
12
9
|
<% end %>
|
@@ -22,15 +22,12 @@
|
|
22
22
|
<div class="field" data-hook="card_code">
|
23
23
|
<%= label_tag "card_code#{payment_method.id}", Spree::CreditCard.human_attribute_name(:card_code), class: "required" %>
|
24
24
|
<div class="input" id="card_code<%= payment_method.id %>"></div>
|
25
|
-
|
26
|
-
<a href="/content/cvv" class="info cvvLink" target="_blank">
|
27
|
-
(<%= I18n.t("spree.what_is_this") %>)
|
28
|
-
</a>
|
29
25
|
</div>
|
30
26
|
|
31
27
|
<div class="clear"></div>
|
32
28
|
<input type="hidden" name="<%= prefix %>[payment_type]" value="<%= SolidusBraintree::Source::CREDIT_CARD %>">
|
33
29
|
<input type="hidden" id="payment_method_nonce" name="<%= prefix %>[nonce]">
|
30
|
+
<input type="hidden" id="device_data" name="<%= prefix %>[device_data]">
|
34
31
|
</div>
|
35
32
|
|
36
33
|
|
@@ -15,6 +15,7 @@
|
|
15
15
|
shippingAddressEditable: false,
|
16
16
|
environment: '<%= Rails.env.production? ? "production" : "sandbox" %>',
|
17
17
|
locale: '<%= paypal_button_preference(:paypal_button_locale, store: current_store) %>',
|
18
|
+
useDataCollector: <%= SolidusBraintree::Gateway.first.preferred_use_data_collector %>,
|
18
19
|
style: {
|
19
20
|
color: '<%= paypal_button_preference(:paypal_button_color, store: current_store) %>',
|
20
21
|
shape: '<%= paypal_button_preference(:paypal_button_shape, store: current_store) %>',
|
@@ -18,21 +18,26 @@ module SolidusBraintree
|
|
18
18
|
config.to_prepare do
|
19
19
|
app.config.spree.payment_methods << SolidusBraintree::Gateway
|
20
20
|
SolidusBraintree::Gateway.allowed_admin_form_preference_types.push(:preference_select).uniq!
|
21
|
-
|
21
|
+
|
22
|
+
::Spree::PermittedAttributes.source_attributes.concat(
|
23
|
+
[:nonce, :payment_type, :paypal_funding_source, :device_data]
|
24
|
+
).uniq!
|
22
25
|
end
|
23
26
|
end
|
24
27
|
|
25
|
-
|
26
|
-
config
|
27
|
-
|
28
|
-
|
29
|
-
'spree/frontend/apple_pay_button.js',
|
30
|
-
'solidus_braintree_manifest.js'
|
31
|
-
]
|
32
|
-
paths["app/controllers"] << "lib/controllers/frontend"
|
33
|
-
paths["app/views"] << "lib/views/frontend"
|
28
|
+
initializer 'add_solidus_braintree_response_to_log_entry_permitted_classes' do
|
29
|
+
Spree.config do |config|
|
30
|
+
config.log_entry_permitted_classes << 'SolidusBraintree::Response'
|
31
|
+
end
|
34
32
|
end
|
35
33
|
|
34
|
+
config.assets.precompile += [
|
35
|
+
'spree/frontend/solidus_braintree/checkout.js',
|
36
|
+
'solidus_braintree_manifest.js'
|
37
|
+
]
|
38
|
+
paths["app/controllers"] << "lib/controllers/frontend"
|
39
|
+
paths["app/views"] << "lib/views/frontend"
|
40
|
+
|
36
41
|
if SolidusSupport.backend_available?
|
37
42
|
config.assets.precompile += ["spree/backend/solidus_braintree.js"]
|
38
43
|
paths["app/controllers"] << "lib/controllers/backend"
|
data/solidus_braintree.gemspec
CHANGED
@@ -15,9 +15,9 @@ Gem::Specification.new do |spec|
|
|
15
15
|
|
16
16
|
spec.metadata['homepage_uri'] = spec.homepage
|
17
17
|
spec.metadata['source_code_uri'] = 'https://github.com/solidusio/solidus_braintree'
|
18
|
-
spec.metadata['changelog_uri'] = 'https://github.com/solidusio/solidus_braintree/
|
18
|
+
spec.metadata['changelog_uri'] = 'https://github.com/solidusio/solidus_braintree/releases'
|
19
19
|
|
20
|
-
spec.required_ruby_version = Gem::Requirement.new('>=
|
20
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 3.0', '< 4')
|
21
21
|
|
22
22
|
# Specify which files should be added to the gem when it is released.
|
23
23
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
@@ -31,14 +31,10 @@ Gem::Specification.new do |spec|
|
|
31
31
|
|
32
32
|
spec.add_dependency 'activemerchant', '~> 1.48'
|
33
33
|
spec.add_dependency 'braintree', '~> 3.4'
|
34
|
-
spec.add_dependency 'solidus_api', ['>=
|
35
|
-
spec.add_dependency 'solidus_core', ['>=
|
34
|
+
spec.add_dependency 'solidus_api', ['>= 3.4.0.dev', '< 5']
|
35
|
+
spec.add_dependency 'solidus_core', ['>= 3.4.0.dev', '< 5']
|
36
36
|
spec.add_dependency 'solidus_support', ['>= 0.8.1', '< 1']
|
37
37
|
|
38
38
|
spec.add_development_dependency 'rails-controller-testing'
|
39
39
|
spec.add_development_dependency 'solidus_dev_support', '~> 2.5'
|
40
|
-
spec.add_development_dependency 'vcr'
|
41
|
-
spec.add_development_dependency 'webmock'
|
42
|
-
|
43
|
-
spec.post_install_message = "If you're upgrading to v2.0.0, please see the README for upgrade instructions."
|
44
40
|
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require '
|
2
|
-
require 'support/order_ready_for_payment'
|
1
|
+
require 'solidus_braintree_helper'
|
2
|
+
require 'support/solidus_braintree/order_ready_for_payment'
|
3
3
|
|
4
4
|
RSpec.describe SolidusBraintree::CheckoutsController, type: :controller do
|
5
5
|
routes { SolidusBraintree::Engine.routes }
|