solidus_stripe 2.1.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b4105fb7ad047aa377a29ebc364dc19d861ce07e4bbcb264fb5494fcf9bbb8f1
4
- data.tar.gz: 43fa8a0106162cd0c26f7ff1e6fc65da2547137d98a1e4650aff04d639daae7d
3
+ metadata.gz: d9e6ec7ddfb05d802b145edb2e2e50d58510148be740c085dd0a7eb99a8e367b
4
+ data.tar.gz: c6598070cbe6c6e18504f27ab999ef0ca6d1b331ecdee9e1838434c261fe699d
5
5
  SHA512:
6
- metadata.gz: 2c891474a71412e3a03443ece9b16be6e49a0e7c6c1f6b6ad69f56d09608976fdc816211e779ce45556cfbc573c380334a65f7747170a3071763cb65b768dad6
7
- data.tar.gz: cf52ef3d344bb3335f795b6e708d1b35151b80159e6a52ced595c09b0339c47b85a2bbf89932d14ff8661b35a3cbd22fb8da0b1cebcb8a95736221e6645609e8
6
+ metadata.gz: 8faba0fdc2be35b90a936273a8d3aedf2411a10e8c01489c5a66b5859fbbcccb38ffcfec3e9d2a34dcdbf065228396b3047210cdbcbb0818c495ff2abf76f098
7
+ data.tar.gz: 82f01e68ff9a5fa8bcc74c759c3974d78cf05411b83cb732ca0ef32553d62d920697093db371a174c826d3391ca19908f0e4a35a4ae152863c61a94ae595f2c4
data/README.md CHANGED
@@ -133,6 +133,80 @@ payment method configured for Stripe via the local variable
133
133
  Of course, the rules listed in the Payment Intents section (adding the stripe
134
134
  country config value, for example) apply also for this feature.
135
135
 
