effective_orders 4.4.7 → 4.5.1

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: fad3df094c171d191535ace76083767eb81ca14c43d88e029707224047b10ac5
4
+ data.tar.gz: 2313c2501be2b4a5f125e8d62b447d313ec1c060fc1fdece8ffad46b63a701d8
5
5
  SHA512:
6
- metadata.gz: 4cb72e5daa0673e071399792a4b5e92d1642c107b4bee7694ace594e3db7510754b8624105caa5d629704293a2e5211a35847d145d7690269900446150177faa
7
- data.tar.gz: 0a641944b932a2d635a063d43a52742213cb4a1717b102f96aa97c6a303e62c14780e946e34f5d4f3c7a706dc31f39dcf1c83fc8c4762e09fbcdc5d1f5a1edea
6
+ metadata.gz: a4da4f9348ad2c421aa4f5da78f3b2701a7df832f9c9c0508fd340a62d65e95f94f02f4b4e55e4efc3f0a985cf88d7e7f1db49166cfebc68e5f1722d01ca709b
7
+ data.tar.gz: 23359059a3fb55c3995bd368bd391f0f49156ceadd88b03db55cd22bf7138a7258cc007862d4b31f928e3467217554128b14616076800349918364a8b7f49c6a
@@ -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()
@@ -86,13 +86,13 @@ module EffectiveOrdersHelper
86
86
  end
87
87
  end
88
88
 
89
- def render_checkout_step1(order, namespace: nil, purchased_url: nil, declined_url: nil)
90
- locals = { order: order, purchased_url: purchased_url, declined_url: declined_url, namespace: namespace }
89
+ def render_checkout_step1(order, namespace: nil, purchased_url: nil, declined_url: nil, deferred_url: nil)
90
+ locals = { order: order, purchased_url: purchased_url, declined_url: declined_url, deferred_url: deferred_url, namespace: namespace }
91
91
  render(partial: 'effective/orders/checkout_step1', locals: locals)
92
92
  end
93
93
 
94
- def render_checkout_step2(order, namespace: nil, purchased_url: nil, declined_url: nil)
95
- locals = { order: order, purchased_url: purchased_url, declined_url: declined_url, namespace: namespace }
94
+ def render_checkout_step2(order, namespace: nil, purchased_url: nil, declined_url: nil, deferred_url: nil)
95
+ locals = { order: order, purchased_url: purchased_url, declined_url: declined_url, deferred_url: deferred_url, namespace: namespace }
96
96
  render(partial: 'effective/orders/checkout_step2', locals: locals)
97
97
  end
98
98
 
@@ -5,15 +5,15 @@ module ActsAsPurchasable
5
5
  def acts_as_purchasable(*options)
6
6
  @acts_as_purchasable = options || []
7
7
 
8
- if table_exists?
9
- instance = new()
10
- raise 'must respond_to price' unless instance.respond_to?(:price)
11
- raise 'must respond_to purchased_order_id' unless instance.respond_to?(:purchased_order_id)
12
-
13
- if defined?(EffectiveQbSync)
14
- raise 'must respond to qb_item_name' unless instance.respond_to?(:qb_item_name)
15
- end
16
- end
8
+ # if table_exists?
9
+ # instance = new()
10
+ # raise 'must respond_to price' unless instance.respond_to?(:price)
11
+ # raise 'must respond_to purchased_order_id' unless instance.respond_to?(:purchased_order_id)
12
+
13
+ # if defined?(EffectiveQbSync)
14
+ # raise 'must respond to qb_item_name' unless instance.respond_to?(:qb_item_name)
15
+ # end
16
+ # end
17
17
 
18
18
  include ::ActsAsPurchasable
19
19
  end
@@ -7,9 +7,11 @@ module ActsAsSubscribable
7
7
  def acts_as_subscribable(*options)
8
8
  @acts_as_subscribable = options || []
9
9
 
