Laravel 支付网关集成错误

问题描述 投票:0回答:1

在手机 pe 集成中,我收到错误。我使用了以下代码。未定义的属性:stdClass::$data 这是我收到的错误代码。请给我解决这个问题的方法。否则请建议用于phonepe网关集成的最佳包laravel

`Undefined property: stdClass::$data

This is the error code i got.

data = array (
            'merchantId' => 'MERCHANTUAT',
            'merchantTransactionId' => uniqid(),
            'merchantUserId' => 'M1V4WG0RLQS6',
            'amount' => 1,
            'redirectUrl' => route('response'),
            'redirectMode' => 'POST',
            'callbackUrl' => route('response'),
            'mobileNumber' => '7708325543',
            'paymentInstrument' =>
                array (
                    'type' => 'PAY_PAGE',
                ),
        );

        $encode = base64_encode(json_encode($data));

        $saltKey = '9bbeca7d-96b9-4b59-b5ee-2ffa5d0763e9';
        $saltIndex = 1;

        $string = $encode.'/pg/v1/pay'.$saltKey;
        $sha256 = hash('sha256',$string);

        $finalXHeader = $sha256.'###'.$saltIndex;

        $url = "https://api-preprod.phonepe.com/apis/pg-sandbox/pg/v1/pay";

        $response = Curl::to($url)
            ->withHeader('Content-Type:application/json')
            ->withHeader('X-VERIFY:'.$finalXHeader)
            ->withData(json_encode(['request' => $encode]))
            ->post();

        $rData = json_decode($response);

        return redirect()->to($rData->data->instrumentResponse->redirectInfo->url);data = array (
            'merchantId' => 'MERCHANTUAT',
            'merchantTransactionId' => uniqid(),
            'merchantUserId' => '5555555',
            'amount' => 1,
            'redirectUrl' => route('response'),
            'redirectMode' => 'POST',
            'callbackUrl' => route('response'),
            'mobileNumber' => '11111111',
            'paymentInstrument' =>
                array (
                    'type' => 'PAY_PAGE',
                ),
        );

        $encode = base64_encode(json_encode($data));

        $saltKey = '9bbeca7d-96b9-4b59-b5ee-2ffa5d079';
        $saltIndex = 1;

        $string = $encode.'/pg/v1/pay'.$saltKey;
        $sha256 = hash('sha256',$string);

        $finalXHeader = $sha256.'###'.$saltIndex;

        $url = "https://api-preprod.phonepe.com/apis/pg-sandbox/pg/v1/pay";

        $response = Curl::to($url)
            ->withHeader('Content-Type:application/json')
            ->withHeader('X-VERIFY:'.$finalXHeader)
            ->withData(json_encode(['request' => $encode]))
            ->post();

        $rData = json_decode($response);

        return redirect()->to($rData->data->instrumentResponse->redirectInfo->url);`

这是我使用过的代码,但出现错误 未定义的属性:stdClass::$data 像这样。我

php laravel payment-gateway phonepe
1个回答
0
投票

您收到错误

Undefined property: stdClass::$data
,因为您已将变量定义为
data
而不是
$data

定义你的变量,如下所示,

$data = array (
    'merchantId' => 'MERCHANTUAT',
    'merchantTransactionId' => uniqid(),
    'merchantUserId' => 'M1V4WG0RLQS6',
    'amount' => 1,
    'redirectUrl' => route('response'),
    'redirectMode' => 'POST',
    'callbackUrl' => route('response'),
    'mobileNumber' => '7708325543',
    'paymentInstrument' =>
        array (
            'type' => 'PAY_PAGE',
        ),
);
© www.soinside.com 2019 - 2024. All rights reserved.