phpphonepe

KEY_NOT_CONFIGURED error showing in phonepe php integration


I am trying to integrate phonepe payment gateway which is working correctly in UAT server but not working in production server. I am getting an error in response once payment is done.

public function request(Request $request)
    {
        $input = $request->all();
        $orderId = $input['orderId'];

        $firebaseController = new FirebaseController();
        $order = $firebaseController->getOrder($orderId);
        $price = $firebaseController->getPrice($order)*100;

        //Calculating UserRef i.e. userId from firebase field
        $fullUserDocPath = $order['userRef']->name();
        $userRef = explode('/', $fullUserDocPath)[6];

        $data = array (
          'merchantId' => getenv('PHONEPE_PRD_MERCHANT_ID'), //merchantid is correct
          'merchantTransactionId' => $orderId,
          'merchantUserId' => $userRef,
          'amount' => 100,
          'redirectUrl' => route('response'),
          'redirectMode' => 'POST',
          'callbackUrl' => route('response'),
          'mobileNumber' => substr($order['phoneNumber'], 3),
          'paymentInstrument' =>
           array (
            'type' => 'PAY_PAGE',
          ),
        );


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

        $saltKey = getenv('PHONEPE_PRD_SALT');
        $saltIndex = getenv('PHONEPE_PRD_SALT_INDEX');

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

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

        $response = Curl::to('https://api.phonepe.com/apis/hermes/pg/v1/pay')
                ->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);

    }

Now, I am being redirected to phonepe production server, and money is getting debited but the response I am recieving is not correct. Kindly help

I am getting below error response

"code" => "KEY_NOT_CONFIGURED",
"message" => "key not found for the merchant"

Solution

  • can confirm that it was a problem with different keys in development & production.

    here are the 4 things you need to change in .env.development & .env.production

    .env.development

    PHONEPE_URL=https://api-preprod.phonepe.com/apis/pg-sandbox/pg/v1/pay
    PHONEPE_MERCHANT_ID=PGTESTPAYUAT
    PHONEPE_API_KEY=099eb0cd-02cf-4e2a-8aca-3e6c6aff0399
    PHONEPE_KEY_INDEX=1
    

    it started working when i used the above in development.