mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-02 21:57:17 +00:00
Turn ivars into private attr_readers
This makes them more changeable and robust. Ruby will raise NoMethodError on typos while it'll silently create a new ivar without us noticing. Also, in my experience, a reader method gives more room to future refactorings and eases testing because methods are easier to stub.
This commit is contained in:
@@ -10,23 +10,23 @@ class ProcessPaymentIntent
|
||||
def call!
|
||||
return unless valid?
|
||||
|
||||
@last_payment.update_attribute(:cvv_response_message, nil)
|
||||
@last_payment.complete!
|
||||
last_payment.update_attribute(:cvv_response_message, nil)
|
||||
last_payment.complete!
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
attr_reader :order
|
||||
attr_reader :order, :payment_intent, :last_payment
|
||||
|
||||
def valid?
|
||||
order.present? && valid_intent_string? && matches_last_payment?
|
||||
end
|
||||
|
||||
def valid_intent_string?
|
||||
@payment_intent&.starts_with?("pi_")
|
||||
payment_intent&.starts_with?("pi_")
|
||||
end
|
||||
|
||||
def matches_last_payment?
|
||||
@last_payment&.state == "pending" && @last_payment&.response_code == @payment_intent
|
||||
last_payment&.state == "pending" && last_payment&.response_code == payment_intent
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user