Skip to main content

API Request Examples

This page provides practical code examples for common Checkout API integration scenarios. Each example demonstrates real-world implementation patterns to help you quickly integrate payment functionality into your application.

Overview​

The examples are organized by use case and include implementations in multiple programming languages where applicable. All examples use test credentials - replace them with your actual project credentials when implementing in production.

Quick Start

New to Paysera Checkout? Start with Create Payment Form and Handle Payment Callback examples to understand the basic payment flow.

Basic Payment Flow​

These examples cover the essential steps of creating and processing payments.

Create Payment Form - Generate a payment form to redirect customer to Paysera

PHP Example​

<?php
$projectId = 12345;
$projectPassword = 'your_project_password';

$orderData = [
'projectid' => $projectId,
'orderid' => 'ORDER-' . time(),
'amount' => 2500, // 25.00 EUR
'currency' => 'EUR',
'accepturl' => 'https://example.com/payment/success',
'cancelurl' => 'https://example.com/payment/cancel',
'callbackurl' => 'https://example.com/payment/callback',
'p_firstname' => 'John',
'p_lastname' => 'Doe',
'p_email' => 'john.doe@example.com',
'lang' => 'en'
];

// Generate signature
ksort($orderData);
$signString = '';
foreach ($orderData as $key => $value) {
$signString .= $value;
}
$signString .= $projectPassword;
$orderData['sign'] = md5($signString);

// Generate form HTML
echo '<form method="POST" action="https://www.paysera.com/pay/">';
foreach ($orderData as $key => $value) {
echo '<input type="hidden" name="' . htmlspecialchars($key) . '" value="' . htmlspecialchars($value) . '" />';
}
echo '<button type="submit">Pay 25.00 EUR</button>';
echo '</form>';
?>
Handle Payment Callback - Process payment confirmation from Paysera

PHP Example​

<?php
$projectPassword = 'your_project_password';

// Get callback data
$data = $_GET;
$receivedSign = $data['sign'] ?? '';
unset($data['sign']);

// Verify signature
ksort($data);
$signString = implode('', $data) . $projectPassword;
$calculatedSign = md5($signString);

if ($calculatedSign !== $receivedSign) {
http_response_code(400);
die('Invalid signature');
}

// Process payment
$orderId = $data['orderid'];
$status = (int)$data['status'];
$amount = (int)$data['amount'];
$currency = $data['currency'];

if ($status === 1) {
// Payment successful
// Update order status in database
updateOrderStatus($orderId, 'paid', $amount, $currency);

echo 'OK';
} else {
// Payment pending or cancelled
echo 'OK';
}
?>

Advanced Features​

Explore more sophisticated payment scenarios and integration patterns.

Donate Button Integration - Accept donations on your website

HTML Donation Button​

<!-- Generated donation button from Paysera -->
<a href="https://www.paysera.com/donate/12345" target="_blank">
<img src="https://www.paysera.com/img/donate-button.png" alt="Donate" />
</a>

PHP Custom Donation Form​

<?php
require_once 'WebToPay.php';

$projectId = 12345;
$projectPassword = 'your_project_password';

// Let user choose donation amount
$donationAmount = $_POST['amount'] ?? 1000; // Default 10.00 EUR

$request = WebToPay::buildRequest([
'projectid' => $projectId,
'sign_password' => $projectPassword,
'orderid' => 'DONATION-' . time(),
'amount' => $donationAmount,
'currency' => 'EUR',
'country' => 'LT',
'accepturl' => 'https://example.com/donation/thank-you',
'cancelurl' => 'https://example.com/donation/cancelled',
'callbackurl' => 'https://example.com/donation/callback',
'p_email' => $_POST['email'] ?? 'donor@example.com',
'paytext' => 'Donation to Our Cause',
'test' => 0
]);

// Display donation form
echo '<form method="POST" action="https://www.paysera.com/pay/">';
echo '<h3>Support Our Cause</h3>';
echo '<select name="amount">';
echo '<option value="500">5.00 EUR</option>';
echo '<option value="1000" selected>10.00 EUR</option>';
echo '<option value="2000">20.00 EUR</option>';
echo '<option value="5000">50.00 EUR</option>';
echo '</select>';
echo '<input type="email" name="email" placeholder="Your email" required />';
foreach ($request as $key => $value) {
echo '<input type="hidden" name="' . htmlspecialchars($key) . '" value="' . htmlspecialchars($value) . '" />';
}
echo '<button type="submit">Donate Now</button>';
echo '</form>';
?>
Periodic Payments - Set up recurring payment subscription
Bank Compatibility

Periodic payments are only available for SEB and Swedbank payment methods. Ensure you select one of these banks when implementing recurring payments.

