effective_orders 4.4.4 → 4.4.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f1c9cb84422232f69446f9612ffa08cebcdc62b85430377f42a7da21c716d10e
4
- data.tar.gz: c72f1703bc93f608862bd55b093fb3fe0d2e239b5030ab43ccd90df616c7ed89
3
+ metadata.gz: 91f309d8560e78018e04639fa0e733cc40632b33048b22b30458e888216420d9
4
+ data.tar.gz: 6562b45ee4e8e400d94d85e568126ad67648eda2525bdc7fdbfefa6b78bc3ab1
5
5
  SHA512:
6
- metadata.gz: e28e1ffc282e08b81a2f85407fb084d4117ed0744a55f7b85e78c1dbe62711f04c80d6aee7cc814e4b1ef167edf4d21da88232a1b07023dc6af2f8ec8af1bce2
7
- data.tar.gz: ed68a2d78bcae4af39223adb8ec445f9d7ccbc61a891717018e166021fa0f5f9ed193aba08c265cc998335438acf05b58f3619d82529233530e366488493d60e
6
+ metadata.gz: c15aa6b827a544df46d52c2fff312a7dd4500bfd2e5c94cd3a59a88687ef29e053555038685601d578e92c385b00a3e253daec03b7893405adb21d75dad54a80
7
+ data.tar.gz: 39eabeb2eacc02d433ea2eb2545bb007d56d3cc96e0868f87febd719903dbb574c776c197ab301216c1f994c81619fb2d71fd26b6c26d843ffdad3086de20a6a
@@ -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,7 +1,7 @@
1
1
  module ActsAsPurchasable
2
2
  extend ActiveSupport::Concern
3
3
 
4
- module ActiveRecord
4
+ module Base
5
5
  def acts_as_purchasable(*options)
6
6
  @acts_as_purchasable = options || []
7
7
 
@@ -3,7 +3,7 @@ module ActsAsSubscribable
3
3
 
4
4
  mattr_accessor :descendants
5
5
 
6
- module ActiveRecord
6
+ module Base
7
7
  def acts_as_subscribable(*options)
8
8
  @acts_as_subscribable = options || []
9
9
 
@@ -1,7 +1,7 @@
1
1
  module ActsAsSubscribableBuyer
2
2
  extend ActiveSupport::Concern
3
3
 
4
- module ActiveRecord
4
+ module Base
5
5
  def acts_as_subscribable_buyer(*options)
6
6
  include ::ActsAsSubscribableBuyer
7
7
  end
@@ -337,13 +337,14 @@ module Effective
337
337
 
338
338
  assign_attributes(
339
339
  state: EffectiveOrders::PURCHASED,
340
- purchased_at: Time.zone.now,
341
340
  payment: payment_to_h(payment),
342
341
  payment_provider: provider,
343
342
  payment_card: (card.presence || 'none'),
344
343
  skip_buyer_validations: skip_buyer_validations
345
344
  )
346
345
 
346
+ self.purchased_at ||= Time.zone.now
347
+
347
348
  Effective::Order.transaction do
348
349
  begin
349
350
  run_purchasable_callbacks(:before_purchase)
@@ -504,7 +505,7 @@ module Effective
504
505
  end
505
506
 
506
507
  def update_purchasables_purchased_order!
507
- order_items.each { |oi| oi.purchasable.update_column(:purchased_order_id, self.id) }
508
+ order_items.each { |oi| oi.purchasable&.update_column(:purchased_order_id, self.id) }
508
509
  end
509
510
 
510
511
  def run_purchasable_callbacks(name)
@@ -3,7 +3,7 @@
3
3
  = f.select :user_id, @users || User.all.to_a.sort { |user1, user2| user1.to_s <=> user2.to_s },
4
4
  label: 'Buyer', required: true, hint: 'The user that should purchase this order.'
5
5
 
6
- = f.cc_field :cc, hint: "Cc the above on any emailed receipts or payment requests."
6
+ = f.email_cc_field :cc, hint: "Cc the above on any emailed receipts or payment requests."
7
7
 
8
8
  %h2 Order Items
9
9
  .order_items
@@ -5,9 +5,9 @@ module EffectiveOrders
5
5
  # Include acts_as_addressable concern and allow any ActiveRecord object to call it
6
6
  initializer 'effective_orders.active_record' do |app|
7
7
  ActiveSupport.on_load :active_record do
8
- ActiveRecord::Base.extend(ActsAsPurchasable::ActiveRecord)
9
- ActiveRecord::Base.extend(ActsAsSubscribable::ActiveRecord)
10
- ActiveRecord::Base.extend(ActsAsSubscribableBuyer::ActiveRecord)
8
+ ActiveRecord::Base.extend(ActsAsPurchasable::Base)
9
+ ActiveRecord::Base.extend(ActsAsSubscribable::Base)
10
+ ActiveRecord::Base.extend(ActsAsSubscribableBuyer::Base)
11
11
  end
12
12
  end
13
13
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveOrders
2
- VERSION = '4.4.4'.freeze
2
+ VERSION = '4.4.9'.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.4
4
+ version: 4.4.9
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-17 00:00:00.000000000 Z
11
+ date: 2020-05-26 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,97 +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
- payment.then((result) => {
46
- if (result.error) {
47
- this.errorPayment(result.error)
48
- } else if (result.paymentIntent.status == 'succeeded') {
49
- this.submitPayment(result.paymentIntent);
50
- }
51
- });
52
- }
53
-
54
- useExistingCard() {
55
- return this.stripe.confirmCardPayment(this.data.client_secret, {
56
- payment_method: this.data.payment_method
57
- });
58
- }
59
-
60
- useNewCard() {
61
- return this.stripe.confirmCardPayment(this.data.client_secret, {
62
- payment_method: {
63
- card: this.card,
64
- billing_details: {
65
- email: this.data.email
66
- }
67
- },
68
- setup_future_usage: 'off_session'
69
- });
70
- }
71
-
72
- errorPayment(error) {
73
- $('#stripe-card-errors').text(error.message);
74
- EffectiveForm.invalidate(this.$form);
75
- }
76
-
77
- submitPayment(payment) {
78
- this.$paymentIntentId.val('' + payment['id']);
79
- this.$form.submit();
80
- }
81
-
82
- style() {
83
- return {
84
- base: {
85
- color: "#32325d",
86
- fontSize: "16px",
87
- },
88
- invalid: {
89
- color: "#dc3545",
90
- iconColor: "#dc3545"
91
- }
92
- };
93
- }
94
-
95
- }
96
-
97
- $(document).ready(function () { new StripeForm().initialize(); });