A PayPal API mock for orders, refunds and invoices.

Your agent creates a new Admin training order, refunds another $100 of the seeded training payment and sends an invoice. Check the new order, the payment’s $200 cumulative refund and the sent invoice’s total and tax.

Connect your agent
The test
  • job_order

    order description contains Admin training; total 300.00; currency USD; after start true

  • returned_payment

    payment order $kestrel_training; status PARTIALLY_REFUNDED; amount 300.00; refunded 200.00

  • invoice_sent

    invoice recipient buyer@example.test; sent true; total 276.60; tax 84.60; after start true

Starting records

  • orders

    ref
    kestrel_training
    description
    Admin training
  • orders / kestrel_training / items

    name
    Admin training session
    quantity
    2

Connect your agent to the PayPal mock

When ancha runs your agent, it sets:

  • PAYPAL_API_URL
  • PAYPAL_CLIENT_ID
  • PAYPAL_CLIENT_SECRET

Point the client you already use at them.

import { Client, Environment, SubscriptionsController } from '@paypal/paypal-server-sdk';
const paypal = new Client({
  clientCredentialsAuthCredentials: { oAuthClientId: process.env.PAYPAL_CLIENT_ID!, oAuthClientSecret: process.env.PAYPAL_CLIENT_SECRET! },
  environment: Environment.Sandbox,
  unstable_httpClientOptions: { adapter: async (config: any) => {
    const headers: Record<string, string> = Object.fromEntries(Object.entries(config.headers.toJSON()).map(([k, v]) => [k, String(v)]));
    if (config.auth) headers.authorization = 'Basic ' + Buffer.from(config.auth.username + ':' + config.auth.password).toString('base64');
    const res = await fetch(String(config.url).replace(/^https:\/\/[^/]+/, process.env.PAYPAL_API_URL!), { method: config.method.toUpperCase(), headers, body: config.data });
    return { data: await res.text(), status: res.status, statusText: res.statusText, headers: Object.fromEntries(res.headers), config, request: {} };
  } },
});
const { result } = await new SubscriptionsController(paypal).listSubscriptions({ statuses: 'ACTIVE' });

Locally, ancha runs your agent as an ordinary process, so keep real PayPal credentials out of its environment.

See all 39 endpoints

billing

GET/v1/billing/plans
POST/v1/billing/plans
GET/v1/billing/plans/:id
POST/v1/billing/plans/:id/activate
POST/v1/billing/plans/:id/deactivate
GET/v1/billing/subscriptions
POST/v1/billing/subscriptions
GET/v1/billing/subscriptions/:id
PATCH/v1/billing/subscriptions/:id
POST/v1/billing/subscriptions/:id/activate
POST/v1/billing/subscriptions/:id/cancel
POST/v1/billing/subscriptions/:id/capture
POST/v1/billing/subscriptions/:id/revise
POST/v1/billing/subscriptions/:id/suspend
GET/v1/billing/subscriptions/:id/transactions

catalogs

GET/v1/catalogs/products
GET/v1/catalogs/products/:id

checkout

POST/v2/checkout/orders
GET/v2/checkout/orders/:id
PATCH/v2/checkout/orders/:id
POST/v2/checkout/orders/:id/authorize
POST/v2/checkout/orders/:id/capture
POST/v2/checkout/orders/:id/confirm-payment-source
POST/v2/checkout/orders/:id/track
PATCH/v2/checkout/orders/:id/trackers/:tracker

invoicing

GET/v2/invoicing/invoices
POST/v2/invoicing/invoices
GET/v2/invoicing/invoices/:id
POST/v2/invoicing/invoices/:id/send

oauth2

POST/v1/oauth2/token

payments

GET/v2/payments/authorizations/:id
POST/v2/payments/authorizations/:id/capture
POST/v2/payments/authorizations/:id/reauthorize
POST/v2/payments/authorizations/:id/void
GET/v2/payments/captures/:id
POST/v2/payments/captures/:id/refund
GET/v2/payments/refunds/:id

reporting

GET/v1/reporting/balances
GET/v1/reporting/transactions

Seed your own data

The data the PayPal mock starts with on every run, cut to a few records. ancha twins seed paypal prints every field.

Full seed YAML
twins:
  - paypal
seed:
  paypal:
    account:
      business_name: Acme Inc.
      email: billing@acme.example
      opening_balance: "18240.00"
    products:
      - ref: analytics
        name: Acme Analytics
        description: Warehouse analytics, dashboards and scheduled reports
        created: -6000h
    plans:
      - ref: team_monthly
        product: analytics
        name: Team (monthly)
        description: Per seat, billed monthly
        price: "49.00"
        quantity_supported: true
        created: -6000h
    subscriptions:
      - ref: lakeview
        plan: team_monthly
        subscriber:
          first_name: Isabel
          last_name: Cruz
          email: isabel.cruz@lakeview-retail.example
        quantity: 5
        started: -2200h
        custom_id: acme-ws-lakeview
    orders:
      - ref: kestrel_training
        payer:
          first_name: Carla
          last_name: Diaz
          email: carla.diaz@kestrel-cu.example
        description: Admin training
        invoice_id: ACME-2026-0417
        items:
          - name: Admin training session
            quantity: 2
            unit_amount: "150.00"
            sku: SVC-TRAIN
        created: -60h
        refunds:
          - at: -40h
            amount: "100.00"
            note: One session cancelled

Check what your agent did

Checks YAML
checks:
  - id: job_order
    state:
      paypal.order:
        description_contains: Admin training
        total: "300.00"
        currency: USD
        after_start: true
  - id: returned_payment
    state:
      paypal.payment:
        order: $kestrel_training
        status: PARTIALLY_REFUNDED
        amount: "300.00"
        refunded: "200.00"
  - id: invoice_sent
    state:
      paypal.invoice:
        recipient: buyer@example.test
        sent: true
        total: "276.60"
        tax: "84.60"
        after_start: true

More payments and commerce tools

All 43 tools

PayPal API mock FAQ

What happens when a payment agent captures an unapproved PayPal order?

For a CAPTURE order awaiting approval, the mock’s POST /v2/checkout/orders/:id/capture returns 422 with UNPROCESSABLE_ENTITY and issue ORDER_NOT_APPROVED. Capturing an APPROVED order creates its captures and changes its status to COMPLETED.

How does the PayPal mock handle a retried capture request?

Repeat the capture request for the same order with the same PayPal-Request-Id. The mock returns the saved status and response body from the first successful request.

Can a billing-agent test catch a PayPal refund larger than the remaining payment?

For a capture still within its refund window and with money left to refund, the mock subtracts earlier refunds before checking the requested amount. An amount above that balance returns 422 with issue REFUND_AMOUNT_EXCEEDED; a fully refunded capture returns issue CAPTURE_FULLY_REFUNDED.

Install the CLI and run your agent against the PayPal mock.

Book a demo

Ancha is not affiliated with PayPal.