PHP Example with Swedbank​

<?php
require_once 'WebToPay.php';

$projectId = 12345;
$projectPassword = 'your_project_password';

$orderData = [
'projectid' => $projectId,
'orderid' => 'SUBSCRIPTION-' . time(),
'amount' => 2999, // 29.99 EUR
'currency' => 'EUR',
'payment' => 'hanza', // Swedbank for periodic payments
'accepturl' => 'https://example.com/subscription/success',
'cancelurl' => 'https://example.com/subscription/cancel',
'callbackurl' => 'https://example.com/subscription/callback',
'p_email' => 'customer@example.com',

// Periodic payment settings
'periodic_payments_enabled' => '1',
'periodic_payments_frequency' => 'month', // Options: day, week, month
'periodic_payments_start_date' => date('Y-m-d', strtotime('+1 month')), // Start next month
'periodic_payments_end_date' => date('Y-m-d', strtotime('+1 year')), // End in 1 year

'test' => 0
];

$request = WebToPay::buildRequest([
'projectid' => $projectId,
'sign_password' => $projectPassword,
] + $orderData);

// Generate payment form
echo '<form method="POST" action="https://www.paysera.com/pay/">';
echo '<h3>Monthly Subscription - 29.99 EUR/month</h3>';
echo '<p>Payment method: Swedbank</p>';
echo '<p>Subscription starts: ' . htmlspecialchars($orderData['periodic_payments_start_date']) . '</p>';
echo '<p>Subscription ends: ' . htmlspecialchars($orderData['periodic_payments_end_date']) . '</p>';

foreach ($request as $key => $value) {
echo '<input type="hidden" name="' . htmlspecialchars($key) . '" value="' . htmlspecialchars($value) . '" />';
}

echo '<button type="submit">Subscribe with Swedbank</button>';
echo '</form>';
?>

PHP Example with SEB​

<?php
// Using SEB bank for periodic payments
$orderData = [
'projectid' => 12345,
'orderid' => 'SUBSCRIPTION-SEB-' . time(),
'amount' => 2999, // 29.99 EUR
'currency' => 'EUR',
'payment' => 'vb2', // SEB for periodic payments
'accepturl' => 'https://example.com/subscription/success',
'cancelurl' => 'https://example.com/subscription/cancel',
'callbackurl' => 'https://example.com/subscription/callback',
'p_email' => 'customer@example.com',

// Periodic payment settings
'periodic_payments_enabled' => '1',
'periodic_payments_frequency' => 'month',
'periodic_payments_start_date' => date('Y-m-d', strtotime('+1 month')),
'periodic_payments_end_date' => date('Y-m-d', strtotime('+1 year')),

'test' => 0
];

$request = WebToPay::buildRequest([
'projectid' => $projectId,
'sign_password' => $projectPassword,
] + $orderData);

// Generate payment form
echo '<form method="POST" action="https://www.paysera.com/pay/">';
echo '<h3>Monthly Subscription - 29.99 EUR/month</h3>';
echo '<p>Payment method: SEB</p>';
echo '<p>Subscription starts: ' . htmlspecialchars($orderData['periodic_payments_start_date']) . '</p>';
echo '<p>Subscription ends: ' . htmlspecialchars($orderData['periodic_payments_end_date']) . '</p>';

foreach ($request as $key => $value) {
echo '<input type="hidden" name="' . htmlspecialchars($key) . '" value="' . htmlspecialchars($value) . '" />';
}

echo '<button type="submit">Subscribe with SEB</button>';
echo '</form>';
?>

Example with Different Frequencies​

<?php
// Daily payment
$dailyPayment = [
'periodic_payments_frequency' => 'day',
'periodic_payments_start_date' => date('Y-m-d', strtotime('+1 day')),
'periodic_payments_end_date' => date('Y-m-d', strtotime('+30 days')),
];

// Weekly payment
$weeklyPayment = [
'periodic_payments_frequency' => 'week',
'periodic_payments_start_date' => date('Y-m-d', strtotime('next monday')),
'periodic_payments_end_date' => date('Y-m-d', strtotime('+12 weeks')),
];

// Monthly payment
$monthlyPayment = [
'periodic_payments_frequency' => 'month',
'periodic_payments_start_date' => date('Y-m-d', strtotime('first day of next month')),
'periodic_payments_end_date' => date('Y-m-d', strtotime('+1 year')),
];
?>
Beneficiary Parameters - Include beneficiary information in payment request

PHP Example​

<?php
require_once 'WebToPay.php';

$projectId = 12345;
$projectPassword = 'your_project_password';

