Invoice Operations
Retrieve and pay outstanding invoices using the ResytechApi client.
Invoices represent outstanding balances on bookings -- for example, when a customer paid a deposit at checkout and owes a remaining balance. The invoice API lets you retrieve invoice details and process payments.
getInvoice
Retrieve invoice details including the amount due, associated cart summary, and booking information.
const result = await api.invoice.getInvoice('invoice-uuid');
if (result.success) {
console.log('Invoice:', result.invoice.uuid);
console.log('Due now:', result.invoice.dueNowCents, 'cents');
console.log('Activity:', result.activity);
console.log('Date:', result.date);
console.log('Time:', result.start, '-', result.end);
}Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
invoiceUuid | string | Yes | Invoice UUID |
GetInvoiceResponse
| Field | Type | Description |
|---|---|---|
success | boolean | Whether the request succeeded |
invoice | ServerInvoice | Invoice details |
cart | ServerShoppingCartOverview | Cart summary with line items, fees, and totals |
activity | string | Activity name |
date | string | Booking date |
start | string | Start time |
end | string | End time |
endDate | string | End date (for multi-day bookings) |
ServerInvoice
| Field | Type | Description |
|---|---|---|
uuid | string | Invoice unique identifier |
dueNowCents | number | Amount due in cents |
The cart field contains the full ServerShoppingCartOverview with all line items, fees, discounts, and payment history. See the Cart & Checkout page for the full type reference.
payInvoice
Pay an outstanding invoice. Like checkout, this requires a Stripe confirmation token and any required agreement acceptances.
const result = await api.invoice.payInvoice('invoice-uuid', {
stripeConfirmationToken: 'tok_xxx',
agreements: ['agreement-uuid-1']
});
if (result.success) {
console.log('Payment confirmed:', result.confirmation);
} else if (result.clientSecret) {
// Stripe requires additional action (3D Secure, etc.)
console.log('Additional verification needed');
}Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
invoiceUuid | string | Yes | Invoice UUID |
request | PayInvoiceRequest | Yes | Payment details |
PayInvoiceRequest
| Field | Type | Required | Description |
|---|---|---|---|
stripeConfirmationToken | string | No | Stripe confirmation token from Stripe.js |
agreements | string[] | No | UUIDs of accepted agreements |
handledNextAction | string | No | Stripe PaymentIntent ID after handling 3D Secure |
PayInvoiceResponse
| Field | Type | Description |
|---|---|---|
success | boolean | Whether payment succeeded |
confirmation | string | Payment confirmation number |
clientSecret | string | Stripe client secret (if additional action is required) |
Invoice Payment Flow
A typical invoice payment follows this sequence:
- Retrieve the invoice to display the amount due and booking details.
- Collect payment using Stripe Elements or your payment form.
- Submit payment with the Stripe token.
- Handle 3D Secure if the response includes a
clientSecretinstead of aconfirmation.
getInvoice(uuid)
|
v
Display amount, booking details
|
v
Collect Stripe payment token
|
v
payInvoice(uuid, { stripeConfirmationToken })
|
+---> success + confirmation --> Done
|
+---> clientSecret returned --> Handle 3D Secure with Stripe.js
|
v
payInvoice(uuid, { handledNextAction: paymentIntentId })
|
v
success + confirmation --> DoneFull Example
const api = new ResytechApi();
await api.initialization.initialize({ identifier: 'invoice-payment' });
// Invoice UUID typically comes from an email link or dashboard
const invoiceUuid = 'inv-abc-123';
// 1. Load invoice details
const invoiceResult = await api.invoice.getInvoice(invoiceUuid);
if (!invoiceResult.success) {
console.error('Invoice not found:', invoiceResult.message);
return;
}
const { invoice, cart, activity, date, start, end } = invoiceResult;
// Display to customer
console.log(`Invoice for: ${activity}`);
console.log(`Booking: ${date} ${start} - ${end}`);
console.log(`Amount due: $${(invoice.dueNowCents / 100).toFixed(2)}`);
if (cart) {
console.log('Line items:');
cart.lineItems?.forEach(item => {
console.log(` ${item.name}: $${item.price}`);
});
console.log('Fees:');
cart.fees?.forEach(fee => {
console.log(` ${fee.name}: $${fee.amount}`);
});
}
// 2. Collect payment via Stripe.js (in your UI)
// const { token } = await stripe.createToken(cardElement);
// 3. Pay the invoice
const payResult = await api.invoice.payInvoice(invoiceUuid, {
stripeConfirmationToken: 'tok_from_stripe_js',
agreements: [] // include any required agreement UUIDs
});
if (payResult.success) {
console.log('Payment complete! Confirmation:', payResult.confirmation);
} else if (payResult.clientSecret) {
// 4. Handle 3D Secure
// const { paymentIntent } = await stripe.handleNextAction({
// clientSecret: payResult.clientSecret
// });
// 5. Retry with handled action
const retryResult = await api.invoice.payInvoice(invoiceUuid, {
handledNextAction: 'pi_payment_intent_id'
});
if (retryResult.success) {
console.log('Payment verified! Confirmation:', retryResult.confirmation);
} else {
console.error('Payment failed:', retryResult.message);
}
} else {
console.error('Payment failed:', payResult.message);
}