136
+ Customizing the V3 API javascript
137
+ ---------------------------------
138
+
139
+ Stripe V3 JS code is now managed via Sprockets. If you need to customize the JS,
140
+ you can simply override or/and add new methods to the relevant object prototype.
141
+ Make sure you load your customizations after Stripe initalization code from
142
+ `spree/frontend/solidus_stripe`.
143
+
144
+ For example, the following code adds a callback method in order to print a debug
145
+ message on the console:
146
+
147
+ ```js
148
+ SolidusStripe.CartPageCheckout.prototype.onPrButtonMounted = function(id, result) {
149
+ if (result) {
150
+ $('#' + id).parent().show();
151
+ console.log('Payment request button is now mounted on element with id #' + id);
152
+ } else {
153
+ console.log('Payment request button failed initalization.');
154
+ }
155
+ }
156
+ ```
157
+
158
+ Styling Stripe Elements
159
+ -----------------------
160
+
161
+ The Elements feature built in this gem come with some standard styles. If you want
162
+ to customize it, you can override the `SolidusStripe.Elements.prototype.baseStyle`
163
+ method and make it return a valid [Stripe Style](https://stripe.com/docs/js/appendix/style)
164
+ object:
165
+
166
+ ```js
167
+ SolidusStripe.Elements.prototype.baseStyle = function () {
168
+ return {
169
+ base: {
170
+ iconColor: '#c4f0ff',
171
+ color: '#fff',
172
+ fontWeight: 500,
173
+ fontFamily: 'Roboto, Open Sans, Segoe UI, sans-serif',
174
+ fontSize: '16px',
175
+ fontSmoothing: 'antialiased',
176
+ ':-webkit-autofill': {
177
+ color: '#fce883',
178
+ },
179
+ '::placeholder': {
180
+ color: '#87BBFD',
181
+ },
182
+ },
183
+ invalid: {
184
+ iconColor: '#FFC7EE',
185
+ color: '#FFC7EE',
186
+ }
187
+ }
188
+ };
189
+ ```
190
+
191
+ You can also style your element containers directly by using CSS rules like this:
192
+
193
+ ```css
194
+ .StripeElement {
195
+ border: 1px solid transparent;
196
+ }
197
+
198
+ .StripeElement--focus {
199
+ box-shadow: 0 1px 3px 0 #cfd7df;
200
+ }
201
+
202
+ .StripeElement--invalid {
203
+ border-color: #fa755a;
204
+ }
205
+
206
+ .StripeElement--webkit-autofill {
207
+ background-color: #fefde5 !important;
208
+ }
209
+ ```
136
210
 
137
211
  Migrating from solidus_gateway
138
212
  ------------------------------
@@ -0,0 +1,6 @@
1
+ //= require ./solidus_stripe/stripe-payment
2
+ //= require ./solidus_stripe/stripe-elements
3
+ //= require ./solidus_stripe/stripe-payment-intents
4
+ //= require ./solidus_stripe/stripe-cart-page-checkout
5
+ //= require ./solidus_stripe/stripe-payment-request-button-shared
6
+ //= require ./solidus_stripe/stripe-init
@@ -19,21 +19,7 @@ SolidusStripe.Elements.prototype.init = function() {
19
19
 
20
20
  SolidusStripe.Elements.prototype.initElements = function() {
21
21
  var buildElements = function(elements) {
22
- var style = {
23
- base: {
24
- color: 'black',
25
- fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
26
- fontSmoothing: 'antialiased',
27
- fontSize: '14px',
28
- '::placeholder': {
29
- color: 'silver'
30
- }
31
- },
32
- invalid: {
33
- color: 'red',
34
- iconColor: 'red'
35
- }
36
- };
22
+ var style = this.baseStyle();
37
23
 
38
24
  elements.create('cardExpiry', {style: style}).mount('#card_expiry');
39
25
  elements.create('cardCvc', {style: style}).mount('#card_cvc');
@@ -42,7 +28,7 @@ SolidusStripe.Elements.prototype.initElements = function() {
42
28
  cardNumber.mount('#card_number');
43
29
 
44
30
  return cardNumber;
45
- };
31
+ }.bind(this);
46
32
 
47
33
  this.cardNumber = buildElements(this.elements);
48
34
 
@@ -57,6 +43,24 @@ SolidusStripe.Elements.prototype.initElements = function() {
57
43
  this.form.bind('submit', this.onFormSubmit.bind(this));
58
44
  };
59
45
 
46
+ SolidusStripe.Elements.prototype.baseStyle = function () {
47
+ return {
48
+ base: {
49
+ color: 'black',
50
+ fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
51
+ fontSmoothing: 'antialiased',
52
+ fontSize: '14px',
53
+ '::placeholder': {
54
+ color: 'silver'
55
+ }
56
+ },
57
+ invalid: {
58
+ color: 'red',
59
+ iconColor: 'red'
60
+ }
61
+ };
62
+ };
63
+
60
64
  SolidusStripe.Elements.prototype.showError = function(error) {
61
65
  var message = error.message || error;
62
66
 
@@ -0,0 +1,20 @@
1
+ $(function() {
2
+ var stripeV3Api = $('[data-v3-api]').data('v3-api');
3
+
4
+ if (stripeV3Api) {
5
+ $.getScript('https://js.stripe.com/v3/')
6
+ .done(function() {
7
+ switch (stripeV3Api) {
8
+ case 'elements':
9
+ new SolidusStripe.Elements().init();
10
+ break;
11
+ case 'payment-intents':
12
+ new SolidusStripe.PaymentIntents().init();
13
+ break;
14
+ case 'payment-request-button':
15
+ new SolidusStripe.CartPageCheckout().init();
16
+ break;
17
+ }
18
+ });
19
+ }
20
+ });
@@ -5,11 +5,8 @@ module SolidusStripe
5
5
  class InstallGenerator < Rails::Generators::Base
6
6
  class_option :auto_run_migrations, type: :boolean, default: false
7
7
 
8
- def add_stylesheets
9
- filename = 'vendor/assets/stylesheets/spree/frontend/all.css'
10
- if File.file? filename
11
- inject_into_file filename, " *= require spree/frontend/solidus_stripe\n", before: '*/', verbose: true
12
- end
8
+ def add_javascripts
9
+ append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/solidus_stripe\n"
13
10
  end
14
11
 
15
12
  def add_migrations
@@ -21,7 +21,6 @@ module SolidusStripe
21
21
 
22
22
  if SolidusSupport.frontend_available?
23
23
  paths["app/views"] << "lib/views/frontend"
24
- config.assets.precompile += ['spree/stripe-v3-payments.js']
25
24
  end
26
25
 
27
26
  if SolidusSupport.api_available?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusStripe
4
- VERSION = "2.1.0"
4
+ VERSION = "3.0.0"
5
5
  end
@@ -1,5 +1,5 @@
1
1
  <% if payment_method.v3_elements? %>
2
- <%= render 'spree/checkout/payment/v3/stripe', payment_method: payment_method %>
2
+ <%= render 'spree/checkout/payment/v3/elements', payment_method: payment_method %>
3
3
  <% elsif payment_method.v3_intents? %>
4
4
  <%= render 'spree/checkout/payment/v3/intents', payment_method: payment_method %>
5
5
  <% else %>
@@ -0,0 +1 @@
1
+ <%= render 'spree/checkout/payment/v3/form_elements', payment_method: payment_method, stripe_v3_api: 'elements' %>
@@ -1,4 +1,4 @@
1
- <div id="payment-request-button" data-stripe-config="<%= payment_method.stripe_config(current_order).to_json %>"></div>
1
+ <div id="payment-request-button" data-stripe-config="<%= payment_method.stripe_config(current_order).to_json %>" data-v3-api="<%= stripe_v3_api %>"></div>
2
2
 
3
3
  <%= image_tag 'credit_cards/credit_card.gif', id: 'credit-card-image' %>
4
4
  <% param_prefix = "payment_source[#{payment_method.id}]" %>
@@ -38,5 +38,3 @@
38
38
  <% end %>
39
39
 
40
40
  <%= hidden_field_tag "#{param_prefix}[cc_type]", '', id: "cc_type", class: 'ccType' %>
41
-
42
- <script src="https://js.stripe.com/v3/"></script>
@@ -1,9 +1 @@
1
- <%= render 'spree/checkout/payment/v3/form_elements', payment_method: payment_method %>
2
-
3
- <%= javascript_include_tag 'spree/stripe-v3-payments' %>
4
-
5
- <script>
6
- $(function() {
7
- new SolidusStripe.PaymentIntents().init();
8
- });
9
- </script>
1
+ <%= render 'spree/checkout/payment/v3/form_elements', payment_method: payment_method, stripe_v3_api: 'payment-intents' %>
@@ -1,9 +1,2 @@
1
- <%= render 'spree/checkout/payment/v3/form_elements', payment_method: payment_method %>
2
-
3
- <%= javascript_include_tag 'spree/stripe-v3-payments' %>
4
-
5
- <script>
6
- $(function() {
7
- new SolidusStripe.Elements().init();
8
- });
9
- </script>
1
+ <% ActiveSupport::Deprecation.warn 'Partial `spree/checkout/payment/v3/_stripe.html.erb` is deprecated and will be removed soon. Please use partial `spree/checkout/payment/v3/elements`', caller(1) %>
2
+ <%= render 'spree/checkout/payment/v3/elements', payment_method: payment_method, stripe_v3_api: 'elements' %>
@@ -1,5 +1,5 @@
1
1
  <% if current_order.present? && cart_checkout_payment_method.present? %>
2
- <div id="stripe-payment-request" class="stripe-payment-request" style="display:none">
2
+ <div id="stripe-payment-request" class="stripe-payment-request" data-v3-api="payment-request-button" style="display:none">
3
3
  <div id="payment-request-button"
4
4
  data-stripe-config="<%= cart_checkout_payment_method.stripe_config(current_order).to_json %>"
5
5
  data-order-token="<%= current_order.guest_token %>"
@@ -11,13 +11,4 @@
11
11
  <div id="card-errors" class='errorExplanation' role="alert" style="display: none">
12
12
  </div>
13
13
  </div>
14
-
15
- <script src="https://js.stripe.com/v3/"></script>
16
-
17
- <%= javascript_include_tag 'spree/stripe-v3-payments' %>
18
- <script>
19
- $(function() {
20
- new SolidusStripe.CartPageCheckout().init()
21
- });
22
- </script>
23
14
  <% end %>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_stripe
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Solidus Team
@@ -91,12 +91,13 @@ files:
91
91
  - LICENSE.md
92
92
  - README.md
93
93
  - Rakefile
94
- - app/assets/javascripts/spree/stripe-payments/stripe-cart-page-checkout.js
95
- - app/assets/javascripts/spree/stripe-payments/stripe-elements.js
96
- - app/assets/javascripts/spree/stripe-payments/stripe-payment-intents.js
97
- - app/assets/javascripts/spree/stripe-payments/stripe-payment-request-button-shared.js
98
- - app/assets/javascripts/spree/stripe-payments/stripe-payment.js
99
- - app/assets/javascripts/spree/stripe-v3-payments.js
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
100
101
  - app/controllers/solidus_stripe/intents_controller.rb
101
102
  - app/controllers/solidus_stripe/payment_request_controller.rb
102
103
  - app/controllers/spree/stripe_controller.rb
@@ -123,6 +124,7 @@ files:
123
124
  - lib/views/frontend/spree/checkout/existing_payment/_stripe.html.erb
124
125
  - lib/views/frontend/spree/checkout/payment/_stripe.html.erb
125
126
  - lib/views/frontend/spree/checkout/payment/v2/_javascript.html.erb
127
+ - lib/views/frontend/spree/checkout/payment/v3/_elements.html.erb
126
128
  - lib/views/frontend/spree/checkout/payment/v3/_form_elements.html.erb
127
129
  - lib/views/frontend/spree/checkout/payment/v3/_intents.html.erb
128
130
  - lib/views/frontend/spree/checkout/payment/v3/_stripe.html.erb
@@ -1,5 +0,0 @@
1
- //= require ./stripe-payments/stripe-payment
2
- //= require ./stripe-payments/stripe-elements
3
- //= require ./stripe-payments/stripe-payment-intents
4
- //= require ./stripe-payments/stripe-cart-page-checkout
5
- //= require ./stripe-payments/stripe-payment-request-button-shared