0

当我使用函数 isPaymentComplete,并返回 $result 以获取付款信息​​时,用户会话结束,如何解决这个问题

paytabs是支付getway,我在我的项目中使用laravel护照,我使用paytabs getway的visa支付,支付过程完成后我使用API​​函数来获取交易,但是当我使用这个函数时,用户会话将过期并退出

支付宝控制器

<?php

namespace App\Http\Controllers;

use App\Order;
use App\Product;
use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
define("AUTHENTICATION", "https://www.paytabs.com/apiv2/validate_secret_key");
define("PAYPAGE_URL", "https://www.paytabs.com/apiv2/create_pay_page");
define("VERIFY_URL", "https://www.paytabs.com/apiv2/verify_payment");

class PaytabsController extends Controller
{
    private $merchant_email;
    private $secret_key;


    public function __construct() {
        $this->merchant_email = "test@gmail.com";
        $this->secret_key = "gIHQJSHpoZTj8QFyRcA7zYXfsBcZ0fAgXh6GaO6zO0SWQxuIK5Pj3NzvoMuo15FYmMFwBM5pNYlEwQmgVczZZ9vnVZMW5rVreAYP";
    }



    public static function getInstance($merchant_email, $merchant_secretKey)
    {

        static $inst = null;
        if ($inst === null) {
            $inst = new PaytabsController();
        }
        $inst->setMerchant($merchant_email, $merchant_secretKey);
        return $inst;
    }




    public function go(){
        $price = session()->get('prices')['price_sar'];
/*
        if (!Auth::user()){
            return redirect('login');
        }
*/
        $pt = \App\Http\Controllers\PaytabsController::getInstance("test@gmail.com", "gIHQJSHpoZTj8QFyRcA7zYXfsBcZ0fAgXh6GaO6zO0SWQxuIK5Pj3NzvoMuo15FYmMFwBM5pNYlEwQmgVczZZ9vnVZMW5rVreAYP");
        $result = $pt->create_pay_page([
            "merchant_email" => "test@gmail.com",
            'secret_key' => "gIHQJSHpoZTj8QFyRcA7zYXfsBcZ0fAgXh6GaO6zO0SWQxuIK5Pj3NzvoMuo15FYmMFwBM5pNYlEwQmgVczZZ9vnVZMW5rVreAYP",
            'title' => "العنوان",
            'cc_first_name' => "الاسم الاول",
            'cc_last_name' => "الاسم الاخير",
            'email' => "example@email.com",
            'cc_phone_number' => "966",
            'phone_number' => "55555555555",
            'billing_address' => "شارع ",
            'city' => "الرياض",
            'state' => "الرياض",
            'postal_code' => "96600",
            'country' => "SAU",
            'address_shipping' => "شارع",
            'city_shipping' => "الرياض",
            'state_shipping' => "الرياض",
            'postal_code_shipping' => "96600",
            'country_shipping' => "SAU",
            "products_per_title"=> "خدمات",
            'currency' => "SAR",
            "unit_price"=> $price,
            'quantity' => "1",
            'other_charges' => "0",
            'amount' => $price,
            'discount'=>"0",
            "msg_lang" => "arabic",
            "reference_no" => "1231231",
            "site_url" => "http://127.0.0.1:8000/",
            'return_url' => "http://127.0.0.1:8000/payment_reference",
            "cms_with_version" => "Laravel",
        ]);



        if($result->response_code == 4012){
            return redirect($result->payment_url);
        }

        return $result->result;

    }




    function setMerchant($merchant_email, $merchant_secretKey) {
        $this->merchant_email = $merchant_email;
        $this->merchant_secretKey = $merchant_secretKey;
        $this->api_key = "";
    }

    function authentication(){
        $obj = json_decode($this->runPost(AUTHENTICATION, array("merchant_email"=> $this->merchant_email, "secret_key"=>  $this->secret_key)),TRUE);

        if($obj->response_code == "4000"){
            return TRUE;
        }
        return FALSE;

    }



    function create_pay_page($values) {
        $values['merchant_email'] = $this->merchant_email;
        $values['secret_key'] = $this->secret_key;
        $values['ip_customer'] = $_SERVER['REMOTE_ADDR'];
        $values['ip_merchant'] = isset($_SERVER['SERVER_ADDR'])? $_SERVER['SERVER_ADDR'] : '::1';
        return json_decode($this->runPost(PAYPAGE_URL, $values));
    }



    function verify_payment($payment_reference){
        $values['merchant_email'] = $this->merchant_email;
        $values['secret_key'] = $this->secret_key;
        $values['payment_reference'] = $payment_reference;
        return json_decode($this->runPost(VERIFY_URL, $values));
    }

    function runPost($url, $fields) {
        $fields_string = "";
        foreach ($fields as $key => $value) {
            $fields_string .= $key . '=' . $value . '&';
        }
        $fields_string = rtrim($fields_string, '&');
        $ch = curl_init();
        $ip = $_SERVER['REMOTE_ADDR'];

        $ip_address = array(
            "REMOTE_ADDR" => $ip,
            "HTTP_X_FORWARDED_FOR" => $ip
        );
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_VERBOSE, true);
        /*
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $ip_address);
        curl_setopt($ch, CURLOPT_POST, count($fields));
        curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_REFERER, 1);
*/
        $result = curl_exec($ch);
        curl_close($ch);

        return $result;
    }



    **public function isPaymentComplete(Request $request)
    {

        $pt = PaytabsController::getInstance("test@gmail.com", "gIHQJSHpoZTj8QFyRcA7zYXfsBcZ0fAgXh6GaO6zO0SWQxuIK5Pj3NzvoMuo15FYmMFwBM5pNYlEwQmgVczZZ9vnVZMW5rVreAYP");
        $result = $pt->verify_payment($request->payment_reference);

        if ($result->response_code == 100) {

            return view('website.approved',[
                'result' => $result
            ]);
        }
        return view('website.canceled');


    }**

}
4

0 回答 0