user2791235
user2791235

Reputation: 11

PAYPAL RESTful API execute call occasional error

I have fully integrated my website with paypal using paypal RESTful's API PHP SDK. Now my problem is every once in a while on the payment process, once the user approves the payment and it comes back to my website for execution, the API execution request comes back with the following responses from paypal. The HTTP response code's in these scenarios are 400 and 500. Below I have listed the error name and error message which comes as a part of the JSON response I get form paypal on execute action (https://api.paypal.com/v1/payments/payment/PAY-xxxxxxxxxxxxxxxxxxxxxxxxxx/execute):

400 PAYMENT_NOT_APPROVED_FOR_EXECUTION,Payer has not approved payment 500 INTERNAL_SERVICE_ERROR,An internal service error has occurred

In terms of the code I use to make that call I have added the function which executes the payment. I should add that this is working in 98% of times. Below is the code:

public function getExecute()
{
    // Payment is cancelled
    if (!(Input::get('success') && Input::get('success') == 'true')) 
        return $this->runPaymentExitProcess();

    // No paymentId
    if (!Session::has('paymentId')) 
        return "No payment id to execute";

    $paymentId = Session::get('paymentId');


    $this->payment = Payment::get($paymentId, $this->apiContext);

    // The payer_id is added to the request query parameters when the user is redirected from paypal back to your site
    $this->execution->setPayer_id(Input::get('PayerID'));

    $response = $this->payment->execute($this->execution, $this->apiContext);


    // Check for paypal errors
    if (isset($response->name)) {
        // When we have a paypal error
        if ($this->hasPaypalError($response)) {
            $error = array('name' => $response->name, 'message' => $response->message);


    Session::put('error', $error);

            return (MODE == 'LIVE') ? Redirect::to('/paypalerror') : Redirect::to('/paypalerror'.MODE_PARAM);
            die;
        }   
    }   

    // Unset session
    Session::forget('paymentId');

    // execution successful
    if ($this->addPaymentIdToUser($paymentId))
        return (MODE == 'LIVE') ? Redirect::to('/') : Redirect::to('/'.MODE_PARAM);

}

The code is in laravel. Please note that the $this->apiContext is set in the constructor of the class. Also this is the function is the success url which is set in the API under redirect_urls.

Can someone please help me figure out if this issue is coming from my side or Paypal's side?

Upvotes: 1

Views: 1199

Answers (1)

Finn K
Finn K

Reputation: 620

For the 400 error, this would occur if the user decided not to approve the payment. If you think the payment was actually approved in the web flow then that would be an issue to look into further.

Can you provide the debugId and approximate time (with timezone, or GMT) of a 500 internal server error response, and a 400 if you believe the payment was actually approved by user.

Upvotes: 0

Related Questions