lib/active_merchant/billing/credit_card.rb in activemerchant-1.54.0 vs lib/active_merchant/billing/credit_card.rb in activemerchant-1.55.0
- old
+ new
@@ -132,10 +132,33 @@
# the gateway will attempt to validate the value.
#
# @return [String] the verification value
attr_accessor :verification_value
+ # Sets if the credit card requires a verification value.
+ #
+ # @return [Boolean]
+ def require_verification_value=(value)
+ @require_verification_value_set = true
+ @require_verification_value = value
+ end
+
+ # Returns if this credit card needs a verification value.
+ #
+ # By default this returns the configured value from `CreditCard.require_verification_value`,
+ # but one can set a per instance requirement with `credit_card.require_verification_value = false`.
+ #
+ # @return [Boolean]
+ def requires_verification_value?
+ @require_verification_value_set ||= false
+ if @require_verification_value_set
+ @require_verification_value
+ else
+ self.class.requires_verification_value?
+ end
+ end
+
# Returns or sets the track data for the card
#
# @return [String]
attr_accessor :track_data
@@ -344,10 +367,10 @@
if verification_value?
unless valid_card_verification_value?(verification_value, brand)
errors << [:verification_value, "should be #{card_verification_value_length(brand)} digits"]
end
- elsif self.class.requires_verification_value?
+ elsif requires_verification_value?
errors << [:verification_value, "is required"]
end
errors
end