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.
job_orderorder description contains Admin training; total 300.00; currency USD; after start true
returned_paymentpayment order $kestrel_training; status PARTIALLY_REFUNDED; amount 300.00; refunded 200.00
invoice_sentinvoice 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_URLPAYPAL_CLIENT_IDPAYPAL_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
/v1/billing/plans/v1/billing/plans/v1/billing/plans/:id/v1/billing/plans/:id/activate/v1/billing/plans/:id/deactivate/v1/billing/subscriptions/v1/billing/subscriptions/v1/billing/subscriptions/:id/v1/billing/subscriptions/:id/v1/billing/subscriptions/:id/activate/v1/billing/subscriptions/:id/cancel/v1/billing/subscriptions/:id/capture/v1/billing/subscriptions/:id/revise/v1/billing/subscriptions/:id/suspend/v1/billing/subscriptions/:id/transactionscatalogs
/v1/catalogs/products/v1/catalogs/products/:idcheckout
/v2/checkout/orders/v2/checkout/orders/:id/v2/checkout/orders/:id/v2/checkout/orders/:id/authorize/v2/checkout/orders/:id/capture/v2/checkout/orders/:id/confirm-payment-source/v2/checkout/orders/:id/track/v2/checkout/orders/:id/trackers/:trackerinvoicing
/v2/invoicing/invoices/v2/invoicing/invoices/v2/invoicing/invoices/:id/v2/invoicing/invoices/:id/sendoauth2
/v1/oauth2/tokenpayments
/v2/payments/authorizations/:id/v2/payments/authorizations/:id/capture/v2/payments/authorizations/:id/reauthorize/v2/payments/authorizations/:id/void/v2/payments/captures/:id/v2/payments/captures/:id/refund/v2/payments/refunds/:idreporting
/v1/reporting/balances/v1/reporting/transactionsSeed 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: trueMore payments and commerce tools
All 43 toolsPayPal API mock FAQ
What happens when a payment agent captures an unapproved PayPal order?
For a CAPTURE order awaiting approval, the mock’s POST / 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.
Ancha is not affiliated with PayPal.