effective_orders 6.13.3 → 6.14.0

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: a7823c5fb7e1f5de56c962426e8ac2f19dcf21eb3ee562652a086db304b1da18
4
- data.tar.gz: f9487dfd15d7088bb70c96a865b8ef06e16fe67c986e25df209234e0f40344e8
3
+ metadata.gz: cdbb9b1f68ae5470c0d64b4e7d27ca32cdcd21c99ce4cdcf36cd06182852bf85
4
+ data.tar.gz: 91732e8679f53cc672cdcf888e79680882cf83fe92a955d95e8a299719eb18ba
5
5
  SHA512:
6
- metadata.gz: c5385f2d84ac47da6a90f54dce6a7abde305a85637f1fa9c15686c5fee5e27f36f9ac20c65355c4e92225a02496cb26e7f009a09bc00a6ba8e3c0bd7423a5619
7
- data.tar.gz: fca2f157ed9f4d30b716382b6161653c42867e4d229f14707b6e2f11edbd49eec1d2677ac7ed381d527f025817d1c050dcc27ff8a2127899a330f34abffdbbbf
6
+ metadata.gz: 974902ddc3095ec659b94e6af5ad8c45ae29ca52f1fa790cf6f787f22ecbc48d2bf1127c50ca0b9d396471700a928c30c734d8dd812b75a204d6ff1e4cc6f572
7
+ data.tar.gz: 1b02ad24cb46a6377c68a68dbe705e23a201860f4696ca1122237c5d228e01ee72951a05dd74e4ebda2cc92c41fc2c01e2e1bf7f62881fc51cb58f46abfa543c
@@ -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
 
@@ -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)
@@ -602,6 +602,16 @@ module Effective
602
602
  EffectiveOrders.send_order_receipt_to_buyer
603
603
  end
604
604
 
605
+ def send_order_declined_to_admin?
606
+ return false if free? && !EffectiveOrders.send_order_receipts_when_free
607
+ EffectiveOrders.send_order_declined_to_admin
608
+ end
609
+
610
+ def send_order_declined_to_buyer?
611
+ return false if free? && !EffectiveOrders.send_order_receipts_when_free
612
+ EffectiveOrders.send_order_declined_to_buyer
613
+ end
614
+
605
615
  def send_payment_request_to_buyer?
606
616
  return false if free? && !EffectiveOrders.send_order_receipts_when_free
607
617
  return false if refund?
@@ -803,7 +813,8 @@ module Effective
803
813
  true
804
814
  end
805
815
 
806
- def decline!(payment: 'none', provider: 'none', card: 'none', validate: true)
816
+ # We only turn on the email when done by a delayed payment or from a rake script.
817
+ def decline!(payment: 'none', provider: 'none', card: 'none', validate: true, email: false)
807
818
  return false if declined?
808
819
  raise('order already purchased') if purchased?
809
820
 
@@ -838,9 +849,17 @@ module Effective
838
849
 
839
850
  raise "Failed to decline order: #{error || errors.full_messages.to_sentence}" unless error.nil?
840
851
 
852
+ send_declined_notifications! if email
853
+
841
854
  true
842
855
  end
843
856
 
857
+ def declined_reason
858
+ return unless declined?
859
+
860
+ delayed_payment_purchase_result.presence || 'credit card declined'
861
+ end
862
+
844
863
  def void!
845
864
  raise('already voided') if voided?
846
865
  voided!(skip_buyer_validations: true)
@@ -876,6 +895,19 @@ module Effective
876
895
  send_refund_notification! if send_refund_notification_to_admin?
877
896
  end
878
897
 
898
+ def send_declined_notifications!
899
+ send_order_declined_to_admin! if send_order_declined_to_admin?
900
+ send_order_declined_to_buyer! if send_order_declined_to_buyer?
901
+ end
902
+
903
+ def send_order_declined_to_admin!
904
+ EffectiveOrders.send_email(:order_declined_to_admin, self) if declined?
905
+ end
906
+
907
+ def send_order_declined_to_buyer!
908
+ EffectiveOrders.send_email(:order_declined_to_buyer, self) if declined?
909
+ end
910
+
879
911
  def send_order_receipt_to_admin!
880
912
  EffectiveOrders.send_email(:order_receipt_to_admin, self) if purchased?
881
913
  end
@@ -0,0 +1,2 @@
1
+ %p.effective-orders-receipt-info An order has been declined by the payment processor: #{@order.declined_reason}
2
+ = render(@order, no_order_actions: true)
@@ -0,0 +1,2 @@
1
+ %p.effective-orders-receipt-info Your order was declined by the payment processor: #{@order.declined_reason}
2
+ = render(@order, no_order_actions: true)
@@ -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
@@ -1,3 +1,3 @@
1
1
  module EffectiveOrders
2
- VERSION = '6.13.3'.freeze
2
+ VERSION = '6.14.0'.freeze
3
3
  end
@@ -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, :send_payment_request_to_buyer, :send_pending_order_invoice_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.13.3
4
+ version: 6.14.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: 2024-06-11 00:00:00.000000000 Z
11
+ date: 2024-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -325,6 +325,8 @@ files:
325
325
  - app/views/effective/orders/show.html.haml
326
326
  - app/views/effective/orders/stripe/_element.html.haml
327
327
  - app/views/effective/orders/stripe/_form.html.haml
328
+ - app/views/effective/orders_mailer/order_declined_to_admin.html.haml
329
+ - app/views/effective/orders_mailer/order_declined_to_buyer.html.haml
328
330
  - app/views/effective/orders_mailer/order_error.html.haml
329
331
  - app/views/effective/orders_mailer/order_receipt_to_admin.html.haml
330
332
  - app/views/effective/orders_mailer/order_receipt_to_buyer.html.haml