Skip to content

Commit ad17b62

Browse files
committed
Fix Payment#is_cvv_risky?
Should not be false when a CVV message is present; that's just a field to collect descriptions from the payment gateway, the code is what matters This makes it consistent with both Payment.risky and OrdersHelper#cvv_response_code.
1 parent 28628d7 commit ad17b62

File tree

2 files changed

+9
-19
lines changed

2 files changed

+9
-19
lines changed

core/app/models/spree/payment.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ def is_avs_risky?
137137
def is_cvv_risky?
138138
return false if cvv_response_code == "M"
139139
return false if cvv_response_code.nil?
140-
return false if cvv_response_message.present?
141140
true
142141
end
143142

core/spec/models/spree/payment_spec.rb

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,26 +1231,17 @@
12311231
end
12321232
end
12331233

1234-
describe "is_cvv_risky?" do
1235-
it "returns false if cvv_response_code == 'M'" do
1236-
payment.update_attribute(:cvv_response_code, "M")
1237-
expect(payment.is_cvv_risky?).to eq(false)
1238-
end
1239-
1240-
it "returns false if cvv_response_code == nil" do
1241-
payment.update_attribute(:cvv_response_code, nil)
1242-
expect(payment.is_cvv_risky?).to eq(false)
1243-
end
1244-
1245-
it "returns false if cvv_response_message == ''" do
1246-
payment.update_attribute(:cvv_response_message, '')
1247-
expect(payment.is_cvv_risky?).to eq(false)
1234+
describe "#is_cvv_risky?" do
1235+
['M', nil].each do |char|
1236+
it "returns false if cvv_response_code is #{char.inspect}" do
1237+
payment.cvv_response_code = char
1238+
expect(payment.is_cvv_risky?).to eq(false)
1239+
end
12481240
end
12491241

1250-
it "returns true if cvv_response_code == [A-Z], omitting D" do
1251-
# should use cvv_response_code helper
1252-
(%w{N P S U} << "").each do |char|
1253-
payment.update_attribute(:cvv_response_code, char)
1242+
['', *('A'...'M'), *('N'..'Z')].each do |char|
1243+
it "returns true if cvv_response_code is #{char.inspect} (not 'M' or nil)" do
1244+
payment.cvv_response_code = char
12541245
expect(payment.is_cvv_risky?).to eq(true)
12551246
end
12561247
end

0 commit comments

Comments
 (0)