PHP code example of tigusigalpa / telegram-wallet-php
1. Go to this page and download the library: Download tigusigalpa/telegram-wallet-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/ */
tigusigalpa / telegram-wallet-php example snippets
use Tigusigalpa\TelegramWallet\WalletPayClient;
use Tigusigalpa\TelegramWallet\DTO\CreateOrderRequest;
use Tigusigalpa\TelegramWallet\DTO\MoneyAmount;
// Initialize with your API key from Wallet Pay
$client = new WalletPayClient(apiKey: 'YOUR_STORE_API_KEY');
// Create a payment order
$order = $client->createOrder(new CreateOrderRequest(
amount: new MoneyAmount('USD', '9.99'),
description: 'Premium subscription for 1 month',
externalId: 'ORDER-' . uniqid(), // Your unique order ID
timeoutSeconds: 3600, // 1 hour to pay
customerTelegramUserId: 123456789, // Who can pay this order
autoConversionCurrency: 'USDT', // Receive payment in USDT
returnUrl: 'https://t.me/YourBot/YourApp',
customData: json_encode(['user_id' => 42])
));
// Send this link to your user — they'll pay right in Telegram!
echo $order->directPayLink;
use Tigusigalpa\TelegramWallet\Webhook\WebhookVerifier;
use Tigusigalpa\TelegramWallet\Enums\WebhookEventType;
$verifier = new WebhookVerifier('YOUR_STORE_API_KEY');
try {
// Verify signature and parse events in one call
$events = $verifier->verifyAndParse(
$_SERVER['REQUEST_METHOD'],
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH),
$_SERVER['HTTP_WALLETPAY_TIMESTAMP'],
file_get_contents('php://input'),
$_SERVER['HTTP_WALLETPAY_SIGNATURE']
);
foreach ($events as $event) {
if ($event->type === WebhookEventType::ORDER_PAID) {
// 🎉 Payment successful!
$customData = json_decode($event->payload->customData, true);
// Now you can:
// - Update your database
// - Grant premium access
// - Send a thank-you message
}
}
http_response_code(200);
echo 'OK';
} catch (InvalidWebhookSignatureException $e) {
http_response_code(401);
echo 'Invalid signature';
}
use Tigusigalpa\TelegramWallet\WalletPayClient;
use GuzzleHttp\Client;
// Simple — just your API key
$client = new WalletPayClient(apiKey: getenv('WALLETPAY_API_KEY'));
// Custom — bring your own HTTP client
$client = new WalletPayClient(
apiKey: getenv('WALLETPAY_API_KEY'),
timeout: 60,
httpClient: new Client(['verify' => true])
);
// Example: Store processed event IDs in database
if (ProcessedWebhookEvent::where('event_id', $event->eventId)->exists()) {
return; // Already processed
}
// Process the event
processPayment($event);
// Mark as processed
ProcessedWebhookEvent::create(['event_id' => $event->eventId]);