第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

為什么我不能得到條帶 webhook 響應(yīng)

為什么我不能得到條帶 webhook 響應(yīng)

PHP
元芳怎么了 2022-10-28 15:24:51
所以我是 Stripe 的新手,我正在嘗試使用 webhook 獲取結(jié)帳付款意圖響應(yīng),我的目的是將結(jié)帳響應(yīng)發(fā)送到我的儀表板角度應(yīng)用程序,以便我可以保存有關(guān)客戶(hù)端的數(shù)據(jù)以及付款是否成功所以我使用了這段代碼:<?phprequire_once('vendor/autoload.php');\Stripe\Stripe::setApiKey('sk_test_xxx');$payload = @file_get_contents('php://input');$event = null;try {    $event = \Stripe\Event::constructFrom(        json_decode($payload, true)    );} catch(\UnexpectedValueException $e) {    // Invalid payload    http_response_code(400);    exit();}$payload = @file_get_contents('php://input');$event = null;try {    $event = \Stripe\Event::constructFrom(        json_decode($payload, true)    );} catch(\UnexpectedValueException $e) {    // Invalid payload    http_response_code(400);    exit();}print_r($payload);// Handle the eventswitch ($event->type) {    case 'payment_intent.succeeded':        $paymentIntent = $event->data->object; // contains a \Stripe\PaymentIntentecho 'success';        // Then define and call a method to handle the successful payment intent.        // handlePaymentIntentSucceeded($paymentIntent);        break;    case 'payment_intent.payment_failed':        $paymentMethod = $event->data->object; // contains a \Stripe\PaymentMethodecho 'failed';        // Then define and call a method to handle the successful attachment of a PaymentMethod.        // handlePaymentMethodAttached($paymentMethod);        break;    // ... handle other event types    default:        // Unexpected event type        http_response_code(400);        exit();}http_response_code(200); 然后我運(yùn)行結(jié)帳測(cè)試,完成并獲得成功頁(yè)面后,我嘗試訪問(wèn) www.website.com/webhooks.php 它總是給我一個(gè) 400 錯(cuò)誤,我不知道我在做什么是錯(cuò)的以及如何使用 webhook 我仍在研究它,所以有人可以告訴我該怎么做
查看完整描述

2 回答

?
ibeautiful

TA貢獻(xiàn)1993條經(jīng)驗(yàn) 獲得超6個(gè)贊

您可以使用Stripe CLI觸發(fā)測(cè)試事件到您的端點(diǎn),甚至可以通過(guò)轉(zhuǎn)發(fā)在本地進(jìn)行測(cè)試。您還可以從 Stripe 儀表板的 Webhook 部分發(fā)送測(cè)試 webhook。

您應(yīng)該添加一些日志記錄并寫(xiě)入文件以檢查要調(diào)試的事件處理。


查看完整回答
反對(duì) 回復(fù) 2022-10-28
?
胡子哥哥

TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超6個(gè)贊

所以我的代碼的問(wèn)題是我不應(yīng)該訪問(wèn) www.website.com/webhooks.php 來(lái)獲取我的響應(yīng),相反,我應(yīng)該將響應(yīng)存儲(chǔ)到數(shù)據(jù)庫(kù)或文件中,或者將其發(fā)送到這樣的地方:


    <?php

    require_once('vendor/autoload.php');

    \Stripe\Stripe::setApiKey('sk_test_xxxx');


    $payload = @file_get_contents('php://input');

    $event = null;


    try {

        $event = \Stripe\Event::constructFrom(

            json_decode($payload, true)

        );

    } catch(\UnexpectedValueException $e) {

        // Invalid payload

        http_response_code(400);

        exit();

    }


    $payload = @file_get_contents('php://input');

    $event = null;


    try {

        $event = \Stripe\Event::constructFrom(

            json_decode($payload, true)

        );

    } catch(\UnexpectedValueException $e) {

        // Invalid payload

        http_response_code(400);

        exit();

    }

    print_r($payload);

    // Handle the event

    switch ($event->type) {

        case 'payment_intent.succeeded':

            $paymentIntent = $event->data->object; // contains a \Stripe\PaymentIntent

    //echo 'success';

            // Then define and call a method to handle the successful payment intent.

            $msg='success';

            handlePaymentIntentSucceeded($paymentIntent,$msg);

            break;

        case 'payment_intent.payment_failed':

            $paymentMethod = $event->data->object; // contains a \Stripe\PaymentMethod


            $msg='failed';

            handlePaymentIntentSucceeded($paymentMethod,$msg);

            // Then define and call a method to handle the successful attachment of a PaymentMethod.

            // handlePaymentMethodAttached($paymentMethod);

            break;

        case 'payment_intent.canceled':

            $paymentMethod = $event->data->object; // contains a \Stripe\PaymentMethod


            $msg='canceled';

            handlePaymentIntentSucceeded($paymentMethod,$msg);

            // Then define and call a method to handle the successful attachment of a PaymentMethod.

            // handlePaymentMethodAttached($paymentMethod);

            break;

        // ... handle other event types

        case 'payment_intent.created':

            $paymentMethod = $event->data->object; // contains a \Stripe\PaymentMethod


            $msg='created';

            handlePaymentIntentSucceeded($paymentMethod,$msg);

            // Then define and call a method to handle the successful attachment of a PaymentMethod.

            // handlePaymentMethodAttached($paymentMethod);

            break;

        case 'payment_intent.processing':

            $paymentMethod = $event->data->object; // contains a \Stripe\PaymentMethod


            $msg='processing';

            handlePaymentIntentSucceeded($paymentMethod,$msg);

            // Then define and call a method to handle the successful attachment of a PaymentMethod.

            // handlePaymentMethodAttached($paymentMethod);

            break;


        default:

            // Unexpected event type

            http_response_code(400);

            exit();

    }


    http_response_code(200);



    function handlePaymentIntentSucceeded($paymentIntent,$status){



        $data=[

            'amount'=>$paymentIntent->amount,

            'name'=>$paymentIntent->charges->data[0]->billing_details->name,

            'email'=>$paymentIntent->charges->data[0]->billing_details->email,

            'error'=>$paymentIntent->last_payment_error->message,

            'status'=>$status


        ];

        $date=date("Y/m/d");


        header("Access-Control-Allow-Origin: *");

        header("Access-Control-Allow-Methods: PUT, GET, POST, DELETE");

        header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");

    // db credentials

        define('DB_HOST', 'localhost');

        define('DB_USER', 'root');

        define('DB_PASS', '');

        define('DB_NAME', 'database');


    // Connect with the database.

        function connect()

        {

            $connect = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);


            if (mysqli_connect_errno($connect)) {

                die("Failed to connect:" . mysqli_connect_error());

            }

            mysqli_set_charset($connect, "utf8");


            return $connect;

        }


        $con = connect();





        // Store data into a database .

        $sql = "INSERT INTO `ordre`( `amount`, `email`, `name`, `status`, `msg`, `date`) VALUES ({$data['amount']},'{$data['email']}','{$data['name']}','{$data['status']}',\"{$data['error']}\",'{$date}')";




        if(mysqli_query($con,$sql))

        {

            http_response_code(201);

//to check if the storage process is done and

            $myFile = "https://6537bee0.ngrok.io/file.txt";

            $myFileLink2 = fopen($myFile2, 'w+') or die("Can't open file.");

            $newnbord ='done';

            fwrite($myFileLink2, $newnbord);

            fclose($myFileLink2);

            return $newnbord ;

        }

        else

        {  http_response_code(422);

            // write error code in a file

            http_response_code(201);

            $myFile2 = "https://6537bee0.ngrok.io/file.txt";

            $myFileLink2 = fopen($myFile2, 'w+') or die("Can't open file.");

            $newnbord =mysqli_error($con).$sql

            ;

            fwrite($myFileLink2, $newnbord);

            fclose($myFileLink2);

            return $newnbord ;


        }



    }



查看完整回答
反對(duì) 回復(fù) 2022-10-28
  • 2 回答
  • 0 關(guān)注
  • 115 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)