fix(checkout): take a repeated capture as a successful payment
The CMS answers a capture of an order already paid with this PayPal order
with { success: true, alreadyCaptured: true } instead of the order. Step 3
took that answer for a capture without authorisation and showed a payment
error. It now reloads the paid order (keeping the shown one if the reload
fails) and continues as after a first capture: confirmation, the
checkout-payment-completed event, and the redirect to the order's result
page. capturePayment is typed as Order | AlreadyCaptured, and the pure
isAlreadyCaptured (utils/captureResponse.ts) tells them apart.
Refs libretech/mp#71
This commit is contained in:
@@ -9,6 +9,7 @@ import type {
|
||||
PaymentMethod,
|
||||
ApiResponse
|
||||
} from "~/types";
|
||||
import type { AlreadyCaptured } from "~/utils/captureResponse";
|
||||
|
||||
/**
|
||||
* Shop API composable.
|
||||
@@ -116,8 +117,9 @@ export function useShopApi() {
|
||||
});
|
||||
},
|
||||
|
||||
async capturePayment(uuid: string, paypalOrderId: string): Promise<Order> {
|
||||
return await $fetch<Order>(`/api/orders/${uuid}/capture/${paypalOrderId}`, {
|
||||
/** The paid order, or { success: true, alreadyCaptured: true } when an earlier capture of this PayPal order went through. */
|
||||
async capturePayment(uuid: string, paypalOrderId: string): Promise<Order | AlreadyCaptured> {
|
||||
return await $fetch<Order | AlreadyCaptured>(`/api/orders/${uuid}/capture/${paypalOrderId}`, {
|
||||
method: "POST"
|
||||
});
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user