Skip to main content

Enbank - PHP example docs

Read on how the payment flow works first and the OpenAPI docs. Then look at the example code bellow.

Enbank Integration Documentation

<script src="http://pay.enbank.me/enbank-pay.min.js"></script>
<?php
# The url of the enbank backend sandbox.
$rootPath = "https://enbank-server-local.fly.dev";
# $rootPath = "https://pay.enbank.me"; # The prod url
function newTransaction($rootPath) {
$request_options = [
'http' => [
'method' => 'POST',
'header' => 'Content-type: application/json\r\n',
'content' => json_encode([
# The amount of the current payment.
'amount' => 9.99,
# The token of the merchant.
'token' => '###PRIVATE_TOKEN###',
# The description for the payment.
'description' => "My Enbank transaction",
# The currency of the payment.
'currency' => 'BGN',
# A url that will be sent a http GET request when the payment was completed.
'successCallback' => 'https://...',
# Additional flags for customizing the payment.
'flags' => (object)[
# For including the shopping cart items
/* 'lineItems' => [
[
'id' => 'itemId'
'amount' => {
'discount' => 0,
'subtotal' => 0,
'vat' => 0,
'vatCoefficient' => 0,
'total' => 9.99
}
'currency': 'BGN',
'description': 'Вафла'
'quantity': 2
]
], */
# To enable tips
// 'tip' => false
# To enable payment expiration
// 'timeOut' => 1673009212
]
])
]
];
$context = stream_context_create($request_options);
$responseText = file_get_contents("$rootPath/transactions/new", false, $context);
$response = json_decode($responseText);
return $response->transactionId;
}

$transactionId = newTransaction($rootPath);
echo "<enbank-pay transactionId=\"$transactionId\"></enbank-pay>";
# or you can redirect with
# header("Location: $rootPath/checkout/$transactionId"", true, 307);