Node.JS API library for Alfa-Bank in Belarus: acquiring, remote payments (VISA, MASTERCARD)
(Unnoficial)
Node.JS API библиотека для Альфа-Банк в Беларуси: эквайринг, удаленные платежи (VISA, MASTERCARD)
(Не оффициально)
- axios
- Composition api style
- Written on typescript (autocomplete filed)
-
register.do
-
register.do
withorderBundle
-
getOrderStatus.do
-
getOrderStatusExtended.do
-
addParams.do
-
refund.do
-
based on documentation merchant manual - ru
Install alfabank package
npm i alfabank
# or
yarn add alfabank
# or
pnpm add alfabank
import
import { useAlfaBank, toBynPenny } from 'alfabank'
convert human amount to minimum unit of measure
toBynPenny(10.5)
// Result: 1050
instance for action
const alfaBank = useAlfaBank({
token: 'your token'
// or
userName: 'your name',
password: ' yor',
language: 'en'
})
Autorization example, for storage use .env
variables
const result = await alfaBank.register({
amount: toBynPenny(115 * 2),
orderNumber: '1234',
returnUrl: `https://mysite/order/status`,
jsonParams: {
email: 'test@mail.ru',
phone: '+375251001100',
},
orderBundle: {
cartItems: {
items: [
{
name: 'Apple iPhone XR 64GB',
positionId: 1,
quantity: {
measure: 'pieces',
value: 2,
},
itemCode: '2',
},
],
},
},
})
if (result?.orderId) {
console.log(result.formUrl, result.orderId)
} else if (result?.errorCode) {
throw new Error(result.errorMessage)
}
const refundData = await alfaBank.refund({
amount: toBynPenny(115 * 2),
orderId: '291c4b92-4c38-70db-b265-5a2000c91c61',
})
console.log(refundData)
mutate response:
params
- field with value converted merchantOrderParams
array to object like {"key": "value"}
paid
- boolean - syntax sugar for check is order paid
{
// ...
merchantOrderParams: [
{
name: "browser_language_param",
value: "ru"
},
],
params: {
browser_language_param: "ru",
// ...
}
}
await alfaBank.addParams({
orderId: "291c4b92-4c38-70db-b265-5a2000c91c61",
params: {
cutom_field1: "sample"
}
})