'支付成功但无法调用回调页面?还是有什么我不知道的问题? 设置薪资 我想在付款后转到 verify.php 页面,但这是不可能的,或者是因为我使用的是 localhost 帮助我'
<?php
require_once 'session.php';
require_once '../constants.php';
if (!isset($_SESSION['amount'], $_SESSION['email'])) {
@session_destroy();
header("Location: ../");
exit;
}
$pay = curl_init();
$email = $_SESSION['email'];
$amount = $_SESSION['amount'] . "00";
// die($amount);
curl_setopt_array($pay, array(
CURLOPT_URL => "https://api.paystack.co/transaction/initialize" ,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'amount' => $amount,
'email' => $email,
]),
CURLOPT_HTTPHEADER => [
"authorization: Bearer $paystack",
"content-type: application/json",
"cache-control: no-cache"
],
));
$response = curl_exec($pay);
$err = curl_error($pay);
if ($err) {
header("Location: individual.php?page=pay&error=payment&access=0");
exit();
}
$tranx = json_decode($response);
if (!$tranx->status or empty($tranx->status)) {
// đã xảy ra lỗi từ API
header("Location: individual.php?page=pay&error=payment&access=1");
exit();
}
header('Location: ' . $tranx->data->authorization_url);
我想在付款后转到此页面,但它没有这样做
<?php
require_once 'session.php';
require_once '../conn.php';
require_once '../constants.php';
if (isset($_GET['reference'])) {
$email = $_SESSION['email'];
$reference = $_GET['reference'];
$uid = $_SESSION['user_id'];
$pay = curl_init();
$paid = $_SESSION['original'];
$schedule_id = $_SESSION['schedule'];
$number = $_SESSION['no'];
$class = $_SESSION['class'];
$price = 0;
$amount = $_SESSION['amount'] . "00";
curl_setopt_array($pay, array(
CURLOPT_URL => "https://api.paystack.co/transaction/verify/" . rawurlencode($reference),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_HTTPHEADER => [
"accept: application/json",
"authorization: Bearer $paystack",
"cache-control: no-cache"
],
));
$response = curl_exec($pay);
$err = curl_error($pay);
if ($err) {
// đã xảy ra lỗi khi liên hệ với API Paystack
header("Location: individual.php?page=pay&error=payment");
exit();
}
if ($response) {
$result = json_decode($response, true);
// if ($resul->data->status == 'success'){
if (array_key_exists('data', $result)
&& array_key_exists('status', $result['data'])
&& ($result['data']['status'] === 'success')
&& ($result['data']['requested_amount'] === intval($amount))) {
//xác nhận quyền truy cập vào trang thanh toán thành công
$paid = substr($paid, 0, -2);
$reference = strtoupper($reference);
$ins = $conn->query("INSERT INTO payment (passenger_id, schedule_id, amount, ref, date) VALUES ('$user_id','$schedule_id', '$paid', '$reference', '$date')");
$code = genCode($schedule_id, $user_id, $class);
$seat = genSeat($schedule_id, $class, $number);
$payment_id = $conn->insert_id;
if ($payment_id > 0) {
$conn->query("INSERT INTO booked (payment_id, schedule_id, user_id, code, class, no, date, seat) VALUES ('$payment_id','$schedule_id', '$user_id', '$code', '$class', '$number', '$date' , '$seat')");
unset($_SESSION['discount']);
unset($_SESSION['amount']);
unset($_SESSION['original']);
unset($_SESSION['schedule']);
unset($_SESSION['no']);
unset($_SESSION['class']);
$_SESSION['pay_success'] = 'true';
$_SESSION['has_paid'] = 'true';
header("Location: individual.php?page=paid&now=true");
exit();
}
}
else {
header("Location: individual.php?page=pay&error=payment");
exit();
}
header("Location: individual.php?page=pay&error=payment");
exit();
}
header("Location: individual.php?page=pay&error=payment");
exit();
}
header("Location: individual.php?page=pay&error=payment");
exit();
您需要在初始化交易时将callback_url设置为您要重定向到的页面的URL。
...
$callbackUrl = "https://your-website.com/verify.php"; // Replace with your actual callback URL
curl_setopt_array($pay, array(
CURLOPT_URL => "https://api.paystack.co/transaction/initialize",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'amount' => $amount,
'email' => $email,
'callback_url' => $callbackUrl, // Add this line
]),
CURLOPT_HTTPHEADER => [
"authorization: Bearer $paystack",
"content-type: application/json",
"cache-control: no-cache"
],
));
...