Search code examples
codeigniterpaypal

PayPal JS SDK Checkout : fetch returns error 500 when switching from sandbox to live


The PayPal JS SDK works fine in sandbox mode, but in Live I keep receiving a 500 error.

I am successfully authorizing credit card payments using the SDK but an error message in https://www.paypal.com/sdk/js?client-id=xxfunding=credit,card&currency=MYR

throw new Error("Promise serialization is not implemented; nothing to deserialize")

I followed the PayPal guide and really can not see my mistake here:

public function paypal_capture()
{
       $gateway_data = $this->billing->gateway(4);

        $orderId = $this->input->post('orderID', true);
        $itype = $this->input->post('itype', true);


      $clientId =$gateway_data['key1']; //$paypal_conf['client_id'];
    $clientSecret =$gateway_data['key2'];//$paypal_conf['secret'];

       if($gateway_data['dev_mode'] == true)
    {
        $environment = new \PayPalCheckoutSdk\Core\SandboxEnvironment($clientId, $clientSecret);

    } else {
         $environment = new \PayPalCheckoutSdk\Core\ProductionEnvironment($clientId, $clientSecret);
    }

     $client = new \PayPalCheckoutSdk\Core\PayPalHttpClient($environment);

     $request = new \PayPalCheckoutSdk\Orders\OrdersCaptureRequest($orderId);
     $request->prefer('return=representation');
     try {

         $response = $client->execute($request);

           echo json_encode($response);

         $response = json_decode(json_encode($response), true);

         if (isset($response['result']) and $response['result']['intent'] == 'CAPTURE' and $response['result']['status'] == 'COMPLETED') {

             $note = 'INV '.$response['result']['purchase_units'][0]['reference_id'].' Paypal Payment #' . $response['result']['id'];




             $this->billing->paynow($response['result']['purchase_units'][0]['reference_id'],  $response['result']['purchase_units'][0]['amount']['value'], $note, 'Card',$itype);

         }
     }
      catch (HttpException $ex) {

         echo json_encode(array('status'=>'Error','message'=>'Code '.$ex->statusCode.' Contact to seller.'));

     }
}

enter image description here


Solution

  • In the PHP...

    if($gateway_data['dev_mode'] == true)
    

    ..ensure this configured value is set to false so that the code communicates with the PayPal live/production endpoints, as well as changing the clientId and secret to be from the an application from the "Live" tab of My Apps & Credentials