SDK for JavaScript
SDK for JavaScript is a software development kit for development of web services which are capable of integrating with the Benker payment solutions to perform purchases by using Payment Page. This section describes how to use SDK for JavaScript to build purchase experience from inside of your web service.
SDK for JavaScript is compatible with the Node.js 4.x runtime environment for executing JavaScript code.
What can I do with SDK for JavaScript?
- Calculate signature and generate an URL for opening the Payment Page.
- Check callback signature and extract payment details from callbacks
What's inside?
SDK for JavaScript contains the following:
- src—a library for development
- _tests_—a library for automatic testing
Using SDK for JavaScript
To start using SDK for JavaScript you need to complete the following tasks:
- Make sure you have you have ready your merchant ID and secret key obtained from Benker.
- If your company has never obtained any ID or secret key from Benker, you need to submit an application for connecting to the Benker payment platform.
- If your company already has an ID and a secret key to sign messages obtained from Benker, you need to notify the Benker technical support specialists that you want to use SDK for JavaScript and consult the customer support on how to arrange a test run.
- Integrate the Benker payment solution in your web service:
- Install the SDK for JavaScript libraries into a directory inside your web service project.
- Import the libraries you need into your web service application.
- Test and put your web service in production mode.
With any questions regarding the use of SDK for JavaScript contact the Benker technical support specialists at help@benker.io.
Installing and importing libraries
You can install the SDK for JavaScript libraries manually or automatically with Yarn or npm, package-management systems used to install and manage software packages written in JavaScript.
The following steps describe how to install the SDK for JavaScript libraries by using Yarn or npm:
- If you have not yet installed a package-management system, you need to download, install and check settings. For more information, see:
- Navigate into the web service source code directory in command line and run one of the following commands:
npm install Benker // for npm yarn add Benker // for Yarn
A package-management system automatically downloads the SDK for JavaScript libraries in the source code directory to enable you to use all the modules provided by the libraries.
- Import the modules into your web service project:
const { Payment } = require('Benker'); const { Callback } = require('Benker');
Opening payment form
A URL for opening Payment Page consists of a set of parameters, which are signed to secure the data transmitted to the Benker payment platform. SDK for JavaScript allows you to seamlessly sign parameters and generate URLs. To open the Payment Page payment form by using SDK for JavaScript do the following:
- Create an instance of the
Paymentclass and specify payment details and the secret key you obtained from the Benker technical support specialists. The secret key is required to sign parameters.const e = new Payment('186', '<secret_key>'); // Project ID and Secret key e.paymentId = 'TEST_1555943554067'; // Payment ID must be unique within your project scope e.paymentAmount = 1000; // Amount in minor currency units e.paymentCurrency = 'EUR'; // Currency in ISO-4217 alpha-3 format e.customerId = 'customer_112'; // Customer ID e.paymentDescription = 'Payment description'; // Payment description (optional)
All parameters in this example, except for the payment description, are mandatory for any purchase.
You can also use any other optional parameters available for Payment Page. For more information about the Payment Page invocation parameters, see Parameters for opening the payment form.
-
Generate the URL for opening the payment form:
const url = e.getUrl();
The URL must contain payment parameters and signature (abbreviated):
https://paymentpage.benker.io/payment?signature=OEKRlLXQsa2.. ..gWg%3D%3D&payment_id=pid_1555943554067...
- Use the generated URL for opening the payment form (details).
Here is an example of generating a URL for opening a payment form in English. The payment method selection page includes detailed payment information including amount, currency, and short payment description.
const e = new Payment('186', '<secret_key>'); // Project ID and Secret key e.paymentId = 'TEST_1555943554067'; // Payment ID must be unique within your project scope e.paymentAmount = 1000; // Amount in minor currency units e.paymentCurrency = 'EUR'; // Currency in ISO-4217 alpha-3 format e.customerId = 'customer_112'; // Customer ID e.paymentDescription = 'Payment description'; // Payment description (optional) e.language_code: 'EN'; // Language code to use in payment form const url = e.getUrl(); // Complete request with signature
Processing callbacks
The Benker payment platform sends payment results to the callback URL you specified when connecting to Benker. Callback is an HTTP POST request that contains response data in JSON format in the req.body object. To extract payment information from JSON string, do the following:
- Create an instance of
Callbackby using the secret key and the JSON string from the callback obtained from the Benker payment platform:const callback = new Callback(<secret_key>, req.body);
-
The following example contains the methods for extracting callback information in the source code that uses the Express framework:
app.post('/payment/callback', function(req, res) { const callback = new Callback(<secret_key>, req.body); if (callback.isPaymentSuccess()) { const paymentCont = callback.payment(); // Getting information about the payment const paymentId = callback.getPaymentId(); // Getting payment ID // Add your code for proccessing successful payment } });
By using SDK for JavaScript, you can automatically check validity of callback signature. Below, you will find an example of callback that includes signature and payment results.
POST /notify/success HTTP/1.1 Content-Length: 1237 User-Agent: GuzzleHttp/6.3.3 curl/7.47.0 PHP/7.0.32-0ubuntu0.16.04.1 Content-Type: application/json Host: webservice.com { "project_id": 200, "payment": { "id": "abc12345", "type": "purchase", "status": "success", "date": "2025-03-20T14:22:06+0000", "method": "Greek Banks", "sum": { "amount": 1000, "currency": "EUR" }, "description": "Success" }, "customer": { "id": "123" }, "operation": { "id": 9529253065607, "type": "sale", "status": "success", "date": "2025-03-20T14:22:06+0000", "created_date": "2025-03-20T14:22:00+0000", "request_id": "f1de353331a01fd14163fe4226-00009530", "sum_initial": { "amount": 1000, "currency": "EUR" }, "sum_converted": { "amount": 1000, "currency": "EUR" }, "code": "0", "message": "Success", "provider": { "id": 1914, "payment_id": "", "auth_code": "" } }, "signature": "OBjT3RaJnOWsDXOclvWoC6+CFSCtLprTo8VFbN6BYVQD2tVK/3d9k+RRA/7N9TV6OQqk+0uPUnx4/c8uaUurw==" }