effective_orders 5.0.2 → 5.0.3

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: 982893ebe426c1097f68ffaccbd87a1977c5d48f4ce1a45dbbf5b13752572542
4
- data.tar.gz: 1742602893eb3c98aea29e31161c05e60b67929802ed51a39c40d20fb3c4f2b3
3
+ metadata.gz: 55f4ecfb00c2ff8fca1e88711877ca4c4a2c5e2772857645b1793eb42d672f6d
4
+ data.tar.gz: 97d1e59387d065240d3b0c160f725831d808ea153d6aedce2104f277c769e005
5
5
  SHA512:
6
- metadata.gz: fa41b81eba8d7c6364fe8192f3e072149562228a666cd8b7b2b41845258e1684a00947bce0b890d9f77f5887ae1a87ba377b68909c7f99d2773ac1801acd12c4
7
- data.tar.gz: f7759f4669a5a66492b6dd0259d5e744d64c403775112d0577280397d4b31e2d98dd66bf764e18c4e5359b16346d22b9444ecb65b087b55c4638e2bf28eccfa2
6
+ metadata.gz: 74166e809d54fd9b2b0f4c266e59da9b0f8ff0947ac2166f6e88686fcaecf05a1c6e520933a935568717beae55a1db032aca72902641fbd031ecf60fe0302527
7
+ data.tar.gz: 464f54b750a6feab8ec0ad9df11c1b8591aa70d33a58faaf0cb03eb03d584ea4362fc9247f3ad3425e3269585cb78a18529cfc28c1ae41eadc0a28d2304f1298
@@ -5,28 +5,21 @@ module Effective
5
5
 
6
6
  protected
7
7
 
8
- def order_purchased(payment:, provider:, card: 'none', email: true, skip_buyer_validations: false, purchased_url: nil, declined_url: nil)
9
- begin
10
- @order.purchase!(payment: payment, provider: provider, card: card, email: email, skip_buyer_validations: skip_buyer_validations)
11
-
12
- Effective::Cart.where(user: @order.user).destroy_all
13
-
14
- if flash[:success].blank?
15
- if EffectiveOrders.mailer[:send_order_receipt_to_buyer] && email
16
- flash[:success] = "Payment successful! A receipt has been sent to #{@order.emails_send_to}"
17
- else
18
- flash[:success] = "Payment successful! An email receipt has not been sent."
19
- end
20
- end
8
+ def order_purchased(payment:, provider:, card: 'none', email: true, skip_buyer_validations: false, purchased_url: nil)
9
+ @order.purchase!(payment: payment, provider: provider, card: card, email: email, skip_buyer_validations: skip_buyer_validations)
21
10
 
22
- purchased_url ||= effective_orders.purchased_order_path(':id')
23
- redirect_to purchased_url.gsub(':id', @order.to_param.to_s)
24
- rescue => e
25
- flash[:danger] = "An error occurred while processing your payment: #{e.message}. Please try again."
11
+ Effective::Cart.where(user: @order.user).destroy_all
26
12
 
27
- declined_url ||= effective_orders.declined_order_path(':id')
28
- redirect_to declined_url.gsub(':id', @order.to_param.to_s)
13
+ if flash[:success].blank?
14
+ if email && EffectiveOrders.mailer[:send_order_receipt_to_buyer]
15
+ flash[:success] = "Payment successful! A receipt has been sent to #{@order.emails_send_to}"
16
+ else
17
+ flash[:success] = "Payment successful! An email receipt has not been sent."
18
+ end
29
19
  end
20
+
21
+ purchased_url ||= effective_orders.purchased_order_path(':id')
22
+ redirect_to purchased_url.gsub(':id', @order.to_param.to_s)
30
23
  end
31
24
 
32
25
  def order_deferred(provider:, email: true, deferred_url: nil)
@@ -1,5 +1,6 @@
1
1
  module Effective
2
2
  class OrdersController < ApplicationController
3
+ include Effective::CrudController
3
4
  include Concerns::Purchase
4
5
 
5
6
  include Providers::Cheque
@@ -12,8 +13,6 @@ module Effective
12
13
  include Providers::Refund
13
14
  include Providers::Stripe
14
15
 
15
- include Effective::CrudController
16
-
17
16
  if (config = EffectiveOrders.layout)
18
17
  layout(config.kind_of?(Hash) ? (config[:orders] || config[:application]) : config)
19
18
  end
@@ -21,7 +21,6 @@ module Effective
21
21
  provider: 'free',
22
22
  card: 'none',
23
23
  purchased_url: free_params[:purchased_url],
24
- declined_url: free_params[:declined_url],
25
24
  email: false
26
25
  )
27
26
  end
@@ -19,8 +19,7 @@ module Effective
19
19
  card: mark_as_paid_params[:payment_card],
20
20
  email: @order.send_mark_as_paid_email_to_buyer?,
21
21
  skip_buyer_validations: true,
22
- purchased_url: effective_orders.admin_order_path(@order),
23
- declined_url: effective_orders.admin_order_path(@order)
22
+ purchased_url: effective_orders.admin_order_path(@order)
24
23
  )
25
24
  end
26
25
 
@@ -14,8 +14,7 @@ module Effective
14
14
  payment: 'for pretend',
15
15
  provider: 'pretend',
16
16
  card: 'none',
17
- purchased_url: pretend_params[:purchased_url],
18
- declined_url: pretend_params[:declined_url]
17
+ purchased_url: pretend_params[:purchased_url]
19
18
  )
20
19
  end
21
20
 
@@ -21,8 +21,7 @@ module Effective
21
21
  order_purchased(
22
22
  payment: 'refund. no payment required.',
23
23
  provider: 'refund',
24
- purchased_url: refund_params[:purchased_url],
25
- declined_url: refund_params[:declined_url]
24
+ purchased_url: refund_params[:purchased_url]
26
25
  )
