7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'app/controllers/effective/providers/deluxe_delayed_purchase.rb', line 7
def deluxe_delayed_purchase
raise('deluxe_delayed_purchase provider is not available') unless EffectiveOrders.deluxe_delayed?
@order ||= Order.deep.find(params[:id])
@order.current_user = nil
EffectiveResources.authorize!(self, :update, @order)
EffectiveResources.authorize!(self, :admin, :effective_orders)
raise('expected a delayed? and deferred? order') unless @order.delayed? && @order.deferred?
api = Effective::DeluxeApi.new
purchased = api.purchase!(@order, @order.delayed_payment_intent)
payment = api.payment
if purchased == false
flash[:danger] = "Payment was unsuccessful. The credit card payment failed with message: #{Array(payment['responseMessage']).to_sentence.presence || 'none'}. Please try again."
return order_declined(
payment: payment,
provider: 'deluxe_delayed',
card: payment['card'],
declined_url: deluxe_delayed_purchase_params[:declined_url]
)
end
@order.assign_attributes(deluxe_delayed_purchase_params.except(:purchased_url, :declined_url, :id))
order_purchased(
payment: payment,
provider: 'deluxe_delayed',
card: payment['card'],
email: @order.send_mark_as_paid_email_to_buyer?,
skip_buyer_validations: true,
purchased_url: effective_orders.admin_order_path(@order)
)
end
|