skip to Main Content

In phone pe intergration i am getting error.i have used the below code.Undefined property: stdClass::$data
this is the error code i am getting.please give me solution for this problem.else please suggest the best package laravel for phonepe gateway integration

`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);`

THis is the code i have used but getting error error
Undefined property: stdClass::$data like this. i

2

Answers


  1. You are getting the error Undefined property: stdClass::$data because you have defined the variable as data instead of $data.

    define your variable like below,

    $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',
            ),
    );
    
    Login or Signup to reply.
  2. You should first check the response of the $rData variable to ensure you are receiving the correct data.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search