27
26
  end
28
27
 
@@ -26,8 +26,7 @@ module Effective
26
26
  payment: payment,
27
27
  provider: 'stripe',
28
28
  card: payment[:card],
29
- purchased_url: stripe_params[:purchased_url],
30
- declined_url: stripe_params[:declined_url]
29
+ purchased_url: stripe_params[:purchased_url]
31
30
  )
32
31
  end
33
32
 
@@ -6,8 +6,6 @@ class EffectiveOrdersDatatable < Effective::Datatable
6
6
  scope :purchased, default: true
7
7
  scope :deferred
8
8
  scope :refunds
9
- scope :not_purchased
10
- scope :all
11
9
  end
12
10
  end
13
11
 
@@ -79,7 +77,7 @@ class EffectiveOrdersDatatable < Effective::Datatable
79
77
  end
80
78
 
81
79
  def user
82
- @user ||= current_user.class.find(attributes[:user_id])
80
+ @user ||= view.current_user.class.find(attributes[:user_id])
83
81
  end
84
82
 
85
83
  end
@@ -107,13 +107,7 @@ module EffectiveOrdersHelper
107
107
  end
108
108
  end
109
109
 
110
- def render_orders(obj, opts = {})
111
- orders = Array(obj.kind_of?(User) ? Effective::Order.purchased_by(obj) : obj)
112
-
113
- if orders.any? { |order| order.kind_of?(Effective::Order) == false }
114
- raise 'expected a User or Effective::Order'
115
- end
116
-
110
+ def render_orders(orders, opts = {})
117
111
  render(partial: 'effective/orders/orders_table', locals: { orders: orders }.merge(opts))
118
112
  end
119
113
 
@@ -362,38 +362,31 @@ module Effective
362
362
 
363
363
  # Effective::Order.new(items: Product.first, user: User.first).purchase!(email: false)
364
364
  def purchase!(payment: 'none', provider: 'none', card: 'none', email: true, skip_buyer_validations: false)
365
- return false if purchased?
366
- error = nil
367
-
368
- assign_attributes(
369
- state: EffectiveOrders::PURCHASED,
370
- payment: payment_to_h(payment),
371
- payment_provider: provider,
372
- payment_card: (card.presence || 'none'),
373
- skip_buyer_validations: skip_buyer_validations
374
- )
365
+ # Assign attributes
366
+ self.state = EffectiveOrders::PURCHASED
367
+ self.skip_buyer_validations = skip_buyer_validations
375
368
 
369
+ self.payment_provider ||= provider
370
+ self.payment_card ||= (card.presence || 'none')
376
371
  self.purchased_at ||= Time.zone.now
372
+ self.payment = payment_to_h(payment) if self.payment.blank?
377
373
 
378
- Effective::Order.transaction do
379
- begin
374
+ begin
375
+ Effective::Order.transaction do
380
376
  run_purchasable_callbacks(:before_purchase)
381
377
  save!
382
378
  update_purchasables_purchased_order!
383
- rescue => e
384
- self.state = state_was
385
- self.purchased_at = nil
386
-
387
- error = e.message
388
- raise ::ActiveRecord::Rollback
389
379
  end
390
- end
380
+ rescue => e
381
+ Effective::Order.transaction do
382
+ save!(validate: false)
383
+ update_purchasables_purchased_order!
384
+ end
391
385
 
392
- raise "Failed to purchase order: #{error || errors.full_messages.to_sentence}" unless error.nil?
386
+ raise(e)
387
+ end
393
388
 
394
389
  run_purchasable_callbacks(:after_purchase)
395
-
396
- send_refund_notification! if email && refund?
397
390
  send_order_receipts! if email
398
391
 
399
392
  true
@@ -456,6 +449,7 @@ module Effective
456
449
  def send_order_receipts!
457
450
  send_order_receipt_to_admin! if EffectiveOrders.mailer[:send_order_receipt_to_admin]
458
451
  send_order_receipt_to_buyer! if EffectiveOrders.mailer[:send_order_receipt_to_buyer]
452
+ send_refund_notification! if refund?
459
453
  end
460
454
 
461
455
  def send_order_receipt_to_admin!
@@ -4,6 +4,8 @@ module Effective
4
4
 
5
5
  acts_as_purchasable
6
6
 
7
+ # belongs_to :purchased_order_id
8
+
7
9
  effective_resource do
8
10
  name :string
9
11
  qb_item_name :string
@@ -3,7 +3,7 @@
3
3
  = link_to 'Print', '#', class: 'btn btn-primary print-button', data: { role: 'print-button' }, onClick: 'window.print(); false;'
4
4
 
5
5
  - if order.purchased?
6
- = link_to 'Email receipt to buyer', effective_orders.send_buyer_receipt_order_path(order),
6
+ = link_to 'E-mail Receipt', effective_orders.send_buyer_receipt_order_path(order),
7
7
  class: 'btn btn-secondary',
8
8
  data: { confirm: "Send receipt to #{order.emails_send_to}?" }
9
9
 
@@ -4,3 +4,7 @@
4
4
  = render_checkout(@order)
5
5
  - else
6
6
  = render @order
7
+
8
+ %hr
9
+
10
+ = link_to 'Continue', effective_orders.orders_path, class: 'btn btn-primary'
@@ -1,3 +1,3 @@
1
1
  module EffectiveOrders
2
- VERSION = '5.0.2'.freeze
2
+ VERSION = '5.0.3'.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: 5.0.2
4
+ version: 5.0.3
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: 2021-03-04 00:00:00.000000000 Z
11
+ date: 2021-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails