replace cvv_response_message usage with redirect_auth_url

This commit is contained in:
Ahmed Ejaz
2025-08-28 02:29:32 +05:00
parent aecb5f49c9
commit ac06126f59
15 changed files with 32 additions and 32 deletions

View File

@@ -57,7 +57,7 @@ module Spree
scope :failed, -> { with_state('failed') }
scope :valid, -> { where.not(state: %w(failed invalid)) }
scope :void, -> { with_state('void') }
scope :authorization_action_required, -> { where.not(cvv_response_message: nil) }
scope :authorization_action_required, -> { where.not(redirect_auth_url: nil) }
scope :requires_authorization, -> { with_state("requires_authorization") }
scope :with_payment_intent, ->(code) { where(response_code: code) }
@@ -164,7 +164,7 @@ module Spree
end
def clear_authorization_url
update_attribute(:cvv_response_message, nil)
update_attribute(:redirect_auth_url, nil)
end
private

View File

@@ -2,7 +2,7 @@
module Api
class PaymentSerializer < ActiveModel::Serializer
attributes :amount, :updated_at, :payment_method, :state, :cvv_response_message
attributes :amount, :updated_at, :payment_method, :state, :redirect_auth_url
def payment_method
object.payment_method.try(:name)

View File

@@ -5,7 +5,7 @@
# /checkout; for admin payments and subscription payemnts it's the order url.
#
# This class confirms that the payment intent matches what's in our database,
# marks the payment as complete, and removes the cvv_response_message field,
# marks the payment as complete, and removes the redirect_auth_url field,
# which we use to indicate that authorization is required. It also completes the
# Order, if appropriate.

View File

@@ -66,7 +66,7 @@ module OrderManagement
allow(PaymentMailer).to receive(:authorization_required) { mail_mock }
allow(payment).to receive(:authorize!) {
payment.state = "requires_authorization"
payment.cvv_response_message = "https://stripe.com/redirect"
payment.redirect_auth_url = "https://stripe.com/redirect"
}
end

View File

