SDK for PHP
SDK for PHP is a software development kit for development of web services which are capable of integrating with the Benker payment solutions to perform purchase by using Payment Page. This section describes how to use SDK for PHP to build purchase experience from inside of your web service.
SDK for PHP is compatible with PHP version 7.0 or higher.
What can I do with SDK for PHP?
- 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 PHP contains the following:
- src—a library for development
- tests—a library for automatic testing
- composer.json—a script for importing libraries
- The service files
Using SDK for PHP
To start using SDK for PHP you need to complete the following tasks:
- Make sure 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 Benker customer support that you want to use SDK for PHP 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 PHP 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 PHP contact the Benker technical support specialists at help@benker.io.
Installing and importing libraries
You can install the SDK for PHP libraries manually.
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 PHP allows you to seamlessly sign parameters and generate URLs. To open the Payment Page payment form by using SDK for PHP do the following:
- Create an instance of the
Paymentclass and specify payment details.$payment = new Benker\Payment('186', 'TEST_1555943554067'); // Project ID and payment ID and payment ID must be unique within your project scope $payment->setPaymentAmount(1000)->setPaymentCurrency('EUR'); // Amount in minor currency units and currency in the ISO-4217 alpha-3 format $payment->setCustomerId('customer007'); // Customer ID $payment->setPaymentDescription('Test payment'); // 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.
- Create a
gateinstance and initiate it with the secret key you obtained from the Benker technical support specialists. The secret key is required to sign parameters.$gate = new Benker\Gate('<secret_key>'); // Secret key you obtained from the technical support service
-
Generate the URL for opening the payment form:
$url = $gate->getPurchasePaymentPageUrl($payment);
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 while the data input page includes a countdown timer.
$gate = new Benker\Gate('<secret_key>'); // Secret key $payment = new Benker\Payment('186', 'TEST_1555943554067'); // Project ID and payment ID and payment ID must be unique within your project scope $payment->setPaymentAmount(1000)->setPaymentCurrency('EUR'); // Amount in minor currency units and currency in ISO-4217 alpha-3 format $payment->setCustomerId('customer007'); // Customer ID $payment->setPaymentDescription('Test payment'); // Payment description $payment->setBestBefore(new \DateTime('2050-01-01 00:00:00 +0000')); // Date and time for timer countdown $payment->setLanguageCode('en'); // Language code to use in payment form $url = $gate->getPurchasePaymentPageUrl($payment); // Complete request with signature
Using the test mode
When working with the SDK for PHP, you can use the test mode. It allows you to check completeness and correctness of specified parameters and get information about errors if there were any.
Before using the test mode, make sure that the server of the web service can send the HTTP requests to sdk.benker.io and that your PHP interpreter meets at least one of the following requirements:
- It supports the
curllibrary (more). - It supports the
socketslibrary with the HTTP access to the URL (more). - The directive
allow_fopen_urlis set totrueand the HTTP access to the URL is supported (more).
This will allow you to specify various parameters to open the payment form as part of the testing activities (you will be able to use both test and production parameters) and to analyse error information. Use the following code:
$payment = new Payment(<project_id>, '<payment_id_in_your_service>'); $payment->setPaymentAmount(1000) ->setPaymentCurrency('EUR') ->setPaymentDescription('Test payment') $gate = new Gate('<secret_key>'); try { return $gate->getPaymentPageUrl($payment); // Receiving the URL to open the payment form } catch (ValidationException $e) { // Validating possible exceptions error_log($e->getFormattedMessage()); // Logging the error message } return null;
Information about the errors that occurred in testing is provided in error messages as follows:
One or more parameters is not valid:
Customer_id:
Must be not null // The id of the customer, required for this request, was not specified
Account_token:
Invalid account token // Incorrect token value was specified
If there are no errors, then the generated URL for opening Payment Page is correct.
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. To extract payment information from a JSON string do the following:
- Create an instance of
Gatewith the secret key, if you did not it earlier.$gate = new Benker\Gate('<secret_key>');
-
Create an instance of
Callbackby using the JSON string from the callback obtained from the Benker payment platform:$callback = $gate->handleCallback($data);
-
Use the following methods to obtain the callback information. You can get either full payment information or request specific payment parameters:
Callback::getPaymentId(); // Getting payment ID Callback::getPaymentStatus(); // Getting payment status Callback::getPayment(); // Getting payment body
By using SDK for PHP, 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==" }