A buyer approving an order is not the same event as a successful capture. PayPal’s own card-testing documentation includes a response with an order marked COMPLETED and a nested capture marked DECLINED. A success screen that checks only the outer status can therefore misreport a refused payment. This guide reproduces that mistake and tests the states around it.
Pick the product before choosing the fixture
| Flow | Setup and fixture source | Boundary to test |
|---|---|---|
| PayPal wallet | Separate sandbox merchant and buyer accounts | Login, approval, cancellation and server capture |
| Expanded Checkout card payment | PayPal’s documented card-testing values or its generator | Card triggers and capture response |
| Braintree | Braintree sandbox credentials and its own testing reference | Its transaction, verification and settlement rules |
Create and inspect accounts in the PayPal sandbox dashboard. Use sandbox application credentials with sandbox endpoints; keep the client secret on the server. Configure the buyer’s funding source for the wallet scenario you actually intend to test.
PayPal’s card-testing documentation provides static cards, its own generator and Expanded Checkout rejection triggers such as CCREJECT-EC. Those are product-specific instructions. Do not assume they apply to every PayPal-owned payment product. The provider also labels 3636500000000260 as a JCB sandbox fixture: its scripted role is not a reason to rewrite a local network-prefix profile.
Use the cross-provider test-card reference for fixture selection. A locally generated number can exercise form validation without guaranteeing a PayPal response. The real-payment failure guide explains the environment boundary.
Inspect the capture that belongs to your order
The example below handles USD, one purchase unit and one final capture. Load the expected order ID, reference, amount and currency from your server’s order record. Receive the provider response through your authenticated server integration. A browser-supplied “expected amount” would defeat the comparison.
function usdCents(value) {
if (typeof value !== 'string' || !/^(0|[1-9][0-9]{0,9})\.[0-9]{2}$/.test(value)) return null;
return BigInt(value.replace('.', ''));
}
export function inspectCaptureOrder(order, expected) {
// Restricted example: USD, one purchase unit, one final capture.
// expected is loaded from YOUR server order, not from the buyer's request.
const amount = usdCents(expected?.amount);
if (!expected || expected.currency !== 'USD' || amount === null || amount <= 0n ||
typeof expected.orderId !== 'string' || !expected.orderId ||
typeof expected.referenceId !== 'string' || !expected.referenceId) return 'review';
if (!order || order.id !== expected.orderId || order.status !== 'COMPLETED' ||
!Array.isArray(order.purchase_units) || order.purchase_units.length !== 1) return 'review';
const unit = order.purchase_units[0];
const captures = unit?.payments?.captures;
if (unit?.reference_id !== expected.referenceId ||
!Array.isArray(captures) || captures.length !== 1) return 'review';
const capture = captures[0];
if (!capture || typeof capture.id !== 'string' || !capture.id ||
capture.amount?.currency_code !== expected.currency ||
usdCents(capture.amount?.value) !== amount || capture.final_capture !== true) return 'review';
if (capture.status === 'COMPLETED') return 'paid';
if (capture.status === 'PENDING') return 'pending';
if (capture.status === 'DECLINED') return 'declined';
return 'review';
}usdCents in the complete module accepts a two-decimal USD string and compares integer cents. This is deliberately not a universal currency parser. A different currency, multiple units, split captures, mismatched amount or unfamiliar response goes to review. Support those cases explicitly before using this model for a wider business flow.
| Case | Input / condition | Expected result |
|---|---|---|
| capture-completed | Order COMPLETED / capture COMPLETED | "paid" |
| capture-pending | Order COMPLETED / capture PENDING | "pending" |
| capture-declined | Order COMPLETED / capture DECLINED | "declined" |
| capture-unrecognized | Order COMPLETED / capture UNRECOGNIZED | "review" |
| wrong-amount | Capture USD 9.99; server expects USD 10.00 | "review" |
| wrong-currency | Capture EUR 10.00; server expects USD 10.00 | "review" |
| partial-capture | Final-capture flag false | "review" |
These reduced fixtures use invented IDs and no credentials. The declined case preserves the significant outer/inner status combination from the provider documentation. It must produce declined, never paid.
Handle transport and parsing errors separately
export async function readCaptureResponse(response, expected) {
if (!response.ok) return 'transport-error';
let order;
try { order = await response.json(); }
catch { return 'invalid-json'; }
return inspectCaptureOrder(order, expected);
}The function accepts a response-like object so tests can supply non-2xx and malformed JSON without making a request. A rejected fetch still needs handling by its caller. Do not display a successful purchase simply because onApprove ran or because an endpoint returned JSON.
For a real integration, follow PayPal’s Checkout integration instructions. Create and capture against server-owned order data. The browser may display the server’s current state, but it is not the authority for fulfillment. Keep cancellation distinct from decline: a closed approval dialog should leave the cart available for another attempt.
Pending, duplicate and delayed observations
test('Duplicate and delayed observations request fulfillment only once', () => {
let current = {state: 'new', captureId: null, review: false};
let fulfillments = 0;
for (const state of ['pending', 'paid', 'paid', 'pending']) {
current = reconcileCapture(current, {captureId: 'CAPTURE-EXAMPLE', state});
fulfillments += Number(current.fulfill);
}
assert.equal(fulfillments, 1);
assert.equal(current.state, 'paid');
assert.equal(current.review, false);
assert.equal(reconcileCapture(current, {captureId: 'CAPTURE-EXAMPLE', state: 'declined'}).review, true);
});The sequence pending → paid → paid → pending requests fulfillment once and retains paid. A conflicting terminal result or a different capture ID requires review. This is a pure model for a single capture, not a webhook signature verifier, refund processor or concurrent job system.
In production, verify the incoming webhook using the provider’s supported method, then reconcile the relevant order/capture with trusted state. PayPal documents both local cryptographic verification and API postback verification; simulator events have different verification constraints. See PayPal’s webhook integration guide.
Store processed event identifiers and the fulfillment transition durably. Use database uniqueness and a transaction or an equivalent durable workflow so two simultaneous deliveries cannot both dispatch goods. A process-local set or the sequential test above does not establish that guarantee. Refunds and disputes need their own state model; a late pending capture should not be mistaken for either.
Run the offline regression project
Extract the complete capture test project and use Node.js 22 or later:
node --test guide-examples.test.mjs
node guide-demo.mjs paypal
The tests cover the false-success regression, pending and unknown statuses, mismatched order/reference/amount/currency, multiple and partial captures, HTTP/JSON failures and replay. They make no payment requests. Passing them verifies this interpretation layer, not account configuration or an entire PayPal integration.
Then repeat relevant scenarios in the actual sandbox and record the provider response and your order state. Use the payment-form checklist for cancellation and recovery, and the Stripe test guide when comparing another provider. Braintree users should follow its separate testing reference instead of transplanting PayPal card triggers or unqualified amount tables.
The linked PayPal card-testing and webhook behavior were last checked against provider documentation on . Providers do change what they publish — the official link beside each claim is authoritative.