@samveys/payment

Driver Midtrans dan Xendit di atas webhooks dan http-client

Versi
1.0.35 Nov 2026
Pasang
pnpm add @samveys/payment
Dokumentasi
README paket ini

Daftar ini dibaca dari versi 1.0.2; jalankan pnpm sync untuk memperbaruinya.

Import
import { midtrans, midtransStatus, xendit, xenditStatus } from '@samveys/payment'

Fungsi (4)

midtrans Fungsi

The Midtrans driver: Snap checkout, the Status API, and signed HTTP notifications.

function midtrans(options: MidtransOptions): PaymentDriver;

Diekspor dari packages/payment/src/midtrans.ts

midtransStatus Fungsi

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;

Diekspor dari packages/payment/src/midtrans.ts

xendit Fungsi

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;

Diekspor dari packages/payment/src/xendit.ts

xenditStatus Fungsi

Xendit invoice status → normalised status.

function xenditStatus(status: string): PaymentStatus;

Diekspor dari packages/payment/src/xendit.ts

Interface (7)

ChargeRequest Interface

Tidak ada komentar dokumentasi.

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;
  …
Tampilkan seluruh deklarasi (15 baris)
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;
}

Diekspor dari packages/payment/src/contracts.ts

Checkout Interface

Tidak ada komentar dokumentasi.

interface Checkout {
    readonly orderId: string;
    /** The page the customer pays on. */
    readonly redirectUrl: string;
    /** Gateway token (Snap token, Xendit invoice id). */
    readonly token: string;
}

Diekspor dari packages/payment/src/contracts.ts

MidtransOptions Interface

Tidak ada komentar dokumentasi.

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;
}

Diekspor dari 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>;
}

Diekspor dari packages/payment/src/contracts.ts

PaymentItem Interface

Tidak ada komentar dokumentasi.

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;
}

Diekspor dari packages/payment/src/contracts.ts

PaymentState Interface

Tidak ada komentar dokumentasi.

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;
}

Diekspor dari packages/payment/src/contracts.ts

XenditOptions Interface

Tidak ada komentar dokumentasi.

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;
}

Diekspor dari packages/payment/src/xendit.ts

Tipe (1)

PaymentStatus Tipe

Normalised payment state across gateways.

type PaymentStatus = 'pending' | 'settled' | 'failed' | 'expired' | 'cancelled' | 'refunded' | 'challenge';

Diekspor dari packages/payment/src/contracts.ts