Integration with a library
We will pay from 100 to 200 EUR for an accurate and working programming code. If you’d like to
cooperate in the future and receive orders for maintenance of a specific system version, the code and your
contact data will be published for open use.
Contact us via email to support@paysera.com
You can integrate Paysera system into your website by downloading our open source software library libwebtopay. The library can be used to check all the necessary security parameters of transferred and received data.
-
WebToPay for PHP (from GitHub).
$ git clone https://github.com/paysera/lib-webtopay
-
WebToPay for .NET (from GitHub).
$ git clone https://github.com/evp/webtopay-lib-dotnet
In the archive, select file libwebtopay/WebToPay.php. Other files are intended as tests, examples and explanations. The latest and the only version of libwebtopay/WebToPay.php file can be downloaded at: WebToPay.php.
Paysera system can also be integrated to your system using open code libraries made by third party:
-
Omnipay 2.x - payment processing library for PHP (from GitHub).
$ git clone https://github.com/povils/omnipay-paysera.git
Below you will find a working example. Locations where your Paysera access data has to be entered are marked with comments.
1. Create a folder.
Create a folder, name it libwebtopay. Here, all the files related to payment integration will be stored.
2. Download libwebtopay library.
Download WebToPay.php file to the libwebtopay folder created.
3. Create a file that directs users to Paysera website.
In the libwebtopay folder, CREATE redirect.php file. The content of this file could be as follows:
<?php require_once('WebToPay.php'); function getSelfUrl(): string { $url = substr(strtolower($_SERVER['SERVER_PROTOCOL']), 0, strpos($_SERVER['SERVER_PROTOCOL'], '/')); if (isset($_SERVER['HTTPS']) === true) { $url .= ($_SERVER['HTTPS'] === 'on') ? 's' : ''; } $url .= '://' . $_SERVER['HTTP_HOST']; if (isset($_SERVER['SERVER_PORT']) === true && $_SERVER['SERVER_PORT'] !== '80') { $url .= ':' . $_SERVER['SERVER_PORT']; } $url .= dirname($_SERVER['SCRIPT_NAME']); return $url; } try { WebToPay::redirectToPayment([ 'projectid' => {YOUR_PROJECT_ID}, 'sign_password' => {YOUR_PROJECT_PASSWORD}, 'orderid' => 0, 'amount' => 1000, 'currency' => 'EUR', 'country' => 'LT', 'accepturl' => getSelfUrl() . '/accept.php', 'cancelurl' => getSelfUrl() . '/cancel.php', 'callbackurl' => getSelfUrl() . '/callback.php', 'test' => 0, ]); } catch (Exception $exception) { echo get_class($exception) . ':' . $exception->getMessage(); }
Instead of WebToPay::redirectToPayment method, you can use WebToPay::buildRequest, which accepts the same parameters and returns the data array necessary for the transfer.
4. Create accept.php
In the libwebtopay folder, create accept.php file. The contents of the file have to be as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/> <title></title> </head> <body> Thank you for buying. </body> </html>
5. Create cancel.php
In the libwebtopay folder, CREATE cancel.php file. The contents of the file have to be as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/> <title></title> </head> <body> Payment canceled. </body> </html>}
6. Processing of payments.
In the libwebtopay folder, create callback.php file. The contents of the file have to be as follows:
<?php require_once('WebToPay.php'); function isPaymentValid(array $order, array $response): bool { if (array_key_exists('payamount', $response) === false) { if ($order['amount'] !== $response['amount'] || $order['currency'] !== $response['currency']) { throw new Exception('Wrong payment amount'); } } else { if ($order['amount'] !== $response['payamount'] || $order['currency'] !== $response['paycurrency']) { throw new Exception('Wrong payment amount'); } } return true; } try { $response = WebToPay::validateAndParseData( $_REQUEST, {YOUR_PROJECT_ID}, {YOUR_PROJECT_PASSWORD} ); if ($response['status'] === '1' || $response['status'] === '3') { //@ToDo: Validate payment amount and currency, example provided in isPaymentValid method. //@ToDo: Validate order status by $response['orderid']. If it is not already approved, approve it. echo 'OK'; } else { throw new Exception('Payment was not successful'); } } catch (Exception $exception) { echo get_class($exception) . ':' . $exception->getMessage(); }
Extra parameters for recurring payments of PIS
There is an option to create recurring payments by providing additional data in the request. After that the bank will execute PIS payment automatically by defined period and frequency. Only a couple of banks provide this option: SEB and Swedbank
Available frequencies for all enabled periodic payment methods:
weekly
monthly
quarterly
semiannual
annual
Available frequencies for some enabled periodic payment methods:
daily
every_working_day
last_day_of_month
last_working_day_of_month
The date format should be yyyy-mm-dd.
The date format should be yyyy-mm-dd.
Request parameters
Seller should not rely on accepturl to confirm an order. Instead, order confirmation on the Seller side should be done per callbackurl.
Script must return text "OK". Only then our system will register, that information about the payment has been received.
If there is no answer "OK", the message will be sent 4 times (when we get it, after an hour, after three hours and after 24 hours).Payment for goods and services (for nb. [order_nr]) ([site_name]).
If you specify the payment purpose, it is necessary to include the following variables, which will be replaced with the appropriate values in the final purpose text:
[order_nr] - payment number.[site_name] or [owner_name] - website address or company name.
Can be set to 0 or 1. If it is set to 1, the payer can skip the additional step where he needs to accept consent using PIS payment. If this parameter is used, additional text is required to be added to your page:
Buyer consent text in other languages provided below the table**
* Final length may vary depending on payment type specification
** Buyer consent text:
Callback
For more information on callbacks - see the chapter Callback .