mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
separate method for charging offline
This commit is contained in:
@@ -62,7 +62,7 @@ class SubscriptionConfirmJob
|
||||
return unless order.payment_required?
|
||||
|
||||
prepare_for_payment!(order)
|
||||
order.process_payments!
|
||||
order.process_payments!(true)
|
||||
raise if order.errors.any?
|
||||
end
|
||||
|
||||
|
||||
@@ -45,6 +45,19 @@ module Spree
|
||||
failed_activemerchant_billing_response(e.message)
|
||||
end
|
||||
|
||||
# NOTE: the name of this method is determined by Spree::Payment::Processing
|
||||
def charge_offline(money, creditcard, gateway_options)
|
||||
options = basic_options(gateway_options)
|
||||
customer_id, payment_method_id = Stripe::CreditCardCloner.new.clone(creditcard,
|
||||
stripe_account_id)
|
||||
|
||||
options[:customer] = customer_id
|
||||
options[:off_session] = true
|
||||
provider.purchase(money, payment_method_id, options)
|
||||
rescue Stripe::StripeError => e
|
||||
failed_activemerchant_billing_response(e.message)
|
||||
end
|
||||
|
||||
# NOTE: the name of this method is determined by Spree::Payment::Processing
|
||||
def authorize(money, creditcard, gateway_options)
|
||||
authorize_response = provider.authorize(*options_for_authorize(money,
|
||||
|
||||
@@ -499,13 +499,13 @@ module Spree
|
||||
# which gets rescued and converted to FALSE when
|
||||
# :allow_checkout_on_gateway_error is set to false
|
||||
#
|
||||
def process_payments!
|
||||
def process_payments!(offline = false)
|
||||
raise Core::GatewayError, Spree.t(:no_pending_payments) if pending_payments.empty?
|
||||
|
||||
pending_payments.each do |payment|
|
||||
break if payment_total >= total
|
||||
|
||||
payment.process!
|
||||
payment.process!(offline)
|
||||
|
||||
if payment.completed?
|
||||
self.payment_total += payment.amount
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
module Spree
|
||||
class Payment < ActiveRecord::Base
|
||||
module Processing
|
||||
def process!
|
||||
def process!(offline = false)
|
||||
return unless payment_method&.source_required?
|
||||
|
||||
raise Core::GatewayError, Spree.t(:payment_processing_failed) unless source
|
||||
@@ -15,7 +15,9 @@ module Spree
|
||||
raise Core::GatewayError, Spree.t(:payment_method_not_supported)
|
||||
end
|
||||
|
||||
if payment_method.auto_capture?
|
||||
if offline
|
||||
charge_offline!
|
||||
elsif payment_method.auto_capture?
|
||||
purchase!
|
||||
else
|
||||
authorize!
|
||||
@@ -32,6 +34,11 @@ module Spree
|
||||
gateway_action(source, :purchase, :complete)
|
||||
end
|
||||
|
||||
def charge_offline!
|
||||
started_processing!
|
||||
gateway_action(source, :charge_offline, :complete)
|
||||
end
|
||||
|
||||
def capture!
|
||||
return true if completed?
|
||||
|
||||
|
||||
Reference in New Issue
Block a user