Hungarian OTP Bank easy-to-integrate Node payment module, demo app included.
Hungarian OTP Bank easy-to-integrate Node payment module, demo app included.
Available at: https://frozen-ravine-69013.herokuapp.com/app/
npm install node-otpbank -S
const { Otpbank } = require('node-otpbank');
const otpbank = new Otpbank(yourPosId, yourPrivateKey);
const amount = req.body.amount;
// you can create your own logic, but the library ships with a default
const transactionId = Otpbank.generateTransactionId();
// this will be the OTP Bank's URL, where the client must navigate
const redirectUrl = otpbank.getOtpRedirectUrl(transactionId);
// return the URL
// this is an early response as the startWorkflowSynch method resolves only when
// the user completes the payment form on OTP Bank's website
res.send(redirectUrl);
// this will be called by OTP Bank after they verified your payment
const callbackUrl = `http://yourwebshop.com/app?transaction=${transactionId}`;
// initiates a SOAP message to OTP Bank
otpbank.startTransaction(
transactionId,
callbackUrl,
amount,
'HUF',
`A shop comment which will appear on the OTP Bank's site`
)
.then((result) => /* transaction started, yay */)
.catch((error) => /* there was a problem with the request */);
// After redirection to the site of the merchant
otpbank.getTransaction(transactionId)
.then((result) => /* get payment data, yay */)
.catch((error) => /* cannot get payment data */);
Otpbank
classThis is the Otpbank export of the module.
static generateTransactionId()
Returns a unique ID, that can be passed to the payment method.
The transaction ID must be exactly 32 characters long. This method creates an Object ID (using bson
package) and concats enough random bytes in order to reach the 32 characters length.
This is the default strategy and can be ignored, so you can ship your own ID generation algorithm.
getOtpRedirectUrl(transactionId: string)
Returns a URL which will redirect the user to the OTP Bank’s website. This URL contains the POS ID (which is received when making a contract with OTP), and the current transaction ID.
startTransaction(transactionId: string, callbackUrl: string, amount: number, currency: string, shopComment: string, optionals?: { consumerRegistrationId: string } = { consumerRegistrationId: '' })
Creates a SOAP request to the OTP Bank’s payment server. If succeeded, the transaction just started. You may now redirect the customer to the payment site.
getTransaction(transactionId: string)
Creates a SOAP request to the OTP Bank’s payment server. If succeeded, the state of the transaction was retrieved by the request.
The lib ships with a demo application. When running npm start
an Express backend initializes, and a small frontend opens in your default browser.
In the demo app you can enter an arbitrary amount and click the Pay button. This will initiate a request to the OTP Bank’s website through the Express backend.
When at the OTP Bank’s website, you can fill out the payment form by using the dummy card data provided by OTP Bank on their website). These card informations can be seen on the console when the Express backend initializes.
After the payment form is submitted, the bank redirects the user to the frontend, where details can be seen about the transaction.
The sequence diagram of the demo flow:
All used resources (always-working & always-failing bank card infos, dummy private keys, dummy POS number, documentations) are available at the OTP Bank website.
In order to integrate OTP Bank’s payment system, you must first make a contract with OTP, then you will receive your own POS number, which can be configured through the module.