$orderData = [
'projectid' => $projectId,
'orderid' => 'ORDER-' . time(),
'amount' => 15000, // 150.00 EUR
'currency' => 'EUR',
'accepturl' => 'https://example.com/payment/success',
'cancelurl' => 'https://example.com/payment/cancel',
'callbackurl' => 'https://example.com/payment/callback',
'p_email' => 'customer@example.com',

// Beneficiary information
'beneficiary_name' => 'John Doe',
'beneficiary_code' => '38001010001', // Personal code or business code
'beneficiary_bank_account' => 'LT123456789012345678',
'beneficiary_address' => '123 Main Street, Vilnius, Lithuania',

'test' => 0
];

$request = WebToPay::buildRequest([
'projectid' => $projectId,
'sign_password' => $projectPassword,
] + $orderData);

// Generate payment form
echo '<form method="POST" action="https://www.paysera.com/pay/">';
echo '<h3>Payment with Beneficiary Information</h3>';
echo '<div class="beneficiary-info">';
echo '<p><strong>Beneficiary:</strong> ' . htmlspecialchars($orderData['beneficiary_name']) . '</p>';
echo '<p><strong>Account:</strong> ' . htmlspecialchars($orderData['beneficiary_bank_account']) . '</p>';
echo '<p><strong>Code:</strong> ' . htmlspecialchars($orderData['beneficiary_code']) . '</p>';
echo '<p><strong>Address:</strong> ' . htmlspecialchars($orderData['beneficiary_address']) . '</p>';
echo '</div>';

foreach ($request as $key => $value) {
echo '<input type="hidden" name="' . htmlspecialchars($key) . '" value="' . htmlspecialchars($value) . '" />';
}

echo '<button type="submit">Pay 150.00 EUR</button>';
echo '</form>';
?>

Use Case Example: Invoice Payment​

<?php
// Example: Pay an invoice with beneficiary details
$invoicePayment = [
'projectid' => 12345,
'orderid' => 'INVOICE-2024-001',
'amount' => 25000, // 250.00 EUR
'currency' => 'EUR',

// Invoice beneficiary
'beneficiary_name' => 'ABC Company Ltd',
'beneficiary_code' => '123456789', // Company registration code
'beneficiary_bank_account' => 'LT987654321098765432',
'beneficiary_address' => 'Business Park 456, Vilnius, Lithuania',

'paytext' => 'Invoice #2024-001 payment',
'accepturl' => 'https://example.com/invoice/paid',
'callbackurl' => 'https://example.com/invoice/callback',
];
?>
Error Handling - Handle common errors during integration

Example​

<?php
function handlePayseraResponse($response) {
if (isset($response['error'])) {
switch ($response['error']) {
case 'invalid_signature':
logError('Payment signature validation failed');
return ['status' => 'error', 'message' => 'Security check failed'];

case 'duplicate_order':
logError('Duplicate order ID: ' . $response['orderid']);
return ['status' => 'error', 'message' => 'Order already exists'];

case 'invalid_amount':
logError('Invalid payment amount');
return ['status' => 'error', 'message' => 'Invalid amount'];

default:
logError('Unknown error: ' . $response['error']);
return ['status' => 'error', 'message' => 'Payment failed'];
}
}

return ['status' => 'success'];
}
?>
Getting Available Payment Types - Retrieve available payment methods before displaying them to customers

Using WebToPay Library (PHP)​

<?php
require_once 'WebToPay.php';

$projectId = 12345;
$currency = 'EUR';
$amount = 5000; // 50.00 EUR in cents

try {
// Get all payment methods for project
$paymentMethods = WebToPay::getPaymentMethodList($projectId, $currency);

// Filter by amount
$availableMethods = $paymentMethods
->filterForAmount($amount, $currency)
->setDefaultLanguage('en');

// Get payment methods for Lithuania
$ltMethods = $availableMethods->getCountry('lt');

echo '<h3>Payment Methods in Lithuania:</h3>';
echo '<ul>';

foreach ($ltMethods->getPaymentMethods() as $method) {
$logo = $method->getLogoUrl() ?: '';
$title = $method->getTitle();
$key = $method->getKey();

echo '<li>';
if ($logo) {
echo '<img src="' . htmlspecialchars($logo) . '" alt="' . htmlspecialchars($title) . '" /> ';
}
echo htmlspecialchars($title);
echo ' <small>(' . htmlspecialchars($key) . ')</small>';
echo '</li>';
}

echo '</ul>';

} catch (WebToPayException $e) {
echo 'Error: ' . $e->getMessage();
}
?>

Without WebToPay Library (Direct XML)​

<?php
$projectId = 12345;
$currency = 'EUR';
$amount = 5000; // Optional: filter by amount in cents

