mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-28 06:15:17 +00:00
Attempt to add a credit card before processing payment
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
module OpenFoodNetwork
|
||||
class StandingOrderPaymentUpdater
|
||||
|
||||
def initialize(order)
|
||||
@order = order
|
||||
end
|
||||
|
||||
def update!
|
||||
return unless payment
|
||||
return if payment.blank?
|
||||
|
||||
if card_required? && !card_set?
|
||||
return unless ensure_credit_card
|
||||
end
|
||||
|
||||
payment.update_attributes(amount: @order.outstanding_balance)
|
||||
end
|
||||
|
||||
@@ -15,5 +19,22 @@ module OpenFoodNetwork
|
||||
def payment
|
||||
@payment ||= @order.pending_payments.last
|
||||
end
|
||||
|
||||
def card_required?
|
||||
payment.payment_method.is_a? Spree::Gateway::StripeConnect
|
||||
end
|
||||
|
||||
def card_set?
|
||||
payment.source is_a? Spree::CreditCard
|
||||
end
|
||||
|
||||
def ensure_credit_card
|
||||
return false unless saved_credit_card.present?
|
||||
payment.update_attributes(source: saved_credit_card)
|
||||
end
|
||||
|
||||
def saved_credit_card
|
||||
@order.standing_order.credit_card
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user