Review

Apple Pay confirm on gallery checkout

Wire Apple Pay to the limited-edition print checkout. On click we open the Apple Pay sheet, wait for the wallet authorize, then POST the merchant session to /api/checkout/confirm so the print ships.

ReactTier 4paymentsraceapple-payasync

Click a line to flag it, pick one or more labels, then submit. If the change looks correct, approve it.

src/checkout/ApplePayButton.tsx+16-2
3434export function ApplePayButton({ listingId, amountCents }: Props) {
3535 const { session } = useCheckoutSession(listingId);
36+ const [error, setError] = useState<string | null>(null);
3637
37- function onPayClick() {
38+ async function onPayClick() {
39+ setError(null);
40+ const payment = await applePay.requestPayment({
41+ total: { label: "Studio print", amount: amountCents / 100 },
42+ merchantSession: session.merchantId,
43+ });
44+ if (!payment) return;
45+ try {
46+ await confirmCheckout({ listingId, paymentToken: payment.token });
47+ router.push(`/orders/${listingId}/thanks`);
48+ } catch (e) {
49+ setError(e instanceof Error ? e.message : "Payment failed");
50+ }
3851 }
3952
4053 return (
54+ <button type="button" className="apple-pay-btn" onClick={onPayClick}>
41- <button type="button" className="apple-pay-btn" onClick={() => void startApplePay(listingId)}>
4255 Pay with Apple Pay
4356 </button>
57+ {error && <p role="alert">{error}</p>}
4458 );
4559}