effective_orders 5.4.2 → 5.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/admin/orders_controller.rb +4 -4
- data/app/controllers/effective/providers/mark_as_paid.rb +1 -1
- data/app/datatables/admin/effective_orders_datatable.rb +1 -1
- data/app/helpers/effective_stripe_helper.rb +10 -0
- data/app/models/effective/order.rb +27 -9
- data/app/views/effective/orders/mark_as_paid/_form.html.haml +7 -6
- data/lib/effective_orders/version.rb +1 -1
- data/lib/effective_orders.rb +18 -0
- 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: 9c608a4f1f72b5f82b0afe786bcc71ba8b951ff22e121ae2e2492afa08410966
|
4
|
+
data.tar.gz: fd836b344d52cb4cc9047aecc243dc2bf43d2b7b69bc0524331449e005e49789
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b7a575224a3cfbcbc271dcbce0f6e4b8d4943995696a3a57372356747faea7b454df6a2202d6c0b9a1ec55b8296ae78511665111841117066f4d2f4366881a4
|
7
|
+
data.tar.gz: d84ada9221fb3c57d2d92254e9925641a53a5bf772b143373616e239f22c4d52b88d131d9983d94a2d57e81cbdccf761a33e0e99d5da0941c7f462eff78307a1
|
@@ -15,7 +15,7 @@ module Admin
|
|
15
15
|
submit :save, 'Checkout', redirect: -> { effective_orders.checkout_admin_order_path(resource) }
|
16
16
|
|
17
17
|
def create
|
18
|
-
@user = current_user.class.find_by_id(
|
18
|
+
@user = current_user.class.find_by_id(permitted_params[:user_id])
|
19
19
|
@order = Effective::Order.new(user: @user)
|
20
20
|
|
21
21
|
authorize_effective_order!
|
@@ -23,12 +23,12 @@ module Admin
|
|
23
23
|
|
24
24
|
Effective::Order.transaction do
|
25
25
|
begin
|
26
|
-
(
|
26
|
+
(permitted_params[:order_items_attributes] || {}).each do |_, item_attrs|
|
27
27
|
purchasable = Effective::Product.new(item_attrs[:purchasable_attributes])
|
28
28
|
@order.add(purchasable, quantity: item_attrs[:quantity])
|
29
29
|
end
|
30
30
|
|
31
|
-
@order.attributes =
|
31
|
+
@order.attributes = permitted_params.except(:order_items_attributes, :user_id)
|
32
32
|
@order.pending!
|
33
33
|
|
34
34
|
message = 'Successfully created order'
|
@@ -123,7 +123,7 @@ module Admin
|
|
123
123
|
|
124
124
|
private
|
125
125
|
|
126
|
-
def
|
126
|
+
def permitted_params
|
127
127
|
params.require(:effective_order).permit(:user_id, :user_type, :cc,
|
128
128
|
:send_payment_request_to_buyer, :note_internal, :note_to_buyer,
|
129
129
|
:payment_provider, :payment_card, :payment, :send_mark_as_paid_email_to_buyer,
|
@@ -26,7 +26,7 @@ module Effective
|
|
26
26
|
def mark_as_paid_params
|
27
27
|
params.require(:effective_order).permit(
|
28
28
|
:purchased_at, :payment, :payment_provider, :payment_card,
|
29
|
-
:note_to_buyer, :send_mark_as_paid_email_to_buyer
|
29
|
+
:note_to_buyer, :note_internal, :send_mark_as_paid_email_to_buyer
|
30
30
|
)
|
31
31
|
end
|
32
32
|
|
@@ -72,7 +72,7 @@ class Admin::EffectiveOrdersDatatable < Effective::Datatable
|
|
72
72
|
|
73
73
|
col :total, as: :price
|
74
74
|
|
75
|
-
col :payment_provider, label: 'Provider', visible: false, search: { collection: EffectiveOrders.
|
75
|
+
col :payment_provider, label: 'Provider', visible: false, search: { collection: EffectiveOrders.admin_payment_providers }
|
76
76
|
col :payment_card, label: 'Card', visible: false
|
77
77
|
|
78
78
|
if EffectiveOrders.collect_note
|
@@ -47,6 +47,16 @@ module EffectiveStripeHelper
|
|
47
47
|
|
48
48
|
def stripe_payment_intent(order)
|
49
49
|
customer = Effective::Customer.for_user(order.user)
|
50
|
+
|
51
|
+
begin
|
52
|
+
stripe_payment_intent_payload(order, customer)
|
53
|
+
rescue => e
|
54
|
+
raise unless Rails.env.development?
|
55
|
+
stripe_payment_intent_payload(order, Effective::Customer.new(user: order.user))
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def stripe_payment_intent_payload(order, customer)
|
50
60
|
customer.create_stripe_customer! # Only creates if customer not already present
|
51
61
|
|
52
62
|
payment = {
|
@@ -120,7 +120,7 @@ module Effective
|
|
120
120
|
validates :payment_provider, presence: true
|
121
121
|
|
122
122
|
validate do
|
123
|
-
self.errors.add(:payment_provider, "unknown payment provider") unless EffectiveOrders.payment_providers.include?(payment_provider)
|
123
|
+
self.errors.add(:payment_provider, "unknown payment provider") unless (EffectiveOrders.payment_providers + EffectiveOrders.admin_payment_providers).include?(payment_provider)
|
124
124
|
end
|
125
125
|
|
126
126
|
validates :payment_card, presence: true
|
@@ -323,6 +323,8 @@ module Effective
|
|
323
323
|
def payment_method
|
324
324
|
return nil unless purchased?
|
325
325
|
|
326
|
+
provider = payment_provider if ['cheque', 'phone'].include?(payment_provider)
|
327
|
+
|
326
328
|
# Normalize payment card
|
327
329
|
card = case payment_card.to_s.downcase.gsub(' ', '').strip
|
328
330
|
when '' then nil
|
@@ -331,7 +333,19 @@ module Effective
|
|
331
333
|
when 'a', 'ax', 'american', 'americanexpress' then 'American Express'
|
332
334
|
when 'd', 'discover' then 'Discover'
|
333
335
|
else payment_card.to_s
|
334
|
-
end
|
336
|
+
end
|
337
|
+
|
338
|
+
# Try again
|
339
|
+
if card == 'none' && payment['card_type'].present?
|
340
|
+
card = case payment['card_type'].to_s.downcase.gsub(' ', '').strip
|
341
|
+
when '' then nil
|
342
|
+
when 'v', 'visa' then 'Visa'
|
343
|
+
when 'm', 'mc', 'master', 'mastercard' then 'MasterCard'
|
344
|
+
when 'a', 'ax', 'american', 'americanexpress' then 'American Express'
|
345
|
+
when 'd', 'discover' then 'Discover'
|
346
|
+
else payment_card.to_s
|
347
|
+
end
|
348
|
+
end
|
335
349
|
|
336
350
|
last4 = if payment[:active_card] && payment[:active_card].include?('**** **** ****')
|
337
351
|
payment[:active_card][15,4]
|
@@ -340,7 +354,7 @@ module Effective
|
|
340
354
|
# stripe, moneris, moneris_checkout
|
341
355
|
last4 ||= (payment['f4l4'] || payment['first6last4']).to_s.last(4)
|
342
356
|
|
343
|
-
[
|
357
|
+
[provider.presence, card.presence, last4.presence].compact.join(' - ')
|
344
358
|
end
|
345
359
|
|
346
360
|
def duplicate
|
@@ -484,14 +498,18 @@ module Effective
|
|
484
498
|
|
485
499
|
# Effective::Order.new(items: Product.first, user: User.first).purchase!(email: false)
|
486
500
|
def purchase!(payment: 'none', provider: 'none', card: 'none', email: true, skip_buyer_validations: false, skip_quickbooks: false)
|
501
|
+
return true if purchased?
|
502
|
+
|
487
503
|
# Assign attributes
|
488
|
-
|
489
|
-
|
504
|
+
assign_attributes(
|
505
|
+
state: EffectiveOrders::PURCHASED,
|
506
|
+
skip_buyer_validations: skip_buyer_validations,
|
490
507
|
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
508
|
+
payment_provider: provider,
|
509
|
+
payment_card: (card.presence || 'none'),
|
510
|
+
purchased_at: Time.zone.now,
|
511
|
+
payment: payment_to_h(payment)
|
512
|
+
)
|
495
513
|
|
496
514
|
begin
|
497
515
|
Effective::Order.transaction do
|
@@ -7,20 +7,21 @@
|
|
7
7
|
= effective_form_with(model: order, url: effective_orders.mark_as_paid_order_path(order), method: :post) do |f|
|
8
8
|
= f.hidden_field :purchased_at, value: Time.zone.now
|
9
9
|
|
10
|
-
= f.select :payment_provider, EffectiveOrders.
|
10
|
+
= f.select :payment_provider, EffectiveOrders.admin_payment_providers, required: true
|
11
11
|
|
12
12
|
= f.text_field :payment_card,
|
13
13
|
label: 'Payment card type, cheque or transaction number',
|
14
14
|
hint: 'Do not enter credit card numbers here, or anywhere.'
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
.row
|
17
|
+
.col
|
18
|
+
= f.text_area :note_to_buyer, hint: 'This message will be displayed to the buyer on the receipt.'
|
19
|
+
.col
|
20
|
+
= f.text_area :note_internal, hint: 'For or internal admin use only. This note will never be displayed to the buyer.'
|
19
21
|
|
20
22
|
= f.check_box :send_mark_as_paid_email_to_buyer,
|
21
23
|
label: 'Yes, send a receipt email to the buyer.',
|
22
24
|
input_html: { checked: (f.object.send_mark_as_paid_email_to_buyer.nil? ? EffectiveOrders.send_order_receipts_when_mark_as_paid : f.object.send_mark_as_paid_email_to_buyer?) }
|
23
25
|
|
24
|
-
= f.text_area :note_to_buyer, hint: 'This message will be displayed on the receipt.'
|
25
26
|
|
26
|
-
= f.submit
|
27
|
+
= f.submit order_checkout_label(order.refund? ? :refund : :mark_as_paid)
|
data/lib/effective_orders.rb
CHANGED
@@ -142,6 +142,24 @@ module EffectiveOrders
|
|
142
142
|
].compact
|
143
143
|
end
|
144
144
|
|
145
|
+
# For the Admin Mark as Paid screen
|
146
|
+
def self.admin_payment_providers
|
147
|
+
[
|
148
|
+
('cheque' if mark_as_paid?),
|
149
|
+
('credit card' if mark_as_paid?),
|
150
|
+
#('free' if free?),
|
151
|
+
('moneris' if moneris?),
|
152
|
+
('moneris_checkout' if moneris_checkout?),
|
153
|
+
('paypal' if paypal?),
|
154
|
+
('phone' if mark_as_paid?),
|
155
|
+
#('pretend' if pretend?),
|
156
|
+
#('refund' if refund?),
|
157
|
+
('stripe' if stripe?),
|
158
|
+
('other' if mark_as_paid?),
|
159
|
+
'none'
|
160
|
+
].compact
|
161
|
+
end
|
162
|
+
|
145
163
|
def self.deferred_providers
|
146
164
|
[('cheque' if cheque?), ('phone' if phone?)].compact
|
147
165
|
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.
|
4
|
+
version: 5.5.0
|
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: 2022-03-
|
11
|
+
date: 2022-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|