Payments
QZPay supports one-time payments, subscription charges, and refunds.
One-Time Payments
Basic Payment
const payment = await billing.payments.process({
amount: 9900, // Amount in cents
paymentMethodId: 'pm_card_visa'
const payment = await billing.payments.process({
paymentMethodId: 'pm_card_visa',
Payment Status
| Status | Description |
|---|
pending | Payment initiated, awaiting processing |
processing | Being processed by provider |
succeeded | Payment completed successfully |
failed | Payment failed |
cancelled | Payment was cancelled |
refunded | Fully refunded |
partially_refunded | Partially refunded |
Refunds
Full Refund
const refund = await billing.payments.refund({
Partial Refund
const refund = await billing.payments.refund({
amount: 2500, // Refund $25.00
reason: 'customer_request'
Payment Object
paymentMethodId?: string;
metadata: Record<string, string>;
externalIds: Record<string, string>;
Events
| Event | Description |
|---|
payment.succeeded | Payment completed successfully |
payment.failed | Payment failed |
payment.refunded | Payment was refunded |
billing.on('payment.succeeded', async (event) => {
const { customerId, amount } = event.data;
await sendReceipt(customerId, amount);
billing.on('payment.failed', async (event) => {
await notifyPaymentFailure(event.data.customerId);
Error Handling
import { PaymentFailedError, CardDeclinedError } from '@qazuor/qzpay-core';
await billing.payments.process({ ... });
if (error instanceof CardDeclinedError) {
// Ask customer to use different card
} else if (error instanceof PaymentFailedError) {
// Generic payment failure
Best Practices
- Always use idempotency keys for payment creation
- Store payment references in your order/transaction records
- Handle webhooks for payment status updates
- Implement retry logic for failed payments
- Log all payment events for audit purposes