@bayarkit/eghl
v0.3.3
Published
eGHL for Node.js and TypeScript: create payments, verify callbacks and confirm each payment with a fresh status query. Zero dependencies, part of bayarkit.
Maintainers
Readme
@bayarkit/eghl
eGHL (ADAPTIS e-Commerce) for bayarkit: one interface for Malaysian payment gateways, and a checked way to confirm a payment. Bahasa Melayu
Evidence: Official eGHL public code (hash class, merchant-api QUERY, Omnipay HashValue2 test vector; no public API guide exists); not yet measured on the test host.
npm install @bayarkit/core @bayarkit/eghlimport { checkoutResponse, confirmPayment, readCallback } from '@bayarkit/core'
import { eghl } from '@bayarkit/eghl'
const gateway = eghl({ serviceId, merchantPassword, environment: 'sandbox', fallbackCustomerIp })
// 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: startFakeEghl from @bayarkit/testing answers like this gateway (signed callbacks
included), and npx bayarkit-fake eghl runs it as a server for tests in other languages.
Traps
- Official plugins disagree on the HashValue2 field list: eGHL_HASH and WHMCS hash ...OrderNumber+Param6+Param7, Magento 2.1.7 omits Param7, and OpenCart omits both Param6 and Param7, so a callback carrying Param7 fails verification in some plugins. (bitbucket.org/eghl/eghl_hash eGHL_HASH.php line 2 vs bitbucket.org/eghl/adaptis-magento @faacfb1 zip Controller/Index/ResponseHandler.gte_m230.php:623-646 vs bitbucket.org/eghl/adaptis-opencart @38c0db3 zip catalog/controller/payment/ghl.php:206)
- The signature is plain SHA-256 over MerchantPassword concatenated with the field values (no separator, not HMAC), and the official hash class silently returns sha256(password) alone when a mandatory field is missing. (https://bitbucket.org/eghl/eghl_hash/raw/HEAD/eGHL_HASH.php)
- The server callback must answer with the plain body 'OK'; the browser return URL and the server callback receive the same fields, so both must verify the hash and be idempotent. (https://bitbucket.org/eghl/eghl-omnipay/raw/HEAD/README.md (lines 37-38, 96))
- Amount is ringgit as a string with exactly two decimals and no comma ('10.00', not sen), and the query must repeat the original Amount and CurrencyCode exactly or it will not find the transaction. (https://bitbucket.org/eghl/paramvalidator/raw/HEAD/src/core/validatorBase.php (isValidAmount) + https://bitbucket.org/eghl/merchantapi/raw/HEAD/README.md)
The full contract, with a source for every fact: gateways/eghl/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
eGHL (ADAPTIS e-Commerce) untuk bayarkit: satu antara muka untuk gateway pembayaran Malaysia, dan cara bersemak untuk mengesahkan bayaran.
Bukti: Kod awam rasmi eGHL (kelas hash, QUERY merchant-api, vektor ujian HashValue2 Omnipay; tiada panduan API awam); belum diukur pada hos ujian.
npm install @bayarkit/core @bayarkit/eghlContoh 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: startFakeEghl daripada @bayarkit/testing, atau npx bayarkit-fake eghl sebagai
pelayan.
Perangkap
- Plugin rasmi bercanggah tentang senarai medan HashValue2: eGHL_HASH dan WHMCS meng-hash ...OrderNumber+Param6+Param7, Magento 2.1.7 meninggalkan Param7, dan OpenCart meninggalkan kedua-dua Param6 dan Param7, jadi callback yang membawa Param7 gagal pengesahan dalam sesetengah plugin. (bitbucket.org/eghl/eghl_hash eGHL_HASH.php line 2 vs bitbucket.org/eghl/adaptis-magento @faacfb1 zip Controller/Index/ResponseHandler.gte_m230.php:623-646 vs bitbucket.org/eghl/adaptis-opencart @38c0db3 zip catalog/controller/payment/ghl.php:206)
- Tandatangan ialah SHA-256 biasa ke atas MerchantPassword yang disambung dengan nilai medan (tanpa pemisah, bukan HMAC), dan kelas hash rasmi diam-diam memulangkan sha256(password) sahaja apabila medan wajib tiada. (https://bitbucket.org/eghl/eghl_hash/raw/HEAD/eGHL_HASH.php)
- Callback pelayan mesti menjawab dengan badan biasa 'OK'; URL return pelayar dan callback pelayan menerima medan yang sama, jadi kedua-duanya mesti mengesahkan hash dan idempoten. (https://bitbucket.org/eghl/eghl-omnipay/raw/HEAD/README.md (lines 37-38, 96))
- Jumlah ialah ringgit sebagai rentetan dengan tepat dua tempat perpuluhan dan tanpa koma ('10.00', bukan sen), dan query mesti mengulang Amount dan CurrencyCode asal dengan tepat atau ia tidak akan menjumpai transaksi itu. (https://bitbucket.org/eghl/paramvalidator/raw/HEAD/src/core/validatorBase.php (isValidAmount) + https://bitbucket.org/eghl/merchantapi/raw/HEAD/README.md)
Kontrak penuh, dengan sumber bagi setiap fakta: gateways/eghl/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
