PHP code example of telepay-app / telepay-php
1. Go to this page and download the library: Download telepay-app/telepay-php library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
telepay-app / telepay-php example snippets
use Telepay\Client;
$client = new Client(
apiKey: 'PUBLIC_API_KEY',
secret: 'SECRET',
);
// ๐ณ Új tranzakció létrehozása
$payload = [
'msisdn' => '+36301234567',
'description' => 'XYZ termék neve',
'success_message' => 'Köszönjük a vásárlást!',
'currency' => 'HUF',
'cart' => [
['name' => 'Teszt termék', 'price' => 3000, 'quantity' => 1]
]
];
$response = $client->createTransaction($payload);
print_r($response);
// ๐ Tranzakció lekérdezése (a visszatérítésekkel együtt)
$tx = $client->getTransaction('TRANSACTION_UUID');
// $tx['status'], $tx['refunded'] (bool), $tx['refunds'] (tömb)
// ๐งพ Teljes refund indítása
// A válaszban: ['queued' => true, 'transaction_id' => '...', 'refund_id' => '...']
$response = $client->refundTransaction('TRANSACTION_UUID');
print_r($response);
use Telepay\Webhooks\Verifier;
use Telepay\Exceptions\SignatureVerificationException;
$rawBody = file_get_contents('php://input');
$sigHeader = $_SERVER['HTTP_TELEPAY_SIGNATURE'] ?? '';
try {
Verifier::assertValid($sigHeader, $rawBody, 'WEBHOOK_SECRET'); // dob, ha érvénytelen
} catch (SignatureVerificationException $e) {
http_response_code(400);
exit;
}
$event = json_decode($rawBody, true);
switch ($event['event'] ?? null) {
case 'transaction.updated':
// státuszváltás (pl. completed/failed/expired) – $event['id'], $event['status']
break;
case 'transaction.refunded':
// VISSZATÉRÍTÉS – $event['id'] az EREDETI tranzakció,
// $event['refund'] = ['id','amount','currency','status','provider_tx_id']
$refund = $event['refund'];
// ... rendelés visszatérítettre állítása ...
break;
}
bash
composer