@samveys/payment
Midtrans and Xendit drivers on webhooks and http-client
import { midtrans, midtransStatus, xendit, xenditStatus } from '@samveys/payment'
Function (4)
midtrans
Function
The Midtrans driver: Snap checkout, the Status API, and signed HTTP notifications.
function midtrans(options: MidtransOptions): PaymentDriver;
Exported from packages/payment/src/midtrans.ts
midtransStatus
Function
Midtrans `transaction_status` (+ `fraud_status`) → normalised status, per the Midtrans "Transaction Status" table: capture with fraud `accept` and settlement are paid; `challenge` needs a manual review in the dashboard; deny, failure → failed.
function midtransStatus(transactionStatus: string, fraudStatus?: string): PaymentStatus;
Exported from packages/payment/src/midtrans.ts
xendit
Function
The Xendit driver on the Invoice API. Xendit does not sign callbacks: it sends a static `x-callback-token`, compared here in constant time, and `status()` re-reads the invoice so a leaked token alone cannot mark an order paid.
function xendit(options: XenditOptions): PaymentDriver;
Exported from packages/payment/src/xendit.ts
xenditStatus
Function
Xendit invoice status → normalised status.
function xenditStatus(status: string): PaymentStatus;
Exported from packages/payment/src/xendit.ts
Interface (7)
ChargeRequest
Interface
No documentation comment.
interface ChargeRequest {
/** Your order id; unique per payment attempt. */
readonly orderId: string;
/** Integer amount in IDR (must equal the sum of the items when items are given). */
readonly amount: number;
readonly currency?: 'IDR';
readonly customer?: {
readonly name?: string;
readonly email?: string;
readonly phone?: string;
…
Show the whole declaration (15 lines)
interface ChargeRequest {
/** Your order id; unique per payment attempt. */
readonly orderId: string;
/** Integer amount in IDR (must equal the sum of the items when items are given). */
readonly amount: number;
readonly currency?: 'IDR';
readonly customer?: {
readonly name?: string;
readonly email?: string;
readonly phone?: string;
…interface ChargeRequest {
/** Your order id; unique per payment attempt. */
readonly orderId: string;
/** Integer amount in IDR (must equal the sum of the items when items are given). */
readonly amount: number;
readonly currency?: 'IDR';
readonly customer?: {
readonly name?: string;
readonly email?: string;
readonly phone?: string;
};
readonly items?: readonly PaymentItem[];
/** Where the customer returns after paying. */
readonly returnUrl?: string;
}
Exported from packages/payment/src/contracts.ts
Checkout
Interface
No documentation comment.
interface Checkout {
readonly orderId: string;
/** The page the customer pays on. */
readonly redirectUrl: string;
/** Gateway token (Snap token, Xendit invoice id). */
readonly token: string;
}
Exported from packages/payment/src/contracts.ts
MidtransOptions
Interface
No documentation comment.
interface MidtransOptions {
/** `SB-Mid-server-…` in sandbox, `Mid-server-…` in production. */
readonly serverKey: string;
/** Default: sandbox when the key starts with `SB-`. */
readonly production?: boolean;
/** For tests and custom transports. */
readonly client?: HttpClient;
}
Exported from packages/payment/src/midtrans.ts
PaymentDriver
Interface
One gateway.
interface PaymentDriver {
readonly name: string;
/** Starts a payment and returns where to send the customer. */
checkout(request: ChargeRequest): Promise<Checkout>;
/** Asks the gateway for the current state (never trust a notification body alone). */
status(orderId: string): Promise<PaymentState>;
/**
* Verifies a notification (signature over the raw body) and returns the state it reports.
* Throws SVS_E108 when the signature is wrong.
*/
notification(rawBody: string, headers: Headers): Promise<PaymentState>;
}
Exported from packages/payment/src/contracts.ts
PaymentItem
Interface
No documentation comment.
interface PaymentItem {
readonly id: string;
readonly name: string;
/** Unit price in the smallest unit the gateway uses (IDR has no minor unit). */
readonly price: number;
readonly quantity: number;
}
Exported from packages/payment/src/contracts.ts
PaymentState
Interface
No documentation comment.
interface PaymentState {
readonly orderId: string;
readonly status: PaymentStatus;
readonly amount: number;
/** Gateway transaction id. */
readonly transactionId: string | undefined;
/** The gateway's own status text, for logs. */
readonly raw: string;
}
Exported from packages/payment/src/contracts.ts
XenditOptions
Interface
No documentation comment.
interface XenditOptions {
/** Secret API key (`xnd_development_…` / `xnd_production_…`). */
readonly secretKey: string;
/** The callback verification token from the Xendit dashboard (`x-callback-token`). */
readonly callbackToken: string;
readonly client?: HttpClient;
}
Exported from packages/payment/src/xendit.ts
Type (1)
PaymentStatus
Type
Normalised payment state across gateways.
type PaymentStatus = 'pending' | 'settled' | 'failed' | 'expired' | 'cancelled' | 'refunded' | 'challenge';
Exported from packages/payment/src/contracts.ts