10
- instance = new()
11
- raise 'must respond to trialing_until' unless instance.respond_to?(:trialing_until)
12
- raise 'must respond to subscription_status' unless instance.respond_to?(:subscription_status)
10
+ # if table_exists?
11
+ # instance = new()
12
+ # raise 'must respond to trialing_until' unless instance.respond_to?(:trialing_until) || !EffectiveOrders.trial?
13
+ # raise 'must respond to subscription_status' unless instance.respond_to?(:subscription_status)
14
+ # end
13
15
 
14
16
  include ::ActsAsSubscribable
15
17
  (ActsAsSubscribable.descendants ||= []) << self
@@ -20,7 +22,7 @@ module ActsAsSubscribable
20
22
  has_one :subscription, as: :subscribable, class_name: 'Effective::Subscription', inverse_of: :subscribable
21
23
  has_one :customer, through: :subscription, class_name: 'Effective::Customer'
22
24
 
23
- before_validation(if: -> { trialing_until.blank? && EffectiveOrders.trial? }) do
25
+ before_validation(if: -> { EffectiveOrders.trial? && trialing_until.blank? }) do
24
26
  self.trialing_until = (Time.zone.now + EffectiveOrders.trial.fetch(:length)).beginning_of_day
25
27
  end
26
28
 
@@ -28,7 +30,10 @@ module ActsAsSubscribable
28
30
  raise :abort unless (subscripter.destroy! rescue false)
29
31
  end
30
32
 
31
- validates :trialing_until, presence: true, if: -> { EffectiveOrders.trial? }
33
+ if EffectiveOrders.trial?
34
+ validates :trialing_until, presence: true
35
+ end
36
+
32
37
  validates :subscription_status, inclusion: { allow_nil: true, in: EffectiveOrders::STATUSES.keys }
33
38
 
34
39
  scope :trialing, -> { where(subscription_status: nil).where('trialing_until > ?', Time.zone.now) }
@@ -51,6 +51,13 @@ module Effective
51
51
  end
52
52
  end
53
53
 
54
+ def invoices
55
+ @invoices ||= if stripe_customer_id.present?
56
+ Rails.logger.info "[STRIPE] list invoices: #{stripe_customer_id}"
57
+ ::Stripe::Invoice.list(customer: stripe_customer_id) rescue nil
58
+ end
59
+ end
60
+
54
61
  def upcoming_invoice
55
62
  @upcoming_invoice ||= if stripe_customer_id.present?
56
63
  Rails.logger.info "[STRIPE] get upcoming invoice: #{stripe_customer_id}"
@@ -28,6 +28,9 @@ module Effective
28
28
  attr_accessor :send_mark_as_paid_email_to_buyer # Set by Admin::Orders#mark_as_paid
29
29
  attr_accessor :skip_buyer_validations # Set by Admin::Orders#create
30
30
 
31
+ # If we want to use orders in a has_many way
32
+ belongs_to :parent, polymorphic: true, optional: true
33
+
31
34
  belongs_to :user, validate: false # This is the buyer/user of the order. We validate it below.
32
35
  has_many :order_items, -> { order(:id) }, inverse_of: :order, class_name: 'Effective::OrderItem', dependent: :delete_all
33
36
 
@@ -337,13 +340,14 @@ module Effective
337
340
 
338
341
  assign_attributes(
339
342
  state: EffectiveOrders::PURCHASED,
340
- purchased_at: Time.zone.now,
341
343
  payment: payment_to_h(payment),
342
344
  payment_provider: provider,
343
345
  payment_card: (card.presence || 'none'),
344
346
  skip_buyer_validations: skip_buyer_validations
345
347
  )
346
348
 
349
+ self.purchased_at ||= Time.zone.now
350
+
347
351
  Effective::Order.transaction do
348
352
  begin
349
353
  run_purchasable_callbacks(:before_purchase)
@@ -56,6 +56,10 @@ module Effective
56
56
 
57
57
  validates :status, inclusion: { in: EffectiveOrders::STATUSES.keys }
58
58
 
59
+ before_validation do
60
+ self.name ||= EffectiveOrders.stripe_plans.find { |plan| plan[:id] == stripe_plan_id }&[:name] || 'Subscribed Plan'
61
+ end
62
+
59
63
  def to_s