// Build API URL
$url = "https://www.paysera.com/payment-methods/{$projectId}";
$url .= "/currency:{$currency}";
if ($amount) {
$url .= "/amount:{$amount}";
}
$url .= "/language:en";

// Fetch payment methods
$xml = file_get_contents($url);
if ($xml === false) {
die('Failed to fetch payment methods');
}

// Parse XML
$methods = simplexml_load_string($xml);

echo '<h3>Available Payment Methods:</h3>';

foreach ($methods->country as $country) {
$countryTitle = (string)$country['title'];
echo '<h4>' . htmlspecialchars($countryTitle) . '</h4>';
echo '<ul>';

foreach ($country->payment_type as $method) {
$key = (string)$method['key'];
$title = (string)$method['title'];
$logoUrl = (string)$method['logo_url'];
$minAmount = (string)$method['min_amount'];
$maxAmount = (string)$method['max_amount'];

echo '<li>';
if ($logoUrl) {
echo '<img src="' . htmlspecialchars($logoUrl) . '" width="50" alt="' . htmlspecialchars($title) . '" /> ';
}
echo '<strong>' . htmlspecialchars($title) . '</strong>';
echo ' <code>' . htmlspecialchars($key) . '</code>';
echo '<br>Min: ' . htmlspecialchars($minAmount) . ' | Max: ' . htmlspecialchars($maxAmount);
echo '</li>';
}

echo '</ul>';
}
?>

JavaScript/AJAX Example​

async function getPaymentMethods(projectId, currency = 'EUR', amount = null) {
let url = `https://www.paysera.com/payment-methods/${projectId}/currency:${currency}`;

if (amount) {
url += `/amount:${amount}`;
}
url += '/language:en';

try {
const response = await fetch(url);
const xmlText = await response.text();

// Parse XML
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(xmlText, 'text/xml');

const countries = xmlDoc.querySelectorAll('country');
const paymentMethods = [];

countries.forEach(country => {
const countryCode = country.getAttribute('code');
const countryTitle = country.getAttribute('title');

const methods = country.querySelectorAll('payment_type');
methods.forEach(method => {
paymentMethods.push({
country: countryCode,
countryTitle: countryTitle,
key: method.getAttribute('key'),
title: method.getAttribute('title'),
logoUrl: method.getAttribute('logo_url'),
minAmount: parseFloat(method.getAttribute('min_amount')),
maxAmount: parseFloat(method.getAttribute('max_amount'))
});
});
});

return paymentMethods;

} catch (error) {
console.error('Error fetching payment methods:', error);
return [];
}
}

// Usage example
getPaymentMethods(12345, 'EUR', 5000).then(methods => {
console.log('Available payment methods:', methods);

// Display in HTML
const container = document.getElementById('payment-methods');
methods.forEach(method => {
const div = document.createElement('div');
div.className = 'payment-method';
div.innerHTML = `
<img src="${method.logoUrl}" alt="${method.title}" />
<span>${method.title}</span>
<small>${method.key}</small>
`;
div.onclick = () => selectPaymentMethod(method.key);
container.appendChild(div);
});
});

Filtering by Groups (PHP)​

<?php
// Get payment methods with grouping
$paymentMethods = WebToPay::getPaymentMethodList($projectId, $currency)
->filterForAmount($amount, $currency)
->setDefaultLanguage('en');

// Get methods for Lithuania with groups
$country = $paymentMethods->getCountry('lt');

echo '<h3>Payment Methods by Group:</h3>';

foreach ($country->getGroups() as $group) {
echo '<div class="payment-group">';
echo '<h4>' . htmlspecialchars($group->getTitle()) . '</h4>';
echo '<div class="methods">';

foreach ($group->getPaymentMethods() as $method) {
$available = $method->isAvailableForAmount($amount, $currency);
$class = $available ? 'available' : 'unavailable';

echo '<div class="method ' . $class . '">';
if ($method->getLogoUrl()) {
echo '<img src="' . htmlspecialchars($method->getLogoUrl()) . '" />';
}
echo '<span>' . htmlspecialchars($method->getTitle()) . '</span>';
echo '</div>';
}

echo '</div>';
echo '</div>';
}
?>
Rate Limiting - API rate limits and monitoring

The Checkout API has the following limits:

  • 1000 payment creations per hour per project
  • 100 callback verifications per minute

Monitor rate limit headers in responses:

X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 950
X-RateLimit-Reset: 1697197200

For more information about integrating Paysera Checkout API:

Need Help?

If you encounter any issues or have questions about these examples, please refer to our Obtaining Credentials guide or contact our support team.