solidus_stripe 2.0.0 → 3.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +50 -1
- data/README.md +131 -7
- data/app/assets/javascripts/spree/frontend/solidus_stripe.js +6 -0
- data/app/assets/javascripts/spree/frontend/solidus_stripe/stripe-cart-page-checkout.js +88 -0
- data/app/assets/javascripts/spree/frontend/solidus_stripe/stripe-elements.js +148 -0
- data/app/assets/javascripts/spree/frontend/solidus_stripe/stripe-init.js +20 -0
- data/app/assets/javascripts/spree/frontend/solidus_stripe/stripe-payment-intents.js +84 -0
- data/app/assets/javascripts/spree/frontend/solidus_stripe/stripe-payment-request-button-shared.js +123 -0
- data/app/assets/javascripts/spree/frontend/solidus_stripe/stripe-payment.js +16 -0
- data/app/controllers/solidus_stripe/intents_controller.rb +29 -20
- data/app/decorators/models/spree/order_update_attributes_decorator.rb +39 -0
- data/app/decorators/models/spree/payment_decorator.rb +11 -0
- data/app/models/solidus_stripe/create_intents_order_service.rb +70 -0
- data/app/models/spree/payment_method/stripe_credit_card.rb +4 -9
- data/lib/generators/solidus_stripe/install/install_generator.rb +2 -5
- data/lib/solidus_stripe/engine.rb +0 -1
- data/lib/solidus_stripe/version.rb +1 -1
- data/lib/views/frontend/spree/checkout/payment/_stripe.html.erb +1 -1
- data/lib/views/frontend/spree/checkout/payment/v3/_elements.html.erb +1 -0
- data/lib/views/frontend/spree/checkout/payment/v3/_form_elements.html.erb +1 -3
- data/lib/views/frontend/spree/checkout/payment/v3/_intents.html.erb +1 -5
- data/lib/views/frontend/spree/checkout/payment/v3/_stripe.html.erb +2 -5
- data/lib/views/frontend/spree/orders/_stripe_payment_request_button.html.erb +1 -79
- data/solidus_stripe.gemspec +1 -1
- data/spec/features/stripe_checkout_spec.rb +143 -68
- data/spec/spec_helper.rb +1 -0
- data/spec/support/solidus_address_helper.rb +15 -0
- metadata +17 -8
- data/app/assets/javascripts/solidus_stripe/stripe-init.js +0 -1
- data/app/assets/javascripts/solidus_stripe/stripe-init/base.js +0 -180
- data/lib/views/frontend/spree/checkout/payment/v3/_elements_js.html.erb +0 -28
- data/lib/views/frontend/spree/checkout/payment/v3/_intents_js.html.erb +0 -48
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solidus_stripe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 3.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Solidus Team
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: solidus_core
|
@@ -36,14 +36,14 @@ dependencies:
|
|
36
36
|
requirements:
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: 0.4
|
39
|
+
version: '0.4'
|
40
40
|
type: :runtime
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: 0.4
|
46
|
+
version: '0.4'
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: activemerchant
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -91,12 +91,20 @@ files:
|
|
91
91
|
- LICENSE.md
|
92
92
|
- README.md
|
93
93
|
- Rakefile
|
94
|
-
- app/assets/javascripts/solidus_stripe
|
95
|
-
- app/assets/javascripts/solidus_stripe/stripe-
|
94
|
+
- app/assets/javascripts/spree/frontend/solidus_stripe.js
|
95
|
+
- app/assets/javascripts/spree/frontend/solidus_stripe/stripe-cart-page-checkout.js
|
96
|
+
- app/assets/javascripts/spree/frontend/solidus_stripe/stripe-elements.js
|
97
|
+
- app/assets/javascripts/spree/frontend/solidus_stripe/stripe-init.js
|
98
|
+
- app/assets/javascripts/spree/frontend/solidus_stripe/stripe-payment-intents.js
|
99
|
+
- app/assets/javascripts/spree/frontend/solidus_stripe/stripe-payment-request-button-shared.js
|
100
|
+
- app/assets/javascripts/spree/frontend/solidus_stripe/stripe-payment.js
|
96
101
|
- app/controllers/solidus_stripe/intents_controller.rb
|
97
102
|
- app/controllers/solidus_stripe/payment_request_controller.rb
|
98
103
|
- app/controllers/spree/stripe_controller.rb
|
104
|
+
- app/decorators/models/spree/order_update_attributes_decorator.rb
|
105
|
+
- app/decorators/models/spree/payment_decorator.rb
|
99
106
|
- app/models/solidus_stripe/address_from_params_service.rb
|
107
|
+
- app/models/solidus_stripe/create_intents_order_service.rb
|
100
108
|
- app/models/solidus_stripe/prepare_order_for_payment_service.rb
|
101
109
|
- app/models/solidus_stripe/shipping_rates_service.rb
|
102
110
|
- app/models/spree/payment_method/stripe_credit_card.rb
|
@@ -119,10 +127,9 @@ files:
|
|
119
127
|
- lib/views/frontend/spree/checkout/existing_payment/_stripe.html.erb
|
120
128
|
- lib/views/frontend/spree/checkout/payment/_stripe.html.erb
|
121
129
|
- lib/views/frontend/spree/checkout/payment/v2/_javascript.html.erb
|
122
|
-
- lib/views/frontend/spree/checkout/payment/v3/
|
130
|
+
- lib/views/frontend/spree/checkout/payment/v3/_elements.html.erb
|
123
131
|
- lib/views/frontend/spree/checkout/payment/v3/_form_elements.html.erb
|
124
132
|
- lib/views/frontend/spree/checkout/payment/v3/_intents.html.erb
|
125
|
-
- lib/views/frontend/spree/checkout/payment/v3/_intents_js.html.erb
|
126
133
|
- lib/views/frontend/spree/checkout/payment/v3/_stripe.html.erb
|
127
134
|
- lib/views/frontend/spree/orders/_stripe_payment_request_button.html.erb
|
128
135
|
- solidus_stripe.gemspec
|
@@ -132,6 +139,7 @@ files:
|
|
132
139
|
- spec/models/solidus_stripe/shipping_rates_service_spec.rb
|
133
140
|
- spec/models/spree/payment_method/stripe_credit_card_spec.rb
|
134
141
|
- spec/spec_helper.rb
|
142
|
+
- spec/support/solidus_address_helper.rb
|
135
143
|
homepage: https://solidus.io
|
136
144
|
licenses:
|
137
145
|
- BSD-3
|
@@ -165,3 +173,4 @@ test_files:
|
|
165
173
|
- spec/models/solidus_stripe/shipping_rates_service_spec.rb
|
166
174
|
- spec/models/spree/payment_method/stripe_credit_card_spec.rb
|
167
175
|
- spec/spec_helper.rb
|
176
|
+
- spec/support/solidus_address_helper.rb
|
@@ -1 +0,0 @@
|
|
1
|
-
//= require ./stripe-init/base
|
@@ -1,180 +0,0 @@
|
|
1
|
-
window.SolidusStripe = window.SolidusStripe || {};
|
2
|
-
|
3
|
-
SolidusStripe.paymentMethod = {
|
4
|
-
config: $('[data-stripe-config').data('stripe-config'),
|
5
|
-
requestShipping: false
|
6
|
-
}
|
7
|
-
|
8
|
-
var authToken = $('meta[name="csrf-token"]').attr('content');
|
9
|
-
|
10
|
-
var stripe = Stripe(SolidusStripe.paymentMethod.config.publishable_key)
|
11
|
-
var elements = stripe.elements({locale: 'en'});
|
12
|
-
|
13
|
-
var element = $('#payment_method_' + SolidusStripe.paymentMethod.config.id);
|
14
|
-
var form = element.parents('form');
|
15
|
-
var errorElement = form.find('#card-errors');
|
16
|
-
var submitButton = form.find('input[type="submit"]');
|
17
|
-
|
18
|
-
function stripeTokenHandler(token) {
|
19
|
-
var baseSelector = `<input type='hidden' class='stripeToken' name='payment_source[${SolidusStripe.paymentMethod.config.id}]`;
|
20
|
-
|
21
|
-
element.append(`${baseSelector}[gateway_payment_profile_id]' value='${token.id}'/>`);
|
22
|
-
element.append(`${baseSelector}[last_digits]' value='${token.card.last4}'/>`);
|
23
|
-
element.append(`${baseSelector}[month]' value='${token.card.exp_month}'/>`);
|
24
|
-
element.append(`${baseSelector}[year]' value='${token.card.exp_year}'/>`);
|
25
|
-
form.find('input#cc_type').val(mapCC(token.card.brand || token.card.type));
|
26
|
-
};
|
27
|
-
|
28
|
-
function initElements() {
|
29
|
-
var style = {
|
30
|
-
base: {
|
31
|
-
color: 'black',
|
32
|
-
fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
|
33
|
-
fontSmoothing: 'antialiased',
|
34
|
-
fontSize: '14px',
|
35
|
-
'::placeholder': {
|
36
|
-
color: 'silver'
|
37
|
-
}
|
38
|
-
},
|
39
|
-
invalid: {
|
40
|
-
color: 'red',
|
41
|
-
iconColor: 'red'
|
42
|
-
}
|
43
|
-
};
|
44
|
-
|
45
|
-
elements.create('cardExpiry', {style: style}).mount('#card_expiry');
|
46
|
-
elements.create('cardCvc', {style: style}).mount('#card_cvc');
|
47
|
-
|
48
|
-
var cardNumber = elements.create('cardNumber', {style: style});
|
49
|
-
cardNumber.mount('#card_number');
|
50
|
-
|
51
|
-
return cardNumber;
|
52
|
-
}
|
53
|
-
|
54
|
-
function setUpPaymentRequest(config, onPrButtonMounted) {
|
55
|
-
if (typeof config !== 'undefined') {
|
56
|
-
var paymentRequest = stripe.paymentRequest({
|
57
|
-
country: config.country,
|
58
|
-
currency: config.currency,
|
59
|
-
total: {
|
60
|
-
label: config.label,
|
61
|
-
amount: config.amount
|
62
|
-
},
|
63
|
-
requestPayerName: true,
|
64
|
-
requestPayerEmail: true,
|
65
|
-
requestShipping: config.requestShipping,
|
66
|
-
shippingOptions: [
|
67
|
-
]
|
68
|
-
});
|
69
|
-
|
70
|
-
var prButton = elements.create('paymentRequestButton', {
|
71
|
-
paymentRequest: paymentRequest
|
72
|
-
});
|
73
|
-
|
74
|
-
paymentRequest.canMakePayment().then(function(result) {
|
75
|
-
var id = 'payment-request-button';
|
76
|
-
|
77
|
-
if (result) {
|
78
|
-
prButton.mount('#' + id);
|
79
|
-
} else {
|
80
|
-
document.getElementById(id).style.display = 'none';
|
81
|
-
}
|
82
|
-
if (typeof onPrButtonMounted === 'function') {
|
83
|
-
onPrButtonMounted(id, result);
|
84
|
-
}
|
85
|
-
});
|
86
|
-
|
87
|
-
paymentRequest.on('paymentmethod', function(result) {
|
88
|
-
errorElement.text('').hide();
|
89
|
-
handlePayment(result);
|
90
|
-
});
|
91
|
-
|
92
|
-
paymentRequest.on('shippingaddresschange', function(ev) {
|
93
|
-
fetch('/stripe/shipping_rates', {
|
94
|
-
method: 'POST',
|
95
|
-
headers: { 'Content-Type': 'application/json' },
|
96
|
-
body: JSON.stringify({
|
97
|
-
authenticity_token: authToken,
|
98
|
-
shipping_address: ev.shippingAddress
|
99
|
-
})
|
100
|
-
}).then(function(response) {
|
101
|
-
return response.json();
|
102
|
-
}).then(function(result) {
|
103
|
-
if (result.error) {
|
104
|
-
showError(result.error);
|
105
|
-
return false;
|
106
|
-
} else {
|
107
|
-
ev.updateWith({
|
108
|
-
status: 'success',
|
109
|
-
shippingOptions: result.shipping_rates
|
110
|
-
});
|
111
|
-
}
|
112
|
-
});
|
113
|
-
});
|
114
|
-
|
115
|
-
return paymentRequest;
|
116
|
-
}
|
117
|
-
};
|
118
|
-
|
119
|
-
function handleServerResponse(response, payment) {
|
120
|
-
if (response.error) {
|
121
|
-
showError(response.error);
|
122
|
-
completePaymentRequest(payment, 'fail');
|
123
|
-
} else if (response.requires_action) {
|
124
|
-
stripe.handleCardAction(
|
125
|
-
response.stripe_payment_intent_client_secret
|
126
|
-
).then(function(result) {
|
127
|
-
if (result.error) {
|
128
|
-
showError(result.error.message);
|
129
|
-
} else {
|
130
|
-
fetch('/stripe/confirm_intents', {
|
131
|
-
method: 'POST',
|
132
|
-
headers: { 'Content-Type': 'application/json' },
|
133
|
-
body: JSON.stringify({
|
134
|
-
spree_payment_method_id: SolidusStripe.paymentMethod.config.id,
|
135
|
-
stripe_payment_intent_id: result.paymentIntent.id,
|
136
|
-
authenticity_token: authToken
|
137
|
-
})
|
138
|
-
}).then(function(confirmResult) {
|
139
|
-
return confirmResult.json();
|
140
|
-
}).then(handleServerResponse);
|
141
|
-
}
|
142
|
-
});
|
143
|
-
} else {
|
144
|
-
completePaymentRequest(payment, 'success');
|
145
|
-
submitPayment(payment);
|
146
|
-
}
|
147
|
-
}
|
148
|
-
|
149
|
-
function completePaymentRequest(payment, state) {
|
150
|
-
if (payment && typeof payment.complete === 'function') {
|
151
|
-
payment.complete(state);
|
152
|
-
}
|
153
|
-
}
|
154
|
-
|
155
|
-
function showError(error) {
|
156
|
-
errorElement.text(error).show();
|
157
|
-
|
158
|
-
if (submitButton.length) {
|
159
|
-
setTimeout(function() {
|
160
|
-
$.rails.enableElement(submitButton[0]);
|
161
|
-
submitButton.removeAttr('disabled').removeClass('disabled');
|
162
|
-
}, 100);
|
163
|
-
}
|
164
|
-
};
|
165
|
-
|
166
|
-
function mapCC(ccType) {
|
167
|
-
if (ccType === 'MasterCard') {
|
168
|
-
return 'mastercard';
|
169
|
-
} else if (ccType === 'Visa') {
|
170
|
-
return 'visa';
|
171
|
-
} else if (ccType === 'American Express') {
|
172
|
-
return 'amex';
|
173
|
-
} else if (ccType === 'Discover') {
|
174
|
-
return 'discover';
|
175
|
-
} else if (ccType === 'Diners Club') {
|
176
|
-
return 'dinersclub';
|
177
|
-
} else if (ccType === 'JCB') {
|
178
|
-
return 'jcb';
|
179
|
-
}
|
180
|
-
};
|
@@ -1,28 +0,0 @@
|
|
1
|
-
<script>
|
2
|
-
// Stripe V3 elements specific JS code
|
3
|
-
|
4
|
-
var cardNumber = initElements();
|
5
|
-
|
6
|
-
cardNumber.addEventListener('change', function(event) {
|
7
|
-
if (event.error) {
|
8
|
-
showError(event.error.message);
|
9
|
-
} else {
|
10
|
-
errorElement.hide().text('');
|
11
|
-
}
|
12
|
-
});
|
13
|
-
|
14
|
-
form.bind('submit', function(event) {
|
15
|
-
if (element.is(':visible')) {
|
16
|
-
event.preventDefault();
|
17
|
-
|
18
|
-
stripe.createToken(cardNumber).then(function(result) {
|
19
|
-
if (result.error) {
|
20
|
-
showError(result.error.message);
|
21
|
-
} else {
|
22
|
-
stripeTokenHandler(result.token);
|
23
|
-
form[0].submit();
|
24
|
-
}
|
25
|
-
});
|
26
|
-
}
|
27
|
-
});
|
28
|
-
</script>
|
@@ -1,48 +0,0 @@
|
|
1
|
-
<script>
|
2
|
-
// Stripe Intents JS code
|
3
|
-
|
4
|
-
var cardNumber = initElements();
|
5
|
-
var paymentRequest = setUpPaymentRequest(SolidusStripe.paymentMethod.config.payment_request);
|
6
|
-
|
7
|
-
form.bind('submit', function(event) {
|
8
|
-
if (element.is(':visible')) {
|
9
|
-
event.preventDefault();
|
10
|
-
|
11
|
-
errorElement.text('').hide();
|
12
|
-
|
13
|
-
stripe.createPaymentMethod(
|
14
|
-
'card',
|
15
|
-
cardNumber
|
16
|
-
).then(function(result) {
|
17
|
-
handlePayment(result);
|
18
|
-
});
|
19
|
-
}
|
20
|
-
});
|
21
|
-
|
22
|
-
function handlePayment(payment) {
|
23
|
-
if (payment.error) {
|
24
|
-
showError(payment.error.message);
|
25
|
-
} else {
|
26
|
-
stripeTokenHandler(payment.paymentMethod);
|
27
|
-
fetch('/stripe/confirm_intents', {
|
28
|
-
method: 'POST',
|
29
|
-
headers: {
|
30
|
-
'Content-Type': 'application/json'
|
31
|
-
},
|
32
|
-
body: JSON.stringify({
|
33
|
-
spree_payment_method_id: SolidusStripe.paymentMethod.config.id,
|
34
|
-
stripe_payment_method_id: payment.paymentMethod.id,
|
35
|
-
authenticity_token: authToken
|
36
|
-
})
|
37
|
-
}).then(function(response) {
|
38
|
-
response.json().then(function(json) {
|
39
|
-
handleServerResponse(json, payment);
|
40
|
-
})
|
41
|
-
});
|
42
|
-
}
|
43
|
-
};
|
44
|
-
|
45
|
-
function submitPayment(_payment) {
|
46
|
-
form.unbind('submit').submit();
|
47
|
-
}
|
48
|
-
</script>
|