60
64
  name || 'New Subscription'
61
65
  end
@@ -15,7 +15,7 @@
15
15
  %td= sub.quantity
16
16
  %td= sub.interval
17
17
 
18
- - if customer.stripe_customer.invoices.present?
18
+ - if customer.invoices.present?
19
19
  .card.my-4
20
20
  .card-header Invoices
21
21
  .card-body
@@ -26,7 +26,7 @@
26
26
  %th Invoice
27
27
  %th Total
28
28
  %tbody
29
- - customer.stripe_customer.invoices.each do |invoice|
29
+ - customer.invoices.each do |invoice|
30
30
  - date_method = [(:date if invoice.respond_to?(:date)), (:period_start if invoice.respond_to?(:period_start)), :created].compact.first
31
31
  %tr
32
32
  %td= link_to Time.zone.at(invoice.public_send(date_method)).strftime('%F'), invoice.invoice_pdf
@@ -2,6 +2,10 @@ class CreateEffectiveOrders < ActiveRecord::Migration[4.2]
2
2
  def self.up
3
3
  create_table <%= @orders_table_name %> do |t|
4
4
  t.integer :user_id
5
+
6
+ t.integer :parent_id
7
+ t.string :parent_type
8
+
5
9
  t.string :state
6
10
  t.datetime :purchased_at
7
11
 
@@ -183,7 +183,7 @@ module EffectiveOrders
183
183
  Rails.logger.info '[STRIPE] index plans'
184
184
 
185
185
  plans = begin
186
- Stripe::Plan.all
186
+ Stripe::Plan.respond_to?(:all) ? Stripe::Plan.all : Stripe::Plan.list
187
187
  rescue => e
188
188
  raise e if Rails.env.production?
189
189
  Rails.logger.info "[STRIPE ERROR]: #{e.message}"
@@ -192,15 +192,18 @@ module EffectiveOrders
192
192
  end
193
193
 
194
194
  plans = plans.map do |plan|
195
+ description = ("$#{'%0.2f' % (plan.amount / 100.0)}" + ' ' + plan.currency.upcase + '/' + plan.interval.to_s)
196
+
195
197
  {
196
198
  id: plan.id,
197
199
  product_id: plan.product,
198
- name: plan.nickname,
200
+ name: plan.nickname || description,
201
+ description: description,
199
202
  amount: plan.amount,
200
203
  currency: plan.currency,
201
- description: ("$#{'%0.2f' % (plan.amount / 100.0)}" + ' ' + plan.currency.upcase + '/' + plan.interval.to_s),
202
204
  interval: plan.interval,
203
- interval_count: plan.interval_count
205
+ interval_count: plan.interval_count,
206
+ trial_period_days: plan.trial_period_days
204
207
  }
205
208
  end.sort do |x, y|
206
209
  val ||= (x[:interval] <=> y[:interval])
@@ -1,3 +1,3 @@
1
1
  module EffectiveOrders
2
- VERSION = '4.4.7'.freeze
2
+ VERSION = '4.5.1'.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.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-24 00:00:00.000000000 Z
11
+ date: 2020-07-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
@@ -253,7 +253,7 @@ homepage: https://github.com/code-and-effect/effective_orders
253
253
  licenses:
254
254
  - MIT
255
255
  metadata: {}
256
- post_install_message:
256
+ post_install_message:
257
257
  rdoc_options: []
258
258
  require_paths:
259
259
  - lib
@@ -268,8 +268,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
268
268
  - !ruby/object:Gem::Version
269
269
  version: '0'
270
270
  requirements: []
271
- rubygems_version: 3.0.3
272
- signing_key:
271
+ rubygems_version: 3.1.2
272
+ signing_key:
273
273
  specification_version: 4
274
274
  summary: Quickly build an online store with carts, orders, automatic email receipts
275
275
  and payment collection via Stripe, StripeConnect, PayPal and Moneris.
@@ -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(); });