Accept payments
External Transactions
Record payments you took on other services so every report, balance and webhook includes them.
Overview
Some payments never pass through PaymentHooks: a sale on another gateway, PayPal, a bank transfer, cash at the counter, or a marketplace payout. Record each one with POST /api/v1/external-transactions and it becomes a Payment (id prefix ph_pay_) with source: "external". It then appears in Payments and Transactions with an External badge, and counts in revenue, analytics, reports, the customer's spend, invoices and your outgoing webhooks, exactly like a gateway payment.
Recording moves no money. Gateway-only actions (capture, a gateway refund) are not available for these payments: refunds are made on the other service and recorded here. Recorded payments are never part of gateway health, success rates or routing.
Authentication
Use a secret API key with the payments:write scope to record, update, void and refund; payments:read to list and retrieve. Send it as Authorization: Bearer <secret key>. Keep the key on a server or in your automation tool's secret store, never in a browser or a mobile app.
Call it from another service
Other services do not send PaymentHooks' JSON on their own. Put a small step between them: your own webhook receiver, or an automation tool (any workflow tool with an HTTP request step). It receives the other service's event, verifies it the way that service documents, translates the fields and calls the API with your secret key. Use that service's transaction id as externalTransactionId: its retries then never create duplicates.
import express from "express";
import { PaymentHooks } from "@paymenthooks/sdk";
const ph = new PaymentHooks({ apiKey: process.env.PAYMENTHOOKS_SECRET_KEY! });
const app = express();
// The other service's webhook. Verify its signature with that service's own
// method first (verifyProviderSignature is yours to implement); never log
// headers, secrets or the raw body.
app.post("/hooks/provider", express.raw({ type: "application/json" }), async (req, res) => {
if (!verifyProviderSignature(req)) return res.sendStatus(400);
const event = JSON.parse(req.body.toString("utf8"));
if (event.type !== "payment.completed") return res.sendStatus(204);
try {
const txn = await ph.externalTransactions.create({
externalProvider: "provider_x",
externalTransactionId: event.data.id, // their id: retries are safe
transactionLocalCurrency: event.data.currency,
transactionLocalCurrencyAmount: event.data.amount_minor,
customerEmail: event.data.payer_email,
occurredAt: event.data.completed_at,
});
console.info("recorded", { id: txn.id, status: txn.status }); // ids only
res.sendStatus(200);
} catch (err) {
// A 409 means the same id was sent with a different amount: investigate, do not retry.
console.error("record failed", { code: (err as { code?: string }).code });
res.sendStatus(500); // the provider retries; a replay is answered with the same record
}
});POST https://paymenthooks.com/api/v1/external-transactions
Authorization: Bearer {{PAYMENTHOOKS_SECRET_KEY}}
Content-Type: application/json
{
"externalProvider": "bank_transfer",
"externalTransactionId": "{{statement.reference}}",
"transactionLocalCurrency": "{{statement.currency}}",
"transactionLocalCurrencyAmount": {{statement.amount_minor_units}},
"customerEmail": "{{statement.payer_email}}",
"occurredAt": "{{statement.booked_at}}",
"invoiceId": "{{statement.invoice_id}}"
}Record a payment
curl -X POST https://paymenthooks.com/api/v1/external-transactions \
-H "Authorization: Bearer $PAYMENTHOOKS_SECRET_KEY" \
-H "Content-Type: application/json" \
-d '{ "externalProvider": "paypal", "externalTransactionId": "5TY05013RG002845M", "transactionLocalCurrency": "EUR", "transactionLocalCurrencyAmount": 4900, "customerEmail": "[email protected]", "customerName": "Jamie Rivera", "paymentMethod": "wallet", "description": "Order 1042", "occurredAt": "2026-11-12T09:30:00Z", "metadata": { "orderId": "1042" } }'Parameters
| Field | Type | Description |
|---|---|---|
externalProvider | string | The service that took the payment, e.g. paypal, bank_transfer, cash, marketplace_x. Lower-cased; spaces and dashes become _ (1-64 characters). |
externalTransactionId | string | That service's own id for the transaction (1-255 printable characters, no spaces). With externalProvider it identifies the record: sending it again never records the payment twice. |
transactionLocalCurrency | string | ISO 4217 currency the money moved in, e.g. EUR. Must be a currency with a live USD rate. |
transactionLocalCurrencyAmount | integer | Amount in the smallest unit of transactionLocalCurrency (cents, paise; whole yen). Positive integer. |
transactionUsdToLocalCurrencyRate | number | 1 USD = X transactionLocalCurrency, the rate the other service used. Omit to use the live rate. Must be 1 (or omitted) for USD. |
status | "succeeded" | "pending" | "failed"Default: | pending for money not yet settled (e.g. a bank transfer announced but not received); settle it later with PATCH. |
customerId | string | One of your customers. Send customerId or customerEmail, not both. |
customerEmail | string | The buyer's email: the existing customer with that email, else a new customer is created. |
customerName | string | Name for a customer created from customerEmail. |
paymentMethod | stringDefault: | card, bank_transfer, upi, wallet, bnpl, crypto, cash, check or other. |
description | string | Up to 500 characters. |
metadata | object | Up to 50 string key-value pairs (keys up to 40 characters, values up to 500). |
occurredAt | string | ISO 8601 date-time with offset: when the payment happened on the other service. Default now. Not in the future, not more than 5 years ago. Every date filter, report and chart uses it. |
invoiceId | string | One of your open invoices this payment pays. Its currency and total must equal the payment's; the invoice becomes paid and invoice.paid is sent. Without a customer field, the invoice's customer is used. |
businessEntityId | string | One of your businesses. A key scoped to a business always records for that business. |
sendReceipt | booleanDefault: | Email the customer the PaymentHooks receipt. Off by default: the other service usually sent its own. |
| Field | Type | Description |
|---|---|---|
description | string | null | Replace or clear the description. |
metadata | object | Merged into the existing metadata; a null or empty value removes the key. |
status | "succeeded" | "failed" | Only for a pending record: the other service settled it. |
customerId / customerEmail / customerName | string | Only while pending: correct the customer. |
sendReceipt | boolean | With status: "succeeded": email the customer the receipt. |
| Field | Type | Description |
|---|---|---|
externalRefundId | string | The other service's refund id. Sending it again returns the recorded refund. |
transactionLocalCurrencyAmount | integer | Refunded amount in the payment's transactionLocalCurrency, smallest unit. At most transactionRefundableLocalCurrencyAmount. |
reason | string | Up to 500 characters. |
notifyCustomer | booleanDefault: | Email the customer a refund confirmation. |
Duplicates & idempotency
externalProvider+externalTransactionIdidentify a record in your account. Sending the same pair again returns200with the existing record and the headerX-Idempotent-Replayed: true; nothing is recorded twice and no webhook is sent again.- The same pair with a different amount, currency, rate, customer, status or invoice returns
409 EXTERNAL_TRANSACTION_CONFLICTnaming the field. Settle a pending record with PATCH instead of sending it again. - The standard
Idempotency-Keyheader is honoured as well. - Refunds are idempotent per
externalRefundIdon the same payment.
Endpoints & Responses
/v1/external-transactionsRecord a payment taken on another service. 201 Created; a repeat of the same externalProvider + externalTransactionId returns 200 with the existing record and X-Idempotent-Replayed: true. Scope: payments:write.{
"externalProvider": "paypal",
"externalTransactionId": "5TY05013RG002845M",
"transactionLocalCurrency": "EUR",
"transactionLocalCurrencyAmount": 4900,
"customerEmail": "[email protected]",
"customerName": "Jamie Rivera",
"paymentMethod": "wallet",
"description": "Order 1042",
"occurredAt": "2026-11-12T09:30:00Z",
"metadata": { "orderId": "1042" }
}{
"data": {
"id": "ph_pay_7c2e9a1f4b8d4e6aa0c3f1d2b5e7a9c4",
"object": "external_transaction",
"source": "external",
"externalProvider": "paypal",
"externalTransactionId": "5TY05013RG002845M",
"status": "succeeded",
"transactionLocalCurrency": "EUR",
"transactionLocalCurrencyAmount": 4900,
"transactionAmountUsdCents": 5326,
"transactionUsdToLocalCurrencyRate": 0.92,
"transactionRefundedAmountUsdCents": 0,
"transactionRefundableLocalCurrencyAmount": 4900,
"customerId": "ph_cus_1f0e3dad99908345f7439f8ffabdffc4",
"invoiceId": null,
"businessEntityId": null,
"paymentMethod": "wallet",
"description": "Order 1042",
"metadata": { "orderId": "1042" },
"occurredAt": "2026-11-12T09:30:00.000Z",
"recordedAt": "2026-11-13T08:02:11.417Z",
"updatedAt": "2026-11-13T08:02:11.417Z",
"canceledAt": null,
"refunds": []
},
"error": null,
"livemode": true
}/v1/external-transactions?externalProvider=paypal&status=succeeded&dateFrom=2026-11-01List recorded external transactions, newest occurredAt first. Filters: externalProvider, status (succeeded, pending, failed, canceled, refunded), customerId, businessEntityId, dateFrom and dateTo (YYYY-MM-DD, on occurredAt), page, pageSize (max 100). Scope: payments:read.{
"data": [ {
"id": "ph_pay_7c2e9a1f4b8d4e6aa0c3f1d2b5e7a9c4",
"object": "external_transaction",
"source": "external",
"externalProvider": "paypal",
"externalTransactionId": "5TY05013RG002845M",
"status": "succeeded",
"transactionLocalCurrency": "EUR",
"transactionLocalCurrencyAmount": 4900,
"transactionAmountUsdCents": 5326,
"transactionUsdToLocalCurrencyRate": 0.92,
"transactionRefundedAmountUsdCents": 0,
"transactionRefundableLocalCurrencyAmount": 4900,
"customerId": "ph_cus_1f0e3dad99908345f7439f8ffabdffc4",
"invoiceId": null,
"businessEntityId": null,
"paymentMethod": "wallet",
"description": "Order 1042",
"metadata": { "orderId": "1042" },
"occurredAt": "2026-11-12T09:30:00.000Z",
"recordedAt": "2026-11-13T08:02:11.417Z",
"updatedAt": "2026-11-13T08:02:11.417Z",
"canceledAt": null,
"refunds": []
} ],
"meta": { "total": 1, "page": 1, "pageSize": 25 },
"error": null,
"livemode": true
}/v1/external-transactions/:idRetrieve one record, with its refunds. A gateway payment's id or another account's id is 404. Scope: payments:read.{
"data": {
"id": "ph_pay_7c2e9a1f4b8d4e6aa0c3f1d2b5e7a9c4",
"object": "external_transaction",
"source": "external",
"externalProvider": "paypal",
"externalTransactionId": "5TY05013RG002845M",
"status": "succeeded",
"transactionLocalCurrency": "EUR",
"transactionLocalCurrencyAmount": 4900,
"transactionAmountUsdCents": 5326,
"transactionUsdToLocalCurrencyRate": 0.92,
"transactionRefundedAmountUsdCents": 0,
"transactionRefundableLocalCurrencyAmount": 4900,
"customerId": "ph_cus_1f0e3dad99908345f7439f8ffabdffc4",
"invoiceId": null,
"businessEntityId": null,
"paymentMethod": "wallet",
"description": "Order 1042",
"metadata": { "orderId": "1042" },
"occurredAt": "2026-11-12T09:30:00.000Z",
"recordedAt": "2026-11-13T08:02:11.417Z",
"updatedAt": "2026-11-13T08:02:11.417Z",
"canceledAt": null,
"refunds": []
},
"error": null,
"livemode": true
}/v1/external-transactions/:idUpdate description and metadata; settle a pending record (status succeeded or failed); correct the customer while pending. Amount, currency, provider, externalTransactionId and occurredAt are immutable (422 EXTERNAL_TRANSACTION_IMMUTABLE). Scope: payments:write.{ "status": "succeeded", "metadata": { "settledBy": "bank-feed" } }{
"data": { "id": "ph_pay_7c2e9a1f4b8d4e6aa0c3f1d2b5e7a9c4", "object": "external_transaction", "status": "succeeded", "metadata": { "settledBy": "bank-feed" } },
"error": null,
"livemode": true
}/v1/external-transactions/:id?reason=entered%20twiceVoid a record (status canceled). It stays readable but no longer counts as revenue, spend or a transaction. Voiding a voided record returns it unchanged. Scope: payments:write.{
"data": { "id": "ph_pay_7c2e9a1f4b8d4e6aa0c3f1d2b5e7a9c4", "object": "external_transaction", "status": "canceled", "canceledAt": "2026-11-13T10:15:02.118Z" },
"error": null,
"livemode": true
}/v1/external-transactions/:id/refundsRecord a refund made on the other service; no money is moved by PaymentHooks. 201 Created; a repeat of the same externalRefundId returns 200 with X-Idempotent-Replayed: true. Returns the record plus refund. Scope: payments:write.{ "externalRefundId": "8MC585209K746392H", "transactionLocalCurrencyAmount": 1000, "reason": "Partial return" }{
"data": {
"id": "ph_pay_7c2e9a1f4b8d4e6aa0c3f1d2b5e7a9c4",
"status": "succeeded",
"transactionRefundedAmountUsdCents": 1087,
"transactionRefundableLocalCurrencyAmount": 3900,
"refund": {
"id": "ph_rfd_3a9e7c1d5b2f8e4a6c0d9b3f7e1a5c8d",
"externalRefundId": "8MC585209K746392H",
"status": "processed",
"transactionLocalCurrency": "EUR",
"transactionLocalCurrencyAmount": 1000,
"transactionAmountUsdCents": 1087,
"transactionUsdToLocalCurrencyRate": 0.92,
"reason": "Partial return",
"createdAt": "2026-11-13T10:02:44.000Z"
}
},
"error": null,
"livemode": true
}Status lifecycle
pendingRecorded, not settled on the other service. Not revenue. PATCH status succeeded or failed.succeededMoney received. Counts in revenue, customer spend, reports and the monthly transactions of your plan.failedThe other service reported a failure. Not revenue.refundedFully refunded through recorded refunds. A partial refund keeps succeeded.canceledVoided with DELETE. Stays readable; counts nowhere.A pending record can become succeeded or failed once (PATCH). Amount, currency, provider, externalTransactionId and occurredAtnever change; void a wrong record and record it again. Succeeded and pending records count toward your plan's monthly transactions like gateway payments.
Refunds
Refund the customer on the other service, then record it with POST /v1/external-transactions/:id/refunds. Partial refunds keep the status succeeded; when the refunds reach the full amount the status becomes refunded. Refunded amounts leave revenue and customer spend. POST /v1/payments/:id/refund refuses these payments with 422 EXTERNAL_PAYMENT_REFUND, because PaymentHooks cannot return money it did not take.
Voiding
DELETE /v1/external-transactions/:id voids a record entered by mistake: its status becomes canceled, it drops out of revenue, spend and reports, and stays readable for your audit trail (the void is in your account's activity log). A record with recorded refunds, or one that paid an invoice, cannot be voided: record a refund or issue a credit note instead.
Webhooks sent
Recorded payments send the same Stripe-shaped payment_intent events as gateway payments, with two extra fields on data.object: payment_source ("external") and external_provider. Gateway payments carry payment_source: "gateway".
| Event | When |
|---|---|
| payment.created | Every new record. data.object.payment_source is "external" and external_provider names the service. |
| payment.succeeded | A succeeded record (on create, or when a pending one is settled). |
| payment.failed | A failed record, or a voided one (status canceled, cancellation_reason "void"). |
| payment.refunded | Every recorded refund; charges.data[0].amount_refunded is the refunded total in the payment's currency. |
| invoice.paid | When the record pays one of your invoices. |
Errors
| Code | HTTP | Meaning |
|---|---|---|
| VALIDATION_ERROR | 400 | A field is missing or invalid; error.fields names it. Unknown fields are refused. |
| NOT_FOUND | 404 | The record, customer or invoice does not exist in your account. |
| EXTERNAL_TRANSACTION_CONFLICT | 409 | This externalProvider + externalTransactionId (or externalRefundId) is already recorded with a different amount, currency, customer, status or invoice. |
| EXTERNAL_TRANSACTION_IMMUTABLE | 422 | PATCH tried to change a field fixed at creation. |
| EXTERNAL_INVOICE_MISMATCH | 422 | invoiceId is in another currency, due another amount, or belongs to another customer. |
| INVALID_STATE | 422 | Not allowed now: settling a non-pending record, refunding a non-succeeded one, voiding one with refunds or a paid invoice, or the invoice is already paid or void. |
| EXCEEDS_REFUNDABLE | 400 | The refund is larger than what is left. |
| PLAN_LIMIT_REACHED | 403 | Your plan's monthly transactions are used up (succeeded and pending records count, like gateway payments). |
| RATE_UNAVAILABLE | 503 | No live USD rate for the currency right now; send transactionUsdToLocalCurrencyRate or retry. |
| EXTERNAL_PAYMENT_REFUND | 422 | Returned by POST /v1/payments/:id/refund for a recorded external payment: refund it on the other service and record the refund here. |