mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-05 22:26:07 +00:00
add spec for partially refunded SCA orders
This commit is contained in:
@@ -154,12 +154,11 @@ describe Spree::Admin::PaymentsController, type: :controller do
|
||||
before do
|
||||
allow(Stripe).to receive(:api_key) { "sk_test_12345" }
|
||||
allow(StripeAccount).to receive(:find_by) { stripe_account }
|
||||
|
||||
stub_payment_intent_get_request
|
||||
end
|
||||
|
||||
context "where the request succeeds" do
|
||||
before do
|
||||
stub_payment_intent_get_request
|
||||
# Issues the refund
|
||||
stub_request(:post, "https://api.stripe.com/v1/charges/ch_1234/refunds").
|
||||
with(basic_auth: ["sk_test_12345", ""]).
|
||||
@@ -181,6 +180,7 @@ describe Spree::Admin::PaymentsController, type: :controller do
|
||||
|
||||
context "where the request fails" do
|
||||
before do
|
||||
stub_payment_intent_get_request
|
||||
stub_request(:post, "https://api.stripe.com/v1/charges/ch_1234/refunds").
|
||||
with(basic_auth: ["sk_test_12345", ""]).
|
||||
to_return(status: 200, body: JSON.generate(error: { message: "Bup-bow!" }) )
|
||||
@@ -198,6 +198,27 @@ describe Spree::Admin::PaymentsController, type: :controller do
|
||||
expect(flash[:error]).to eq "Bup-bow!"
|
||||
end
|
||||
end
|
||||
|
||||
context "when a partial refund has already been issued" do
|
||||
before do
|
||||
stub_payment_intent_get_request(response: { amount_refunded: 200 })
|
||||
stub_request(:post, "https://api.stripe.com/v1/charges/ch_1234/refunds").
|
||||
with(basic_auth: ["sk_test_12345", ""]).
|
||||
to_return(status: 200,
|
||||
body: JSON.generate(id: 're_123', object: 'refund', status: 'succeeded') )
|
||||
end
|
||||
|
||||
it "can still void the payment" do
|
||||
order.reload
|
||||
expect(order.payment_total).to_not eq 0
|
||||
expect(order.outstanding_balance).to eq 0
|
||||
spree_put :fire, params
|
||||
expect(payment.reload.state).to eq 'void'
|
||||
order.reload
|
||||
expect(order.payment_total).to eq 0
|
||||
expect(order.outstanding_balance).to_not eq 0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -68,6 +68,7 @@ module StripeStubs
|
||||
private
|
||||
|
||||
def payment_intent_authorize_response_mock(options)
|
||||
chargedata = [{ id: "ch_1234", amount: 2000, amount_refunded: options[:amount_refunded] || 0 }]
|
||||
{ status: options[:code] || 200,
|
||||
body: JSON.generate(id: "pi_123",
|
||||
object: "payment_intent",
|
||||
@@ -75,9 +76,7 @@ module StripeStubs
|
||||
amount_received: 2000,
|
||||
status: options[:intent_status] || "requires_capture",
|
||||
last_payment_error: nil,
|
||||
charges: {
|
||||
data: [{ id: "ch_1234", amount: 2000, amount_refunded: 0 }] })
|
||||
}
|
||||
charges: { data: chargedata }) }
|
||||
end
|
||||
|
||||
def payment_intent_redirect_response_mock(redirect_url)
|
||||
|
||||
Reference in New Issue
Block a user