📜  ipn listener paypel php 代码示例

📅  最后修改于: 2022-03-11 14:54:17.345000             🧑  作者: Mango

代码示例1
// example for laravel
    public function listener(Request $request)
    {

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, 'https://ipnpb.sandbox.paypal.com/cgi-bin/webscr');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, "cmd=_notify-validate&" . http_build_query($_POST));
        $response = curl_exec($ch);
        curl_close($ch);


        if ($response == "VERIFIED") {

            $this->payerEmail = $_POST['payer_email'];
            $this->name = $_POST['first_name'] . " " . $_POST['last_name'];
            $this->price = $_POST['mc_gross'];
            $this->currency = $_POST['mc_currency'];
            $this->paymentStatus = $_POST['payment_status'];
            $this->amount = $_POST['quantity'];
            $this->purchase_id = $_POST['txn_id']; 
            //$this->other
            //$this->other1
            if ($this->paymentStatus == "Completed") {
                        // code if
            } else {
             
                // code else
            }
        }
    }