mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-02 21:57:17 +00:00
use capture! if payment is already authorized
This commit is contained in:
@@ -6,14 +6,22 @@ module Spree
|
||||
def process!
|
||||
return unless validate!
|
||||
|
||||
purchase!
|
||||
if response_code
|
||||
capture!
|
||||
else
|
||||
purchase!
|
||||
end
|
||||
end
|
||||
|
||||
def process_offline!
|
||||
return unless validate!
|
||||
return if authorization_action_required?
|
||||
|
||||
charge_offline!
|
||||
if response_code
|
||||
capture!
|
||||
else
|
||||
charge_offline!
|
||||
end
|
||||
end
|
||||
|
||||
def authorize!(return_url = nil)
|
||||
|
||||
@@ -14,7 +14,7 @@ FactoryBot.define do
|
||||
association(:source, factory: :credit_card)
|
||||
order
|
||||
state { 'checkout' }
|
||||
response_code { '12345' }
|
||||
response_code { nil }
|
||||
|
||||
payment_method { FactoryBot.create(:payment_method, distributors: [distributor]) }
|
||||
end
|
||||
|
||||
@@ -97,6 +97,30 @@ describe Spree::Payment do
|
||||
expect { payment.process! }.to raise_error(Spree::Core::GatewayError)
|
||||
expect(payment.state).to eq('invalid')
|
||||
end
|
||||
|
||||
context "the payment is already authorized" do
|
||||
before do
|
||||
allow(payment).to receive(:response_code) { "pi_123" }
|
||||
end
|
||||
|
||||
it "should call capture instead of purchase" do
|
||||
expect(payment).to receive(:capture!)
|
||||
expect(payment).to_not receive(:purchase!)
|
||||
payment.process!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "#process_offline when payment is already authorized" do
|
||||
before do
|
||||
allow(payment).to receive(:response_code) { "pi_123" }
|
||||
end
|
||||
|
||||
it "should call capture if the payment is already authorized" do
|
||||
expect(payment).to receive(:capture!)
|
||||
expect(payment).to_not receive(:purchase!)
|
||||
payment.process!
|
||||
end
|
||||
end
|
||||
|
||||
context "#authorize" do
|
||||
|
||||
Reference in New Issue
Block a user