问题是我在一定条件下使用laravel redirect将用户重定向到特定的外部URL,并且条件为true,但是重定向仅登录到网络中,并没有真正更改浏览器中的URL。我也尝试在纯PHP中使用标头函数,但没有帮助。
这是我的代码:
public function purchase(Request $request, Transaction $transaction, User $user_model)
{
$username = $request->input('username');
if (!isset($username)) {
$this->setMessage(400, 'پر کردن فیلد username الزامی است');
return response()->json(['status' => 'error', 'data' => $this->getMessage()]);
}
$user = $user_model->scopeGetUserId($username);
if ($user == null) {
$this->setMessage(404, 'کاربر یافت نشد');
return response()->json(['status' => 'error', 'data' => $this->getMessage()], 200);
}
$user_id = $user->id;
$diet_type_id = $request->input('diet_type_id');
$price = 100;
$Amount = $price; //Amount will be based on Toman - Required
$Description = "پرداخت مبلغ $price تومان برای دریافت رژیم از سلامتپاد"; // Required
$Email = 'm.esmiran@gmail.com'; // Optional
$Mobile = '09123456789'; // Optional
$CallbackURL = 'http://salamatpaad.com/test/public/api/verify/' . $user_id . '/' . $diet_type_id; // Required
$client = new SoapClient('https://ir.zarinpal.com/pg/services/WebGate/wsdl', array('encoding' => 'UTF-8'));
$result = $client->PaymentRequest(
array(
'MerchantID' => $transaction->scopeGetMerchantId(),
'Amount' => $Amount,
'Description' => $Description,
'Email' => $Email,
'Mobile' => $Mobile,
'CallbackURL' => $CallbackURL
)
);
//Redirect to URL You can do it also by creating a form
if ($result->Status == 100) {
return redirect()->to('https://www.zarinpal.com/pg/StartPay/' . $result->Authority);
} else {
echo 'ERR: ' . $result->Status;
}
}