<?php
// Configuração
$apiKey = 'sua_chave_api_aqui';
$baseUrl = 'https://api.zeldax.com';
// Criar pagamento
function criarPagamento($valor, $descricao) {
global $apiKey, $baseUrl;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "$baseUrl/api/payment/create");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
'amount' => $valor,
'description' => $descricao
]));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $apiKey,
'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
// Consultar pagamento
function consultarPagamento($paymentId) {
global $apiKey, $baseUrl;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "$baseUrl/api/payment/$paymentId");
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $apiKey
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
// Webhook para receber notificações
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$json = file_get_contents('php://input');
$data = json_decode($json, true);
// Processar evento
if ($data['event'] === 'payment.completed') {
$paymentId = $data['payment_id'];
$amount = $data['amount'];
// Atualizar seu banco de dados
}
}
?>