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 +4 -4
- data/app/controllers/effective/concerns/purchase.rb +12 -19
- data/app/controllers/effective/orders_controller.rb +1 -2
- data/app/controllers/effective/providers/free.rb +0 -1
- data/app/controllers/effective/providers/mark_as_paid.rb +1 -2
- data/app/controllers/effective/providers/pretend.rb +1 -2
- data/app/controllers/effective/providers/refund.rb +1 -2
- data/app/controllers/effective/providers/stripe.rb +1 -2
- data/app/datatables/effective_orders_datatable.rb +1 -3
- data/app/helpers/effective_orders_helper.rb +1 -7
- data/app/models/effective/order.rb +16 -22
- data/app/models/effective/product.rb +2 -0
- data/app/views/effective/orders/_order_actions.html.haml +1 -1
- data/app/views/effective/orders/show.html.haml +4 -0
- 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: 55f4ecfb00c2ff8fca1e88711877ca4c4a2c5e2772857645b1793eb42d672f6d
|
4
|
+
data.tar.gz: 97d1e59387d065240d3b0c160f725831d808ea153d6aedce2104f277c769e005
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
9
|
-
|
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
|
-
|
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
|
-
|
28
|
-
|
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
|
@@ -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
|
|
@@ -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
|
|
@@ -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(
|
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
|
-
|
366
|
-
|
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
|
-
|
379
|
-
|
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
|
-
|
380
|
+
rescue => e
|
381
|
+
Effective::Order.transaction do
|
382
|
+
save!(validate: false)
|
383
|
+
update_purchasables_purchased_order!
|
384
|
+
end
|
391
385
|
|
392
|
-
|
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!
|
@@ -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 '
|
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
|
|
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.
|
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-
|
11
|
+
date: 2021-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|