@bayarkit/bayarcash
v0.3.3
Published
Bayarcash for Node.js and TypeScript: create payments, verify callbacks and confirm each payment with a fresh status query. Zero dependencies, part of bayarkit.
Downloads
764
Maintainers
Readme
@bayarkit/bayarcash
Bayarcash (also behind BCL.my) for bayarkit: one interface for Malaysian payment gateways, and a checked way to confirm a payment. Bahasa Melayu
Evidence: Measured on the sandbox, 27 Oct 2026: a paid and a failed FPX payment through the adapter (return URL, status query, portal); the server-to-server callback was not observed.
npm install @bayarkit/core @bayarkit/bayarcashimport { checkoutResponse, confirmPayment, readCallback } from '@bayarkit/core'
import { bayarcash } from '@bayarkit/bayarcash'
const gateway = bayarcash({ token, secretKey, portalKey, environment: 'sandbox' })
// Checkout: one reference per attempt; amounts are integer sen (RM10.50 = 1050).
const payment = await gateway.createPayment({ reference, amount, description, customer, returnUrl, callbackUrl })
return checkoutResponse(payment) // a 303 redirect, or a self-submitting form when the gateway wants a POST
// Callback route: never mark an order paid from the callback body or the return URL alone.
const result = await confirmPayment(gateway, await readCallback(request), { reference, amount })
if (result.ok) {
// mark the order paid (idempotently: gateways retry callbacks)
}Test without real money: startFakeBayarcash from @bayarkit/testing answers like this gateway (signed callbacks
included), and npx bayarkit-fake bayarcash runs it as a server for tests in other languages.
Traps
- The API secret key is account-wide: a correctly signed return or callback can belong to another portal in the same account. A transaction names its portal by NAME (
portal), so give every portal a unique name; the adapter compares it with the configured portal key's name. (gateways/bayarcash/spec.md (measured)) - The checkout id is a payment intent (
pi_…), not a transaction:GET /transactions/pi_…is 404. Read it withGET /payment-intents/{id}(status and attempts), which answers 201 even though it is a read. (gateways/bayarcash/spec.md (measured)) - The checksum sorts values by field NAME and joins them with
|; apayment_channellist is joined with,inside it. (official PHP SDK ChecksumGenerator + tests) amountis ringgit with two decimals ("25.00") in both the JSON body and the checksum; a callback may carry it as a number. (official PHP SDK tests)order_number(the reference) takes at most 30 characters of ASCII letters, digits, space and"()*,-./:;@\_`~, with no leading or trailing space: a UUID (36) or#,&,?,+or a non-ASCII letter is refused with 422. None of this is in the API reference; the adapter refuses such a reference before the request (INVALID_REFERENCE). (gateways/bayarcash/spec.md (measured))- The Personal Access Token is long (984 characters on the sandbox): keep it in a TEXT column or a secret store, not VARCHAR(255); a token cut to 255 characters answers 401
Unauthenticated.(gateways/bayarcash/spec.md (measured)) GET /portalsis paginated (15 per page, newest first). An integration that reads only the first page loses its portal once the account has more; the adapter asks byportal_keyand walks every page. (gateways/bayarcash/spec.md (measured))
The full contract, with a source for every fact: gateways/bayarcash/spec.md.
Need help installing?
If you would rather not wire up a payment gateway yourself, Sasa Teguh, the studio that maintains bayarkit, can install it on your site or app and test it against the gateway sandbox before you go live.
Contact page · Email: [email protected] · WhatsApp: 017-762 9379
Bahasa Melayu
Bayarcash (juga di belakang BCL.my) untuk bayarkit: satu antara muka untuk gateway pembayaran Malaysia, dan cara bersemak untuk mengesahkan bayaran.
Bukti: Diukur pada sandbox, 27 Okt 2026: satu bayaran FPX berjaya dan satu gagal melalui adapter (URL return, pertanyaan status, portal); callback pelayan-ke-pelayan tidak diperhatikan.
npm install @bayarkit/core @bayarkit/bayarcashContoh kod di atas sama untuk semua gateway: hanya adapter dan kuncinya yang berubah. Jumlah ialah sen integer
(RM10.50 = 1050). Jangan tanda pesanan dibayar daripada badan callback atau pautan kembali semata-mata;
confirmPayment menyemak tandatangan, bertanya gateway semula, dan memadankan rujukan, jumlah dan mata wang.
Uji tanpa wang sebenar: startFakeBayarcash daripada @bayarkit/testing, atau npx bayarkit-fake bayarcash sebagai
pelayan.
Perangkap
- Kunci rahsia API meliputi seluruh akaun: return atau callback yang ditandatangani dengan betul boleh milik portal lain dalam akaun yang sama. Transaksi menamakan portalnya ikut NAMA (
portal), jadi beri setiap portal nama yang unik; adapter membandingkannya dengan nama bagi kunci portal yang dikonfigurasi. (gateways/bayarcash/spec.md (measured)) - Id checkout ialah payment intent (
pi_…), bukan transaksi:GET /transactions/pi_…memberi 404. Baca denganGET /payment-intents/{id}(status dan percubaan), yang menjawab 201 walaupun ia bacaan. (gateways/bayarcash/spec.md (measured)) - Checksum mengisih nilai mengikut NAMA medan dan menyambungnya dengan
|; senaraipayment_channeldisambung dengan,di dalamnya. (official PHP SDK ChecksumGenerator + tests) amountialah ringgit dengan dua tempat perpuluhan ("25.00") dalam badan JSON dan dalam checksum; callback mungkin membawanya sebagai nombor. (official PHP SDK tests)order_number(rujukan) menerima paling banyak 30 aksara huruf ASCII, digit, ruang dan"()*,-./:;@\_`~, tanpa ruang di awal atau hujung: UUID (36), atau#,&,?,+atau huruf bukan ASCII ditolak dengan 422. Semua ini tiada dalam rujukan API; adapter menolak rujukan begitu sebelum permintaan (INVALID_REFERENCE). (gateways/bayarcash/spec.md (measured))- Personal Access Token panjang (984 aksara pada sandbox): simpan dalam lajur TEXT atau stor rahsia, bukan VARCHAR(255); token yang dipotong ke 255 aksara menjawab 401
Unauthenticated.(gateways/bayarcash/spec.md (measured)) GET /portalsdibahagi kepada halaman (15 sehalaman, terbaru dahulu). Integrasi yang membaca halaman pertama sahaja kehilangan portalnya bila akaun ada lebih banyak; adapter bertanya ikutportal_keydan melalui setiap halaman. (gateways/bayarcash/spec.md (measured))
Kontrak penuh, dengan sumber bagi setiap fakta: gateways/bayarcash/spec.md. Dokumentasi penuh: README.ms.md.
Perlukan bantuan memasang?
Jika anda tidak mahu menyambung gateway pembayaran sendiri, Sasa Teguh, studio yang menyelenggara bayarkit, boleh memasangnya di laman atau aplikasi anda dan mengujinya pada sandbox gateway sebelum anda mula menerima bayaran.
Halaman hubungi · E-mel: [email protected] · WhatsApp: 017-762 9379
MIT © Muhammad Aiman
