1. Envoyez la requete de creation de session
Les champs obligatoires sont amount, currency et network. Utilisez d'abord des cles de test, puis passez aux cles de production apres l'activation mainnet.
cURL
curl -X POST https://xpayr.com/api/v1/payments \
-H "Authorization: Bearer sk_test_xxx" \
-H "Content-Type: application/json" \
-d '{
"amount": 49.90,
"currency": "USDT",
"network": "tron-mainnet",
"is_multi_chain": true,
"is_reusable": false,
"send_invoice_email": true,
"customer_email": "buyer@example.com",
"metadata": {
"order_id": "ORDER-1001",
"customer_id": "cus_123"
},
"success_url": "https://example.com/paid",
"cancel_url": "https://example.com/cancel",
"ipn_callback_url": "https://example.com/webhooks/xpayr"
}'
Node.js
const response = await fetch("https://xpayr.com/api/v1/payments", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.XPAYR_SECRET_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
amount: 49.90,
currency: "USDT",
network: "tron-mainnet",
is_multi_chain: true,
is_reusable: false,
send_invoice_email: true,
customer_email: "buyer@example.com",
metadata: { order_id: "ORDER-1001", customer_id: "cus_123" },
success_url: "https://example.com/paid",
cancel_url: "https://example.com/cancel",
ipn_callback_url: "https://example.com/webhooks/xpayr"
})
});
const session = await response.json();
console.log(session.payment_url);
PHP
$payload = [
'amount' => 49.90,
'currency' => 'USDT',
'network' => 'tron-mainnet',
'is_multi_chain' => true,
'is_reusable' => false,
'send_invoice_email' => true,
'customer_email' => 'buyer@example.com',
'metadata' => ['order_id' => 'ORDER-1001', 'customer_id' => 'cus_123'],
'success_url' => 'https://example.com/paid',
'cancel_url' => 'https://example.com/cancel',
'ipn_callback_url' => 'https://example.com/webhooks/xpayr',
];
$ch = curl_init('https://xpayr.com/api/v1/payments');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('XPAYR_SECRET_KEY'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode($payload),
]);
$session = json_decode(curl_exec($ch), true);
curl_close($ch);
echo $session['payment_url'] ?? 'No payment URL returned';
2. Redirigez vers l'URL de paiement renvoyee
{
"id": "ps_abc123",
"object": "payment_session",
"amount": "49.90",
"currency": "USDT",
"network": "tron-mainnet",
"status": "pending",
"payment_url": "https://xpayr.com/test/ps_abc123",
"livemode": false
}