From 813459ee384b711d1141c0790f32caa956cb0a07 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Wed, 22 Jul 2020 17:05:45 +0200 Subject: [PATCH] Clarify method documentation --- app/models/spree/payment.rb | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/app/models/spree/payment.rb b/app/models/spree/payment.rb index f940db551f..13fc27c6aa 100644 --- a/app/models/spree/payment.rb +++ b/app/models/spree/payment.rb @@ -32,16 +32,12 @@ module Spree # invalidate previously entered payments after_create :invalidate_old_payments - # Prevents #validate_source to end up in a chain of validations, from - # payment to payment up until the original credit card record. + # Skips the validation of the source (for example, credit card) of the payment. # - # All payments are validated before saving thus, we get nothing by checking - # they are valid in the future. Quite the opposite. Stripe is accepting - # refunds whose source are cards that were valid when the payment was - # placed but are now expired, and we consider them invalid. - # - # Skipping the source validation when applying a refund avoids this - # situation. We trust the payment gateway. + # This is used in refunds as the validation of the card can fail but the refund can go through, + # we trust the payment gateway in these cases. For example, Stripe is accepting refunds with + # source cards that were valid when the payment was placed but are now expired, and we + # consider them invalid. attr_accessor :skip_source_validation attr_accessor :source_attributes @@ -188,10 +184,13 @@ module Spree gateway_error e end - # Inherited from Spree, makes newly entered payments invalidate previously - # entered payments so the most recent payment is used by the gateway. + # Makes newly entered payments invalidate previously entered payments so the most recent payment + # is used by the gateway. def invalidate_old_payments order.payments.with_state('checkout').where("id != ?", id).each do |payment| + + # Using update_column skips validations and so it skips validate_source. As we are just + # invalidating past payments here, we don't want to validate all of them at this stage. payment.update_column(:state, 'invalid') end end