@mnpay/qpay
v0.6.0
Published
Client library for the QPay payment service — invoices, payments, eBarimt 3.0 and Quick QR.
Maintainers
Readme
QPay API Integration
This package provides a simple interface to integrate with the QPay payment service for merchants. It allows handling payments, invoices, authentication, and more via the QPay API.
official documentation: https://developer.qpay.mn
Features
- Authentication: Obtain and refresh access tokens.
- Invoice Management: Create, get, and cancel invoices.
- Payment Management: Check, get, and cancel payments, along with retrieving payment lists.
Installation
To install this package, use npm or yarn:
npm install @mnpay/qpayor
yarn add @mnpay/qpayUsage
Importing the Package
import { useQpay } from '@mnpay/qpay';Example: Initializing the QPay API
const qpay = useQpay({
baseUrl?: 'https://merchant.qpay.mn'
version?: 'v2'
accessToken?: 'access_token'
refreshToken?: 'refresh_token'
expiresIn?: new Date()
});Methods
authenticate
Obtain an access token using client_id and client_secret.
refreshToken
Refresh the access token using a refresh_token.
createInvoice
Create a new invoice for a payment.
getInvoice
Retrieve the details of a created invoice using invoice_id.
cancelInvoice
Cancel an existing invoice by sending the invoice_id.
getPayment
Retrieve the details of a payment using the payment_id.
checkPayment
Check if the payment was completed by providing the invoice_id and object_type.
cancelPayment
Cancel a payment by sending the payment_id.
refundPayment
Refund a payment by sending the payment_id, with an optional callback_url and note.
getPaymentList
Retrieve a list of payments made by customers.
createEbarimt
Create an eBarimt 3.0 receipt from a completed payment. Takes payment_id
(from checkPayment), ebarimt_receiver_type and ebarimt_receiver.
cancelEbarimt
Cancel an eBarimt receipt by payment_id, with an optional note.
Quick QR
Quick QR is a separate QPay product for registering sub-merchants and taking
QR payments into their accounts. It runs on its own host
(https://quickqr.qpay.mn) and its token request requires a terminal_id,
so it has its own client rather than extra methods on useQpay.
import { useQpayQuickQr } from '@mnpay/qpay'
const quickQr = useQpayQuickQr({
terminalId: process.env.QPAY_QUICKQR_TERMINAL_ID!,
username: process.env.QPAY_CLIENT_ID!,
password: process.env.QPAY_CLIENT_SECRET!,
})
const { data: merchant } = await quickQr.createCompanyMerchant({
register_number: '6691374',
company_name: 'Test LLC',
name: 'Test',
mcc_code: '5812',
city: '11',
district: '3505',
address: 'SBD 1st khoroo',
phone: '99112233',
email: '[email protected]',
})
const { data: invoice } = await quickQr.createInvoice({
merchant_id: merchant.merchant_id!,
amount: 100,
currency: 'MNT',
description: 'Order payment',
mcc_code: '5812',
callback_url: 'https://yoursite.com/webhook/quickqr',
bank_accounts: [
{
account_bank_code: '050000',
account_number: '5016271526',
account_name: 'Test LLC',
is_default: true,
},
],
})
const { data: payment } = await quickQr.checkPayment({ invoice_id: invoice.invoice_id! })Tokens are obtained and refreshed automatically by an Axios interceptor.
Invalid input raises QpayConfigError before any network call.
| Method | Endpoint |
|---|---|
| authenticate | POST /v2/auth/token |
| refreshToken | POST /v2/auth/refresh |
| getCityList | GET /v2/aimaghot |
| getDistrictList | GET /v2/sumduureg/{city_code} |
| createCompanyMerchant | POST /v2/merchant/company |
| updateCompanyMerchant | PUT /v2/merchant/company/{merchant_id} |
| createPersonMerchant | POST /v2/merchant/person |
| updatePersonMerchant | PUT /v2/merchant/person/{merchant_id} |
| getMerchant | GET /v2/merchant/{merchant_id} |
| deleteMerchant | DELETE /v2/merchant/{merchant_id} |
| getMerchantList | POST /v2/merchant/list |
| createInvoice | POST /v2/invoice |
| getInvoice | GET /v2/invoice/{invoice_id} |
| cancelInvoice | DELETE /v2/invoice/{invoice_id} |
| checkPayment | POST /v2/payment/check |
License
MIT License
