Earn with Paysera Do you create a libraries?


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

To integrate the system for MacroPayments we recommend to use our prepared open source library. Library performs all needful inspections of saveable, transmissible and receivable data.

Attention: libwebtopay is suitable to use with both MicroPayments and MacroPayments.

You are able to test libwebtopay in demo mode. To run demo version in your web browser address bar add:

https://www.yourwebsiteurl.com/libwebtopay/demo/

Attention: mentioned way to demo folder would be different in address, if you extracted archive in other place.

Attention: to try demonstration, indicate your project ID from paysera.com website in projectid field. Demonstration will not work if you try it from your computer (localhost).

How to integrate into your website?

In summary, it is enough to call for two methods. First one prepares data for sending, second one checks answer about committed payment.

Fully workable example is given bellow. You have to add your paysera.com connection data in commented places.

1. Create a folder.

Create a folder named libwebtopay. It will contain all files related to the payment integration.

2. Download libwebtopay library.

Download WebToPay.php file to the created folder libwebtopay.

3. Create a payment form file.

Create a file named form.php in the folder libwebtopay. The content of this file has to be:

<!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>

<?php

require_once('WebToPay.php');

function get_self_url() {
    $s = substr(strtolower($_SERVER['SERVER_PROTOCOL']), 0, strpos($_SERVER['SERVER_PROTOCOL'], '/'));

    if (!empty($_SERVER["HTTPS"])) {
        $s .= ($_SERVER["HTTPS"] == "on") ? "s" : "";
    }

    $s .= '://'.$_SERVER['HTTP_HOST'];

    if (!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != '80') {
        $s .= ':'.$_SERVER['SERVER_PORT'];
    }

    $s .= dirname($_SERVER['SCRIPT_NAME']);

    return $s;
}

try {
    $self_url = get_self_url();

    $request = WebToPay::buildRequest(array(
            // Here is listed only few parameters.
            // List of all possible values with descriptions are listed bellow.
            'projectid'     => 0,
            'sign_password' => 'd41d8cd98f00b204e9800998ecf8427e',
            'orderid'       => 0,
            'amount'        => 1000,
            'currency'      => 'EUR',
            'country'       => 'LT',
            'accepturl'     => $self_url.'/accept.php',
            'cancelurl'     => $self_url.'/cancel.php',
            'callbackurl'   => $self_url.'/callback.php',
            'test'          => 0,
        ));
}
catch (WebToPayException $e) {
    echo $e->getMessage();
}

?>

<form action="<?php echo WebToPay::PAY_URL; ?>" method="post">
    <?php foreach ($request as $key => $val): ?>
        <input type="hidden"
               name="<?php echo $key ?>"
               value="<?php echo htmlspecialchars($val); ?>"/>
    <?php endforeach; ?>

    <input type="submit" value="Pay" />
</form>

</body>
</html>

Full list of parameters with description of WebToPay::buildRequest() method:

Parameter Length Necessary Description
projectid 11 Yes Unique project number. Only activated projects can accept payments.
orderid 40 Yes Order number from your system.
lang 3 No It is possible to indicate user language (ISO 639-2/B: LIT, RUS, ENG, etc.). If Paysera does not support selected language, system will automatically choose language according IP address or ENG by default .
amount 11 No Amount in cents the client has to pay.
currency 3 No Payment currency (USD, EUR) you want the client to pay in. If the selected currency cannot be accepted by a specific payment method, the system will convert it automatically to the acceptable currency, according to the currency rate of the day. Payamount and paycurrency answers will be sent to your website.
accepturl 255 Yes Full address (URL), to which the client is directed after a successful payment.
cancelurl 255 Yes Full address (URL), to which the client is directed after an unsuccessful payment or cancellation.
callbackurl 255 Yes Full address (URL), to which a seller will get information about performed payment.

Script must return text "OK". Only then our system will register, that information about payment has been received.

If there is no answer "OK", message will be sent 4 times (when we get it, after hour, after three hours and after 24 hours).
payment 20 No Payment type. The parameter that should be empty. List of payment types will be provided to the user. It is used only if the user wants the payment to be made by a concrete method.
country 2 No Payer's country (LT, EE, LV, GB, PL, DE). All possible types of payment in that country are immediately indicated to the payer, after selecting a country.
paytext 255* No Payment purpose visible when making the payment. If not specified, default text is used:
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.

If these variables are not specified, the default purpose text will be used.

Example of a payment purpose:

Payment for goods made to order [order_nr] in website [site_name].
p_firstname 255 No Payer's name. Requested in the majority of payment methods. Necessary for certain payment methods.
p_lastname 255 No Payer's surname. Requested in the majority of payment methods. Necessary for certain payment methods.
p_email 255 No Payer's email address is necessary. If the email address is not received, the client will be requested to enter it. At this email address Paysera will inform the payer about the payment status.
p_street 255 No Payer's address, to which goods will be sent (e.g.: Mėnulio g. 7 - 7). Necessary for certain payment methods.
p_city 255 No Payer's city, to which goods will be sent (e.g.: Vilnius). Necessary for certain payment methods.
p_state 20 No Payer's state code (necessary, when buying in USA). Necessary for certain payment methods.
p_zip 20 No Payer's postal code. Lithuanian postal codes can be found here. Necessary for certain payment methods.
p_countrycode 2 No Payer's country code. The list with country codes can be found here. Necessary for certain payment methods.
sign 255 Yes Parameter with data signature. It is necessary to make sure that data is being sent from your website.

If you use not a PHP programing language, you have to pay attention in coding when generating 'sign' parameter. PHP functions strlen() and strtolower() do not maintain UTF-8, because of that operations are being performed not with UTF-8, but with bytes: strlen('ąbčd') == 6 and strtolower('ĄBČD') == 'ĄbČd'.

If You use PHP programming language, we suggest You to use LibWebToPay library, which has a method for sign generation.

test 1 No The parameter, which allows to test the connection. The payment is not executed, but the result is returned immediately, as if the payment has been made. To test, it is necessary to activate the mode for a particular project by logging in and selecting: "Manage projects" -> "Payment gateway" (for a specific project) -> "Allow test payments" (check).
version 9 Yes A version number of Paysera system specification (API).

* Final length may vary depending on payment type specification

4. Create a accept.php file.

Create a file named accept.php in the folder libwebtopay. The content of this file has to be:

<!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.
</body>
</html>

5. Create a cancel.php file.

Create a file named cancel.php in the folder libwebtopay. The content of this file has to be:

<!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 cancelled.
</body>
</html>

6. Processing of committed payments.

Create a file named callback.php in the folder libwebtopay. The content of this file has to be:

<?php

require_once('WebToPay.php');

try {
    $response = WebToPay::checkResponse($_GET, array(
    // List of all possible values with descriptions are listed bellow.
    'projectid'     => 0,
    'sign_password' => 'd41d8cd98f00b204e9800998ecf8427e',

    // Path to file to which all requests will be logged
    // If you plan to use this feature, make sure that log file
    // is not accessible from outside.
    // 'log' => 'webtopay.log',
    ));

    echo 'OK';
}
catch (Exception $e) {
    echo get_class($e).': '.$e->getMessage();
}

Attention! In GET method all paysera.com parameters have prefix WebToPay::PREFIX. Method WebToPay::checkResponse()returns all data without prefix. Illustration about that:

>>> $response = WebToPay::checkResponse(array('foo' => 'bar', 'wp_projectid' => '123'), array(...));
>>> print_r($response);
array('projectid' => '123')

For more information on callbacks see the chapter - Callback .