Вот часть моего вебхука:
Код: Выделить всё
try {
$payload = json_decode($input);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new Exception('JSON decode error: ' . json_last_error_msg());
}
file_put_contents('webhook.log', print_r($payload, true), FILE_APPEND); // Log payload
if ($payload->eventType === 'PaymentSession.captured' || $payload->eventType === 'PaymentSession.approved') {
if (isset($payload->data->metadata->site)) {
$intent = $payload->data->id;
$site = $payload->data->metadata->site;
$oid = $payload->data->metadata->oid;
$endpoint = "https://".$site."/complete";
$params = array('pid' => $intent, 'oid' => $oid, 'u' => '1');
$url = $endpoint . '?' . http_build_query($params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
if (curl_errno($ch)) {
throw new Exception('cURL error: ' . curl_error($ch));
}
file_put_contents('curlResult.log', print_r($result, true), FILE_APPEND);
curl_close($ch);
echo $url;
} else {
echo "Metadata does not contain 'site' key.";
}
} elseif ($payload->eventType === 'Customer.created') {
file_put_contents('webhookcustomer.log', print_r($payload, true), FILE_APPEND);
} else {
echo "Event type is not supported.";
}
http_response_code(200);
echo "Webhook received and verified successfully.";
}
Код: Выделить всё
if(isset($_GET['u']))
{
$row = $db->selectRow(
'SELECT data FROM meta_data WHERE meta_id = ?
',
[$_GET['oid']]
);
$jsonBookingDetails = $row['data'];
$jsonBookingDetails = json_decode($jsonBookingDetails);
if ($jsonBookingDetails->type === "test") {
// webhook is 400 if completeTestBooking() is omitted
completeTestBooking("1234",$db);
savePayment($jsonBookingDetails->name, $address, $jsonBookingDetails->amount, $_GET['pid'], "Succeeded", $db);
}
}
Код: Выделить всё
function completeTestBooking($testId, $db)
{
$mail = new PHPMailer(true);
try {
//Server settings
$mail->CharSet = "UTF-8";
$mail->SMTPDebug = SMTP::DEBUG_OFF;
$mail->isSMTP();
$mail->Host = 'smtp.example.com';
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Username = 'info@co.uk';
$mail->Password = 'password';
//Recipients
$mail->setFrom('info@co.uk', 'Bookings');
$mail->addAddress('test@example.com');
//Content
$mail->isHTML(true);
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body in bold![/b]';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
return true;
} catch (Exception $e) {
return false;
}
}
Подробнее здесь: https://stackoverflow.com/questions/786 ... s-included