npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@bayar-sdk/midtrans

v0.0.1

Published

Midtrans provider adapter for bayar-sdk — create charges, check status, refund and verify webhooks for Midtrans Core API (bank transfer, virtual account, QRIS, GoPay, e-wallet, credit card).

Readme

@bayar-sdk/midtrans

Adapter Midtrans (Core API v1/v2) untuk @bayar-sdk/core. Provider ini mengikuti contract PaymentProvider dan lolos runProviderContractTests().

Instalasi

bun add @bayar-sdk/core @bayar-sdk/midtrans

Quick start

import { MidtransProvider } from "@bayar-sdk/midtrans";
import type { ChargeRequest, RefundRequest } from "@bayar-sdk/core";

const provider = new MidtransProvider({
	serverKey: "server-key-anda",
	httpClient: { fetch }, // inject httpClient agar mudah di-mock/test
	environment: "sandbox", // atau "production" (default: sandbox)
});

const req: ChargeRequest = {
	amount: 50000, // integer minor unit (Rp50.000)
	currency: "IDR",
	paymentMethod: { type: "virtual_account", bank: "bca" },
	referenceId: "order-123",
};

const result = await provider.createCharge(req, {
	idempotencyKey: "idem-001", // wajib
});
console.log(result.chargeId, result.actions);

Cek status charge

const charge = await provider.getCharge(result.chargeId);
console.log(charge.normalizedStatus); // "pending" | "paid" | ...

Refund (full & partial)

const refundReq: RefundRequest = {
	chargeId: result.chargeId,
	// amount: 50000, // opsional — isi untuk partial refund
};

const refund = await provider.refund(refundReq, {
	idempotencyKey: "idem-refund-001", // wajib
});
console.log(refund.refundId, refund.normalizedStatus);

Refund hanya diizinkan saat charge berstatus paid; selain itu provider melempar PaymentSDKError dengan kode REFUND_NOT_ALLOWED.

Webhook

// Contoh handler Hono:
app.post("/webhook/midtrans", async (c) => {
	const event = await provider.parseWebhook(await c.req.json(), c.req.raw.headers);
	// Signature SHA512 sudah diverifikasi sebelum event dikembalikan.
	console.log(event.normalizedStatus);
	return c.text("ok");
});

Metode pembayaran yang didukung (v1)

| Metode SDK | payment_type Midtrans | | --------------------- | ----------------------- | | virtual_account | bank_transfer | | qris | qris | | wallet (GoPay) | gopay | | card (token-based) | credit_card |

Bank virtual account yang didukung: bca, bni, bri, permata, mandiri, cimb, danamon, bsi, seabank, saqu (input dinormalisasi ke lowercase; bank lain melempar INVALID_REQUEST).

Keterbatasan

  • Card menerima token hasil snap/3DS — raw card data (PAN/CVV) tidak pernah diproses di repo ini.
  • capturePayment() tidak didukung (Midtrans Core API memisahkan capture hanya untuk card authorize) — melempar CAPTURE_NOT_SUPPORTED.
  • Idempotency dikelola in-memory per instance provider — untuk multi-instance, integrasikan dengan storage eksternal (di luar scope v1).
  • Semua amount dalam integer minor unit (IDR); string gross_amount Midtrans di-parse tanpa parseFloat.