effective_orders 4.4.7 → 4.4.8

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: e1292868ad11472eacfd9b3d03b373044bf2655c0f8d34db31819beb86a02bfb
4
- data.tar.gz: d67604e57e3d44a36e04b15e7822a0c9495701faf5885353aa82065cd48c0755
3
+ metadata.gz: 9e201446ccdd9da7fa7afe58f64d9721438bfa2eb9d0f820dcab879c9f447204
4
+ data.tar.gz: 4db859784870c6e04572dcf53d9ed9cd6ecafd1a1cef1adc68bdb642d333fbba
5
5
  SHA512:
6
- metadata.gz: 4cb72e5daa0673e071399792a4b5e92d1642c107b4bee7694ace594e3db7510754b8624105caa5d629704293a2e5211a35847d145d7690269900446150177faa
7
- data.tar.gz: 0a641944b932a2d635a063d43a52742213cb4a1717b102f96aa97c6a303e62c14780e946e34f5d4f3c7a706dc31f39dcf1c83fc8c4762e09fbcdc5d1f5a1edea
6
+ metadata.gz: b8ea3eb173f2db102c4539bc08add41a15f399df5d9f24a88cdf116bf98ec37e07b75ae7de6a5476a4682fe91425de25d4ece1b10ac02655f03907bcae59be11
7
+ data.tar.gz: d5796fd79c659f9c25c8ac6389c101d1ccc4dc42a8b60e167c9ebad59fe46a652ce18955d871fffbfa607acae9076dad4700c63911ebbabb718f3a6e6353f82e
@@ -0,0 +1,77 @@
1
+ this.StripeForm ||= class StripeForm
2
+ constructor: ->
3
+ @form = null
4
+ @paymentIntent = null
5
+
6
+ @data = null
7
+ @stripe = null
8
+ @card = null
9
+
10
+ initialize: ->
11
+ @form = $('form[data-stripe-form]').first()
12
+ return false unless @form.length > 0
13
+
14
+ @paymentIntent = @form.find("input[name$='[payment_intent_id]']").first()
15
+ @data = @form.data('stripe-form')
16
+ @stripe = Stripe(@data.key)
17
+ @card = @stripe.elements().create('card', @style())
18
+
19
+ @mount()
20
+
21
+ style: ->
22
+ style: {
23
+ base: { color: '#32325d', fontSize: '16px', },
24
+ invalid: { color: '#dc3545', iconColor: '#dc3545' }
25
+ }
26
+
27
+ mount: ->
28
+ @card.mount('#stripe-card-element')
29
+
30
+ @card.addEventListener('change', (error) ->
31
+ $('#stripe-card-errors').text(if error.message then error.message else '')
32
+ )
33
+
34
+ @form.on('click', '[type=submit]', (event) => @submit(event))
35
+
36
+ submit: (event) ->
37
+ event.preventDefault()
38
+
39
+ payment = if @shouldUseNewCard() then @useNewCard() else @useExistingCard()
40
+
41
+ $.active = $.active + 1
42
+
43
+ payment.then((result) =>
44
+ if result.error
45
+ @errorPayment(result.error)
46
+ else if result.paymentIntent.status == 'succeeded'
47
+ @submitPayment(result.paymentIntent)
48
+ ).then((result) =>
49
+ $.active = $.active - 1
50
+ )
51
+
52
+ shouldUseNewCard: ->
53
+ @form.get(0).checkValidity() &&
54
+ @paymentIntent.val().length == 0 &&
55
+ (@data.token_required || @form.children('.collapse.show').length > 0)
56
+
57
+ useNewCard: ->
58
+ @stripe.confirmCardPayment(@data.client_secret, {
59
+ payment_method: {
60
+ card: @card,
61
+ billing_details: { email: @data.email }
62
+ },
63
+ setup_future_usage: 'off_session'
64
+ })
65
+
66
+ useExistingCard: ->
67
+ @stripe.confirmCardPayment(@data.client_secret, { payment_method: @data.payment_method })
68
+
69
+ submitPayment: (payment) ->
70
+ @paymentIntent.val(payment['id'])
71
+ @form.submit()
72
+
73
+ errorPayment: (error) ->
74
+ $('#stripe-card-errors').text(error.message)
75
+ EffectiveForm.invalidate(@form);
76
+
77
+ $ -> (new StripeForm()).initialize()
@@ -1,3 +1,3 @@
1
1
  module EffectiveOrders
