Forwarding When Payment Execution Complete

jasonk21
Contributor
Contributor

Hello All --

 

I am new to the Paypal API, and am using the PHP v2 API for integration into our site.  I have the payments executing properly, however I am having an issue getting the application to re-direct to another page when completed.  Instead, what I always get is the original route with a get request containing the paymentId, token, and payerId.  I have spent a bunch of time trying to find the solution - including if there are other urls I should pass in when I create the payment, but I only see the option to set the return and cancel urls. Any help is appreciated!

 

Thank you!

Login to Me Too
2 REPLIES 2

MTS_Andre
Moderator
Moderator

Hi Jasonk21, when you create an order you can set a return URL and a cancel return URL as you said ("but I only see the option to set the return and cancel urls"). The return URL is the one which re-directs to a page on your website once the payment completed.

 

Can you specify when you say "to re-direct to another page when completed", do you mean the return URL we were talking above or a different one? Thanks.

Login to Me Too

jasonk21
Contributor
Contributor

Hello @MTS_Andre --

 

Thank you for the quick reply!  Currently, I was following the tutorial at https://medium.com/justlaravel/how-to-integrate-paypal-payment-gateway-in-laravel-695063599449 and I get to the step where the payment creates successfully, and I get the approvalUrl back.  The approval URL in my code (and as shown in the tutorial) then redirects to the new URL route in my application for executing the payment.   The assumption that I am making from my interpretation of the tutorial is the returnUrl does not redirect to a route that shows the order successfully completed, but instead is to return a route to execute the created payment.  This interpretation appears to be successful, and that route is followed, with funds showing they were moved and the payment successfully executing.  However, after the execute command successfully executes, and I get a $results object back, I attempt to redirect to a new route (also on my site) which is a confirmation page indicating that the customer has successfully completed the transaction.  In the tutorial, they are at the code snippets as shown:

 

$payment = Payment::get($payment_id, $this->_api_context);
$execution = new PaymentExecution();
$execution->setPayerId(Input::get('PayerID'));
/**Execute the payment **/
$result = $payment->execute($execution, $this->_api_context);
if ($result->getState() == 'approved') {\Session::put('success', 'Payment success');
return Redirect::route('/');
}

Sadly, that Redirect::route('/') (for me, it is actually Redirect::route('cart.confirmation'), but I am not getting any errors, so I do not believe this is the error location) never executes.  Instead I get stuck on a blank page with the payer_id, payment_id, and token in the url path.  

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.