@@ -64,7 +64,7 @@ namespace :ofn do
environment = '#{Rails.env}'")
Spree::Payment.update_all("response_code = null, avs_response = null,
cvv_response_code = null, identifier = null,
cvv_response_message = null")
cvv_response_message = null, redirect_auth_url = null")
Spree::CreditCard.update_all("
month = 12, year = 2020, start_month = 12, start_year = 2000,
cc_type = 'VISA', first_name = 'Dummy', last_name = 'Dummy', last_digits = '2543'")

View File

@@ -208,7 +208,7 @@ RSpec.describe PaymentGateways::StripeController do
create(
:payment,
payment_method:,
cvv_response_message: "https://stripe.com/redirect",
redirect_auth_url: "https://stripe.com/redirect",
response_code: "pi_123",
order:,
state: "requires_authorization"
@@ -244,7 +244,7 @@ RSpec.describe PaymentGateways::StripeController do
expect(response).to redirect_to order_path(order)
payment.reload
expect(payment.state).to eq("completed")
expect(payment.cvv_response_message).to be nil
expect(payment.redirect_auth_url).to be nil
end
it "moves the order state to completed" do
@@ -273,7 +273,7 @@ RSpec.describe PaymentGateways::StripeController do
expect(response).to redirect_to order_path(order)
payment.reload
expect(payment.state).to eq("completed")
expect(payment.cvv_response_message).to be nil
expect(payment.redirect_auth_url).to be nil
end
end
@@ -288,7 +288,7 @@ RSpec.describe PaymentGateways::StripeController do
expect(response).to redirect_to order_path(order)
payment.reload
expect(payment.state).to eq("completed")
expect(payment.cvv_response_message).to be nil
expect(payment.redirect_auth_url).to be nil
end
end
end
@@ -307,7 +307,7 @@ RSpec.describe PaymentGateways::StripeController do
expect(response).to redirect_to order_path(order)
expect(flash[:error]).to eq("The payment could not be processed. error message")
payment.reload
expect(payment.cvv_response_message).to be nil
expect(payment.redirect_auth_url).to be nil
expect(payment.state).to eq("failed")
end
end
@@ -330,7 +330,7 @@ RSpec.describe PaymentGateways::StripeController do
expect(response).to redirect_to order_path(order)
expect(flash[:error]).to eq("The payment could not be processed. ")
payment.reload
expect(payment.cvv_response_message).to eq("https://stripe.com/redirect")
expect(payment.redirect_auth_url).to eq("https://stripe.com/redirect")
expect(payment.state).to eq("requires_authorization")
end
end

View File

@@ -78,7 +78,7 @@ RSpec.describe Spree::Admin::PaymentsController do
context "where further action is required" do
before do
allow_any_instance_of(Spree::Payment).to receive(:authorize!) do |payment|
payment.update cvv_response_message: "https://www.stripe.com/authorize"
payment.update redirect_auth_url: "https://www.stripe.com/authorize"
payment.update state: "requires_authorization"
end
end
@@ -234,7 +234,7 @@ RSpec.describe Spree::Admin::PaymentsController do
allow(PaymentMailer).to receive(:authorize_payment) { mail_mock }
request.env["HTTP_REFERER"] = "http://foo.com"
allow(Spree::Payment).to receive(:find).with(payment.id.to_s) { payment }
allow(payment).to receive(:cvv_response_message).and_return("https://www.stripe.com/authorize")
allow(payment).to receive(:redirect_auth_url).and_return("https://www.stripe.com/authorize")
allow(payment).to receive(:requires_authorization?) { true }
end

View File

@@ -44,7 +44,7 @@ RSpec.describe Stripe::AuthorizeResponsePatcher do
it "patches response.cvv_result.message with nil" do
new_response = patcher.call!
expect(new_response.cvv_result['message']).to be_nil
expect(new_response.cvv_result['redirect_auth_url']).to eq nil
end
end
end

View File

@@ -1048,11 +1048,11 @@ RSpec.describe Spree::Payment do
end
describe "#clear_authorization_url" do
let(:payment) { create(:payment, cvv_response_message: "message") }
let(:payment) { create(:payment, redirect_auth_url: "auth_url") }
it "removes the cvv_response_message" do
it "removes the redirect_auth_url" do
payment.clear_authorization_url
expect(payment.cvv_response_message).to eq(nil)
expect(payment.redirect_auth_url).to eq(nil)
end
end

View File

@@ -9,11 +9,11 @@ RSpec.describe PaymentsRequiringActionQuery do
let(:order) { create(:order, user:) }
describe '#call' do
context "payment has a cvv_response_message" do
context "payment has a redirect_auth_url" do
let(:payment) do
create(:payment,
order:,
cvv_response_message: "https://stripe.com/redirect",
redirect_auth_url: "https://stripe.com/redirect",
state: "requires_authorization")
end
@@ -22,9 +22,9 @@ RSpec.describe PaymentsRequiringActionQuery do
end
end
context "payment has no cvv_response_message" do
context "payment has no redirect_auth_url" do
let(:payment) do
create(:payment, order:, cvv_response_message: nil)
create(:payment, order:, redirect_auth_url: nil)
end
it "does not find the payment" do

View File

@@ -18,18 +18,18 @@ RSpec.describe "/payments/:id/authorize" do
describe "when user is logged in" do
before { sign_in user }
context "has cvv response message" do
context "has redirect auth url" do
before do
allow_any_instance_of(Spree::Payment).to receive(:cvv_response_message).and_return('http://example.com')
allow_any_instance_of(Spree::Payment).to receive(:redirect_auth_url).and_return('http://example.com')
end
it "redirects to the CVV response URL" do
it "redirects to the 3D-Auth url" do
get authorize_payment_path(payment)
expect(response).to redirect_to('http://example.com')
end
end
context "doesn't have cvv response message" do
context "doesn't have redirect auth url" do
it "redirect to order URL" do
get authorize_payment_path(payment)
expect(response).to redirect_to(order_url(order))

View File

@@ -44,7 +44,7 @@ RSpec.describe Api::Admin::OrderSerializer do
order:,
state: 'requires_authorization',
amount: 123.45,
cvv_response_message: "https://stripe.com/redirect"
redirect_auth_url: "https://stripe.com/redirect"
)
end

View File

@@ -36,7 +36,7 @@ RSpec.describe Checkout::StripeRedirect do
true
end
expect(stripe_payment).to receive(:cvv_response_message).and_return(test_redirect_url)
expect(stripe_payment).to receive(:redirect_auth_url).and_return(test_redirect_url)
expect(service.path).to eq test_redirect_url
end

View File

@@ -17,7 +17,7 @@ RSpec.describe ProcessPaymentIntent do
create(
:payment,
payment_method:,
cvv_response_message: "https://stripe.com/redirect",
redirect_auth_url: "https://stripe.com/redirect",
response_code: "pi_123",
order:,
state: "requires_authorization"
@@ -104,7 +104,7 @@ RSpec.describe ProcessPaymentIntent do
service.call!
payment.reload
expect(payment.state).to eq("completed")
expect(payment.cvv_response_message).to be nil
expect(payment.redirect_auth_url).to be nil
end
it "completes the order" do

View File

@@ -17,7 +17,7 @@ RSpec.describe "Payments requiring action" do
let!(:payment) do
create(:payment,
order:,
cvv_response_message: "https://stripe.com/redirect",
redirect_auth_url: "https://stripe.com/redirect",
state: "requires_authorization")
end
@@ -31,7 +31,7 @@ RSpec.describe "Payments requiring action" do
context "there are no payments requiring authorization" do
let!(:payment) do
create(:payment, order:, cvv_response_message: nil)
create(:payment, order:, redirect_auth_url: nil)
end
it "does not show the table of payments requiring authorization" do