effective_orders 6.13.3 → 6.14.1
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/providers/deluxe_delayed.rb +1 -0
- data/app/helpers/effective_orders_helper.rb +3 -2
- data/app/mailers/effective/orders_mailer.rb +21 -0
- data/app/models/effective/deluxe_api.rb +24 -2
- data/app/models/effective/order.rb +39 -6
- data/app/views/effective/orders/_checkout_step2.html.haml +1 -1
- data/app/views/effective/orders/_order.html.haml +1 -0
- data/app/views/effective/orders/_order_declined.html.haml +10 -0
- data/app/views/effective/orders/deluxe/_form.html.haml +6 -0
- data/app/views/effective/orders/deluxe_delayed/_form.html.haml +6 -0
- data/app/views/effective/orders_mailer/order_declined_to_admin.html.haml +2 -0
- data/app/views/effective/orders_mailer/order_declined_to_buyer.html.haml +2 -0
- data/config/effective_orders.rb +2 -1
- data/lib/effective_orders/version.rb +1 -1
- data/lib/effective_orders.rb +3 -1
- data/lib/generators/templates/effective_orders_mailer_preview.rb +8 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bd29353ae8797a9589a4a80bd592c376f008e82df8c216ec691967e4c4e5a96
|
4
|
+
data.tar.gz: 5bff3315e5bd67b4e23eb90c1fb17e8d5267c9a21d12efe5791230f7f675e729
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8bafbde6a79e146b216f982ee6b292c93966918e9f2d8e74a21b9951d352dbe10c8d57e5380eb9482b3163bb7f5ced4a17b69884c1987d6ca767020e904ddaa
|
7
|
+
data.tar.gz: 76f4706faff04901d8a4061125624560bfcad049bd2be920095c46cc53cf6f7954fb13668a808622135dd95b23f286db5322dea3290b51a7d4dfc22cd237ee6c
|
@@ -23,6 +23,7 @@ module Effective
|
|
23
23
|
end
|
24
24
|
|
25
25
|
# Decode the base64 encoded JSON object into a Hash
|
26
|
+
# {"type"=>"Token", "status"=>"success", "data"=>{"token"=>"1983661243624242", "nameOnCard"=>"CardHolder", "expDate"=>"12/24", "maskedPan"=>"424242******4242", "cardType"=>"Visa"}}
|
26
27
|
payment_intent = api.decode_payment_intent_payload(payment_intent_payload)
|
27
28
|
card_info = api.card_info(payment_intent)
|
28
29
|
|
@@ -119,12 +119,13 @@ module EffectiveOrdersHelper
|
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
|
-
def render_checkout_step1(order, namespace: nil, purchased_url: nil, declined_url: nil, deferred_url: nil, skip_deferred: false, skip_order:
|
122
|
+
def render_checkout_step1(order, namespace: nil, purchased_url: nil, declined_url: nil, deferred_url: nil, skip_deferred: false, skip_order: nil)
|
123
123
|
locals = { order: order, purchased_url: purchased_url, declined_url: declined_url, deferred_url: deferred_url, namespace: namespace, skip_deferred: skip_deferred, skip_order: skip_order }
|
124
124
|
render(partial: 'effective/orders/checkout_step1', locals: locals)
|
125
125
|
end
|
126
126
|
|
127
|
-
def render_checkout_step2(order, namespace: nil, purchased_url: nil, declined_url: nil, deferred_url: nil, skip_deferred: false, skip_order:
|
127
|
+
def render_checkout_step2(order, namespace: nil, purchased_url: nil, declined_url: nil, deferred_url: nil, skip_deferred: false, skip_order: nil)
|
128
|
+
skip_order = order.delayed_payment_date_upcoming? if skip_order.nil?
|
128
129
|
locals = { order: order, purchased_url: purchased_url, declined_url: declined_url, deferred_url: deferred_url, namespace: namespace, skip_deferred: skip_deferred, skip_order: skip_order }
|
129
130
|
render(partial: 'effective/orders/checkout_step2', locals: locals)
|
130
131
|
end
|
@@ -25,6 +25,27 @@ module Effective
|
|
25
25
|
mail(to: @order.emails.first, cc: @order.cc.presence, subject: subject, **headers)
|
26
26
|
end
|
27
27
|
|
28
|
+
def order_declined_to_admin(resource, opts = {})
|
29
|
+
raise('expected an Effective::Order') unless resource.kind_of?(Effective::Order)
|
30
|
+
|
31
|
+
@order = resource
|
32
|
+
subject = subject_for(__method__, "Declined Order: ##{@order.to_param}", resource, opts)
|
33
|
+
headers = headers_for(resource, opts)
|
34
|
+
|
35
|
+
mail(to: mailer_admin, subject: subject, **headers)
|
36
|
+
end
|
37
|
+
|
38
|
+
def order_declined_to_buyer(resource, opts = {})
|
39
|
+
raise('expected an Effective::Order') unless resource.kind_of?(Effective::Order)
|
40
|
+
|
41
|
+
@order = resource
|
42
|
+
subject = subject_for(__method__, "Declined Order: ##{@order.to_param}", resource, opts)
|
43
|
+
headers = headers_for(resource, opts)
|
44
|
+
|
45
|
+
# Just to the purchaser. Not everyone.
|
46
|
+
mail(to: @order.emails.first, cc: @order.cc.presence, subject: subject, **headers)
|
47
|
+
end
|
48
|
+
|
28
49
|
# This is sent when an admin creates a new order or /admin/orders/new
|
29
50
|
# Or when Pay by Cheque or Pay by Phone (deferred payments)
|
30
51
|
# Or uses the order action Send Payment Request
|
@@ -136,6 +136,7 @@ module Effective
|
|
136
136
|
raise('expected a delayed order') unless order.delayed?
|
137
137
|
raise('expected a deferred order') unless order.deferred?
|
138
138
|
raise('expected delayed payment intent') unless order.delayed_payment_intent.present?
|
139
|
+
raise('expected a delayed_ready_to_purchase? order') unless order.delayed_ready_to_purchase?
|
139
140
|
|
140
141
|
order.update_columns(delayed_payment_purchase_ran_at: now, delayed_payment_purchase_result: nil)
|
141
142
|
|
@@ -157,8 +158,8 @@ module Effective
|
|
157
158
|
|
158
159
|
puts "Successfully purchased order #{order.id}"
|
159
160
|
else
|
160
|
-
order.assign_attributes(delayed_payment_purchase_result: "failed with message: #{Array(payment['responseMessage']).to_sentence.presence || 'none'}
|
161
|
-
order.decline!(payment: payment, provider: provider, card: card)
|
161
|
+
order.assign_attributes(delayed_payment_purchase_result: "failed with message: #{Array(payment['responseMessage']).to_sentence.presence || 'none'}")
|
162
|
+
order.decline!(payment: payment, provider: provider, card: card, email: true)
|
162
163
|
|
163
164
|
puts "Failed to purchase order #{order.id} #{order.delayed_payment_purchase_result}"
|
164
165
|
end
|
@@ -178,6 +179,27 @@ module Effective
|
|
178
179
|
true
|
179
180
|
end
|
180
181
|
|
182
|
+
# This is only used for testing
|
183
|
+
def generate_payment_intent(card: nil, expiry: nil, cvv: nil, encode: false)
|
184
|
+
card ||= '4242 4242 4242 4242'
|
185
|
+
expiry ||= "12/#{Time.zone.now.year - 1998}"
|
186
|
+
cvv ||= '123'
|
187
|
+
|
188
|
+
card_info = { expiry: expiry, cvv: cvv }
|
189
|
+
params = { paymentMethod: { card: { card: card.gsub(" ", '') }.merge(card_info) } }
|
190
|
+
|
191
|
+
response = post('/paymentmethods/token', params: params)
|
192
|
+
|
193
|
+
# Like the delayed_purchase form gives us
|
194
|
+
retval = {
|
195
|
+
type: "Token",
|
196
|
+
status: "success",
|
197
|
+
data: { expDate: card_info[:expiry], cardType: 'Visa', token: response.fetch('token') }
|
198
|
+
}
|
199
|
+
|
200
|
+
encode ? Base64.encode64(retval.to_json) : retval
|
201
|
+
end
|
202
|
+
|
181
203
|
protected
|
182
204
|
|
183
205
|
def create_payment_params(order, payment_intent)
|
@@ -566,6 +566,12 @@ module Effective
|
|
566
566
|
"Your #{delayed_payment_method} will be charged $#{'%0.2f' % total_to_f} on #{delayed_payment_date.strftime('%F')}"
|
567
567
|
end
|
568
568
|
|
569
|
+
def delayed_payment_date_past?
|
570
|
+
return false unless delayed?
|
571
|
+
delayed_payment_date <= Time.zone.now.to_date
|
572
|
+
end
|
573
|
+
|
574
|
+
# This is checked by an effective_orders view helper. When upcoming we only collect card info.
|
569
575
|
def delayed_payment_date_upcoming?
|
570
576
|
return false unless delayed?
|
571
577
|
delayed_payment_date > Time.zone.now.to_date
|
@@ -576,11 +582,6 @@ module Effective
|
|
576
582
|
delayed_payment_date == Time.zone.now.to_date
|
577
583
|
end
|
578
584
|
|
579
|
-
def delayed_payment_date_past?
|
580
|
-
return false unless delayed?
|
581
|
-
delayed_payment_date < Time.zone.now.to_date
|
582
|
-
end
|
583
|
-
|
584
585
|
def pending_refund?
|
585
586
|
return false if EffectiveOrders.buyer_purchases_refund?
|
586
587
|
return false if purchased?
|
@@ -602,6 +603,16 @@ module Effective
|
|
602
603
|
EffectiveOrders.send_order_receipt_to_buyer
|
603
604
|
end
|
604
605
|
|
606
|
+
def send_order_declined_to_admin?
|
607
|
+
return false if free? && !EffectiveOrders.send_order_receipts_when_free
|
608
|
+
EffectiveOrders.send_order_declined_to_admin
|
609
|
+
end
|
610
|
+
|
611
|
+
def send_order_declined_to_buyer?
|
612
|
+
return false if free? && !EffectiveOrders.send_order_receipts_when_free
|
613
|
+
EffectiveOrders.send_order_declined_to_buyer
|
614
|
+
end
|
615
|
+
|
605
616
|
def send_payment_request_to_buyer?
|
606
617
|
return false if free? && !EffectiveOrders.send_order_receipts_when_free
|
607
618
|
return false if refund?
|
@@ -803,7 +814,8 @@ module Effective
|
|
803
814
|
true
|
804
815
|
end
|
805
816
|
|
806
|
-
|
817
|
+
# We only turn on the email when done by a delayed payment or from a rake script.
|
818
|
+
def decline!(payment: 'none', provider: 'none', card: 'none', validate: true, email: false)
|
807
819
|
return false if declined?
|
808
820
|
raise('order already purchased') if purchased?
|
809
821
|
|
@@ -838,9 +850,17 @@ module Effective
|
|
838
850
|
|
839
851
|
raise "Failed to decline order: #{error || errors.full_messages.to_sentence}" unless error.nil?
|
840
852
|
|
853
|
+
send_declined_notifications! if email
|
854
|
+
|
841
855
|
true
|
842
856
|
end
|
843
857
|
|
858
|
+
def declined_reason
|
859
|
+
return unless declined?
|
860
|
+
|
861
|
+
delayed_payment_purchase_result.presence || 'credit card declined'
|
862
|
+
end
|
863
|
+
|
844
864
|
def void!
|
845
865
|
raise('already voided') if voided?
|
846
866
|
voided!(skip_buyer_validations: true)
|
@@ -876,6 +896,19 @@ module Effective
|
|
876
896
|
send_refund_notification! if send_refund_notification_to_admin?
|
877
897
|
end
|
878
898
|
|
899
|
+
def send_declined_notifications!
|
900
|
+
send_order_declined_to_admin! if send_order_declined_to_admin?
|
901
|
+
send_order_declined_to_buyer! if send_order_declined_to_buyer?
|
902
|
+
end
|
903
|
+
|
904
|
+
def send_order_declined_to_admin!
|
905
|
+
EffectiveOrders.send_email(:order_declined_to_admin, self) if declined?
|
906
|
+
end
|
907
|
+
|
908
|
+
def send_order_declined_to_buyer!
|
909
|
+
EffectiveOrders.send_email(:order_declined_to_buyer, self) if declined?
|
910
|
+
end
|
911
|
+
|
879
912
|
def send_order_receipt_to_admin!
|
880
913
|
EffectiveOrders.send_email(:order_receipt_to_admin, self) if purchased?
|
881
914
|
end
|
@@ -9,7 +9,7 @@
|
|
9
9
|
.effective-order-purchase-actions
|
10
10
|
- provider_locals = { order: order, purchased_url: purchased_url, declined_url: declined_url, deferred_url: deferred_url }
|
11
11
|
|
12
|
-
- if EffectiveOrders.delayed? && order.
|
12
|
+
- if EffectiveOrders.delayed? && order.delayed_payment_date_upcoming?
|
13
13
|
= render partial: '/effective/orders/delayed/form', locals: provider_locals
|
14
14
|
|
15
15
|
- elsif EffectiveOrders.free? && order.free?
|
@@ -5,6 +5,7 @@
|
|
5
5
|
= render partial: 'effective/orders/order_header', locals: { order: order }
|
6
6
|
= render partial: 'effective/orders/order_payment', locals: { order: order }
|
7
7
|
= render partial: 'effective/orders/order_shipping', locals: { order: order }
|
8
|
+
= render partial: 'effective/orders/order_declined', locals: { order: order }
|
8
9
|
= render partial: 'effective/orders/order_deferred', locals: { order: order }
|
9
10
|
= render partial: 'effective/orders/order_notes', locals: { order: order }
|
10
11
|
= render partial: 'effective/orders/order_items', locals: { order: order }
|
@@ -13,4 +13,10 @@
|
|
13
13
|
-# This is set by the deluxe.js javascript on Submit
|
14
14
|
= f.hidden_field :payment_intent, required: true
|
15
15
|
|
16
|
+
- if EffectiveOrders.deluxe[:environment] == 'sandbox'
|
17
|
+
.alert.alert-info.mb-4
|
18
|
+
This is the #{Rails.env.upcase} SERVER.
|
19
|
+
%br
|
20
|
+
Use credit card number 4242 4242 4242 4242 with any future expiry and any CVC.
|
21
|
+
|
16
22
|
= render('effective/orders/deluxe/element')
|
@@ -7,4 +7,10 @@
|
|
7
7
|
-# This is set by the deluxe.js javascript on Submit
|
8
8
|
= f.hidden_field :payment_intent, required: true
|
9
9
|
|
10
|
+
- if EffectiveOrders.deluxe[:environment] == 'sandbox'
|
11
|
+
.alert.alert-info.mb-4
|
12
|
+
This is the #{Rails.env.upcase} SERVER.
|
13
|
+
%br
|
14
|
+
Use credit card number 4242 4242 4242 4242 with any future expiry and any CVC.
|
15
|
+
|
10
16
|
= render('effective/orders/deluxe_delayed/element')
|
data/config/effective_orders.rb
CHANGED
@@ -94,9 +94,10 @@ EffectiveOrders.setup do |config|
|
|
94
94
|
# Email settings
|
95
95
|
config.send_order_receipt_to_admin = true
|
96
96
|
config.send_order_receipt_to_buyer = true
|
97
|
+
config.send_order_declined_to_admin = false
|
98
|
+
config.send_order_declined_to_buyer = false
|
97
99
|
config.send_payment_request_to_buyer = true
|
98
100
|
config.send_pending_order_invoice_to_buyer = true
|
99
|
-
|
100
101
|
config.send_refund_notification_to_admin = true
|
101
102
|
|
102
103
|
config.send_order_receipts_when_mark_as_paid = true
|
data/lib/effective_orders.rb
CHANGED
@@ -32,7 +32,9 @@ module EffectiveOrders
|
|
32
32
|
:mailer, :parent_mailer, :deliver_method, :mailer_layout, :mailer_sender, :mailer_admin, :mailer_subject,
|
33
33
|
|
34
34
|
# Emails
|
35
|
-
:send_order_receipt_to_admin, :send_order_receipt_to_buyer,
|
35
|
+
:send_order_receipt_to_admin, :send_order_receipt_to_buyer,
|
36
|
+
:send_order_declined_to_admin, :send_order_declined_to_buyer,
|
37
|
+
:send_payment_request_to_buyer, :send_pending_order_invoice_to_buyer,
|
36
38
|
:send_order_receipts_when_mark_as_paid, :send_order_receipts_when_free,
|
37
39
|
:send_subscription_events,
|
38
40
|
:send_subscription_trialing, :send_subscription_trial_expired,
|
@@ -11,6 +11,14 @@ class EffectiveOrdersMailerPreview < ActionMailer::Preview
|
|
11
11
|
EffectiveOrders.mailer_klass.order_receipt_to_buyer(build_preview_order)
|
12
12
|
end
|
13
13
|
|
14
|
+
def order_declined_to_admin
|
15
|
+
Effective::OrdersMailer.order_declined_to_admin(build_preview_order)
|
16
|
+
end
|
17
|
+
|
18
|
+
def order_declined_to_buyer
|
19
|
+
Effective::OrdersMailer.order_declined_to_buyer(build_preview_order)
|
20
|
+
end
|
21
|
+
|
14
22
|
def payment_request_to_buyer
|
15
23
|
EffectiveOrders.mailer_klass.payment_request_to_buyer(build_preview_order)
|
16
24
|
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: 6.
|
4
|
+
version: 6.14.1
|
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: 2024-
|
11
|
+
date: 2024-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -286,6 +286,7 @@ files:
|
|
286
286
|
- app/views/effective/orders/_layout.html.haml
|
287
287
|
- app/views/effective/orders/_order.html.haml
|
288
288
|
- app/views/effective/orders/_order_actions.html.haml
|
289
|
+
- app/views/effective/orders/_order_declined.html.haml
|
289
290
|
- app/views/effective/orders/_order_deferred.html.haml
|
290
291
|
- app/views/effective/orders/_order_footer.html.haml
|
291
292
|
- app/views/effective/orders/_order_header.html.haml
|
@@ -325,6 +326,8 @@ files:
|
|
325
326
|
- app/views/effective/orders/show.html.haml
|
326
327
|
- app/views/effective/orders/stripe/_element.html.haml
|
327
328
|
- app/views/effective/orders/stripe/_form.html.haml
|
329
|
+
- app/views/effective/orders_mailer/order_declined_to_admin.html.haml
|
330
|
+
- app/views/effective/orders_mailer/order_declined_to_buyer.html.haml
|
328
331
|
- app/views/effective/orders_mailer/order_error.html.haml
|
329
332
|
- app/views/effective/orders_mailer/order_receipt_to_admin.html.haml
|
330
333
|
- app/views/effective/orders_mailer/order_receipt_to_buyer.html.haml
|