effective_orders 4.5.2 → 4.5.7
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 +4 -4
- data/app/assets/javascripts/effective_orders/providers/stripe.js.coffee +2 -1
- data/app/controllers/effective/carts_controller.rb +2 -0
- data/app/controllers/effective/customers_controller.rb +2 -0
- data/app/models/concerns/acts_as_subscribable.rb +6 -0
- data/app/models/effective/order.rb +15 -7
- data/app/models/effective/subscripter.rb +7 -1
- data/app/models/effective/subscription.rb +4 -0
- data/lib/effective_orders.rb +2 -1
- data/lib/effective_orders/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7af8313072b9cd7b4ab2fdac74aa083b29a0c8dbcc9e23b215aa96a771478884
|
4
|
+
data.tar.gz: 9a472569b70bcc8d2b2aec76e5922bc96f946df57cebd1f6a3dba055f85a1284
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c82f040bd36057c9919a11378f6fd2c0fc4fb552c06237f6d27f4f96f20f38c43ffb5e71b2cb61c03da91f47162ff62c15458cc486e2eb6523f15941915375c
|
7
|
+
data.tar.gz: 8095e12ec205f3d259290058ec9650a8e8b532c2ff1dec4220354baeecf374cc875fcc7b6797d171f8dd3b3b4d32da6bbf8cb618fc0a08df557023df4beaf4ea
|
@@ -8,7 +8,7 @@ this.StripeForm ||= class StripeForm
|
|
8
8
|
@card = null
|
9
9
|
|
10
10
|
initialize: ->
|
11
|
-
@form = $('form[data-stripe-form]').first()
|
11
|
+
@form = $('form[data-stripe-form]:not(.initialized)').first()
|
12
12
|
return false unless @form.length > 0
|
13
13
|
|
14
14
|
@paymentIntent = @form.find("input[name$='[payment_intent_id]']").first()
|
@@ -17,6 +17,7 @@ this.StripeForm ||= class StripeForm
|
|
17
17
|
@card = @stripe.elements().create('card', @style())
|
18
18
|
|
19
19
|
@mount()
|
20
|
+
@form.addClass('initialized')
|
20
21
|
|
21
22
|
style: ->
|
22
23
|
style: {
|
@@ -2,6 +2,8 @@ module Effective
|
|
2
2
|
class CartsController < ApplicationController
|
3
3
|
layout (EffectiveOrders.layout.kind_of?(Hash) ? EffectiveOrders.layout[:carts] : EffectiveOrders.layout)
|
4
4
|
|
5
|
+
before_action :authenticate_user!
|
6
|
+
|
5
7
|
def show
|
6
8
|
@cart = current_cart
|
7
9
|
@pending_orders = Effective::Order.pending.where(user: current_user) if current_user.present?
|
@@ -67,6 +67,12 @@ module ActsAsSubscribable
|
|
67
67
|
subscribed? && subscription_status == EffectiveOrders::PAST_DUE
|
68
68
|
end
|
69
69
|
|
70
|
+
# If we do use stripe
|
71
|
+
def subscription_trialing?
|
72
|
+
subscribed? && subscription_status == EffectiveOrders::TRIALING
|
73
|
+
end
|
74
|
+
|
75
|
+
# If we don't use stripe
|
70
76
|
def trialing?
|
71
77
|
subscription_status.blank?
|
72
78
|
end
|
@@ -228,13 +228,13 @@ module Effective
|
|
228
228
|
|
229
229
|
def update_prices!
|
230
230
|
raise('already purchased') if purchased?
|
231
|
-
raise('must be pending') unless pending?
|
231
|
+
raise('must be pending or confirmed') unless pending? || confirmed?
|
232
232
|
|
233
233
|
order_items.each do |item|
|
234
234
|
purchasable = item.purchasable
|
235
235
|
|
236
236
|
if purchasable.blank? || purchasable.marked_for_destruction?
|
237
|
-
item.mark_for_destruction
|
237
|
+
item.mark_for_destruction
|
238
238
|
else
|
239
239
|
item.price = purchasable.price
|
240
240
|
end
|
@@ -382,11 +382,11 @@ module Effective
|
|
382
382
|
|
383
383
|
raise "Failed to purchase order: #{error || errors.full_messages.to_sentence}" unless error.nil?
|
384
384
|
|
385
|
+
run_purchasable_callbacks(:after_purchase)
|
386
|
+
|
385
387
|
send_refund_notification! if email && refund?
|
386
388
|
send_order_receipts! if email
|
387
389
|
|
388
|
-
run_purchasable_callbacks(:after_purchase)
|
389
|
-
|
390
390
|
true
|
391
391
|
end
|
392
392
|
|
@@ -487,13 +487,17 @@ module Effective
|
|
487
487
|
|
488
488
|
def get_tax
|
489
489
|
return nil unless tax_rate.present?
|
490
|
-
|
490
|
+
present_order_items.reject { |oi| oi.tax_exempt? }.map { |oi| (oi.subtotal * (tax_rate / 100.0)).round(0).to_i }.sum
|
491
491
|
end
|
492
492
|
|
493
493
|
private
|
494
494
|
|
495
|
+
def present_order_items
|
496
|
+
order_items.reject { |oi| oi.marked_for_destruction? }
|
497
|
+
end
|
498
|
+
|
495
499
|
def assign_order_totals
|
496
|
-
self.subtotal =
|
500
|
+
self.subtotal = present_order_items.map { |oi| oi.subtotal }.sum
|
497
501
|
self.tax_rate = get_tax_rate() unless (tax_rate || 0) > 0
|
498
502
|
self.tax = get_tax()
|
499
503
|
self.total = subtotal + (tax || 0)
|
@@ -534,7 +538,11 @@ module Effective
|
|
534
538
|
end
|
535
539
|
|
536
540
|
def send_email(email, *mailer_args)
|
537
|
-
|
541
|
+
begin
|
542
|
+
Effective::OrdersMailer.public_send(email, *mailer_args).public_send(EffectiveOrders.mailer[:deliver_method])
|
543
|
+
rescue => e
|
544
|
+
raise if Rails.env.development? || Rails.env.test?
|
545
|
+
end
|
538
546
|
end
|
539
547
|
|
540
548
|
def truthy?(value)
|
@@ -126,7 +126,13 @@ module Effective
|
|
126
126
|
return false unless subscription.stripe_subscription.blank?
|
127
127
|
|
128
128
|
Rails.logger.info "[STRIPE] create subscription: #{items}"
|
129
|
-
|
129
|
+
|
130
|
+
stripe_subscription = Stripe::Subscription.create(
|
131
|
+
customer: customer.stripe_customer_id,
|
132
|
+
items: items,
|
133
|
+
metadata: metadata,
|
134
|
+
trial_from_plan: true
|
135
|
+
)
|
130
136
|
|
131
137
|
subscription.update!(
|
132
138
|
stripe_subscription: stripe_subscription,
|
data/lib/effective_orders.rb
CHANGED
@@ -14,9 +14,10 @@ module EffectiveOrders
|
|
14
14
|
# Subscription statuses (as per stripe)
|
15
15
|
ACTIVE = 'active'.freeze
|
16
16
|
PAST_DUE = 'past_due'.freeze
|
17
|
+
TRIALING = 'trialing'.freeze
|
17
18
|
CANCELED = 'canceled'.freeze
|
18
19
|
|
19
|
-
STATUSES = { ACTIVE => ACTIVE, PAST_DUE => PAST_DUE, CANCELED => CANCELED }
|
20
|
+
STATUSES = { ACTIVE => ACTIVE, PAST_DUE => PAST_DUE, CANCELED => CANCELED, TRIALING => TRIALING }
|
20
21
|
|
21
22
|
# The following are all valid config keys
|
22
23
|
mattr_accessor :orders_table_name
|
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.5.
|
4
|
+
version: 4.5.7
|
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-
|
11
|
+
date: 2020-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|