2
- VERSION = '4.4.7'.freeze
2
+ VERSION = '4.4.8'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_orders
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.7
4
+ version: 4.4.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-24 00:00:00.000000000 Z
11
+ date: 2020-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -121,7 +121,7 @@ files:
121
121
  - app/assets/images/effective_orders/stripe.png
122
122
  - app/assets/javascripts/effective_orders.js
123
123
  - app/assets/javascripts/effective_orders/customers.js.coffee
124
- - app/assets/javascripts/effective_orders/providers/stripe.js
124
+ - app/assets/javascripts/effective_orders/providers/stripe.js.coffee
125
125
  - app/assets/javascripts/effective_orders/subscriptions.js.coffee
126
126
  - app/assets/stylesheets/effective_orders.scss
127
127
  - app/assets/stylesheets/effective_orders/_cart.scss
@@ -1,101 +0,0 @@
1
- class StripeForm {
2
- initialize() {
3
- let $form = $('form[data-stripe-form]').first();
4
- if ($form.length == 0) { return false; }
5
-
6
- this.$form = $form;
7
- this.$paymentIntentId = this.$form.find("input[name$='[payment_intent_id]']").first();
8
-
9
- this.data = $form.data('stripe-form');
10
- this.stripe = Stripe(this.data.key);
11
- this.card = this.stripe.elements().create("card", { style: this.style() });
12
-
13
- this.mount();
14
- }
15
-
16
- mount() {
17
- this.card.mount("#stripe-card-element");
18
-
19
- this.card.addEventListener('change', function ({ error }) {
20
- if (error) {
21
- $('#stripe-card-errors').text(error.message);
22
- } else {
23
- $('#stripe-card-errors').text('');
24
- }
25
- });
26
-
27
- this.$form.on('click', '[type=submit]', (event) => { this.submit(event) });
28
- }
29
-
30
- shouldUseNewCard() {
31
- let $newCardForm = this.$form.children('.collapse.show')
32
-
33
- return (
34
- this.$form.get(0).checkValidity() &&
35
- (this.data.token_required || $newCardForm.length > 0) &&
36
- this.$paymentIntentId.val().length == 0
37
- )
38
- }
39
-
40
- submit(event) {
41
- event.preventDefault();
42
-
43
- let payment = this.shouldUseNewCard() ? this.useNewCard() : this.useExistingCard();
44
-
45
- $.active = $.active + 1;
46
-
47
- payment.then((result) => {
48
- if (result.error) {
49
- this.errorPayment(result.error)
50
- } else if (result.paymentIntent.status == 'succeeded') {
51
- this.submitPayment(result.paymentIntent);
52
- }
53
- }).then((result) => {
54
- $.active = $.active - 1;
55
- });
56
- }
57
-
58
- useExistingCard() {
59
- return this.stripe.confirmCardPayment(this.data.client_secret, {
60
- payment_method: this.data.payment_method
61
- });
62
- }
63
-
64
- useNewCard() {
65
- return this.stripe.confirmCardPayment(this.data.client_secret, {
66
- payment_method: {
67
- card: this.card,
68
- billing_details: {
69
- email: this.data.email
70
- }
71
- },
72
- setup_future_usage: 'off_session'
73
- });
74
- }
75
-
76
- errorPayment(error) {
77
- $('#stripe-card-errors').text(error.message);
78
- EffectiveForm.invalidate(this.$form);
79
- }
80
-
81
- submitPayment(payment) {
82
- this.$paymentIntentId.val('' + payment['id']);
83
- this.$form.submit();
84
- }
85
-
86
- style() {
87
- return {
88
- base: {
89
- color: "#32325d",
90
- fontSize: "16px",
91
- },
92
- invalid: {
93
- color: "#dc3545",
94
- iconColor: "#dc3545"
95
- }
96
- };
97
- }
98
-
99
- }
100
-
101
- $(document).ready(function () { new StripeForm().initialize(); });