‘I made a successful payment but can’t call the callback page? Or is there something wrong that I don’t know about?
setting paystack
I want after making payment to go to verify.php page but it’s not possible, or is it because I’m using localhost
Help me’
pay.php
<?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);
verify.php
i want to go to this page affter payment but it doesn’t do that
<?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();
New contributor
Tuấn Anh Nguyễn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.