I have Omnipay functioning perfectly in my payment gateway but when the system redirects to PayPal i get the following on screen before redirecting to PayPal:
Redirecting to https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&useraction=commit&token=-=TOKEN IS HERE-
What I'm wondering is if anyone knows how to stop the page displaying and redirect straight to PayPal without this middle page. My code for the redirect is below:
$gateway=GatewayFactory::create('PayPal_Express');
$gateway->setUsername(['username']);
$gateway->setPassword(['password']);
$gateway->setSignature(['signature']);
$gateway->setTestMode(['testing']);
$totalamount=number_format(['ordertotal'],2);
try{
$response=$gateway->purchase(
array(
'cancelUrl' => base_url('paymentMethod/'),
'returnUrl' => base_url('paypalexpress/confirm'),
'amount' => $totalamount,
'currency' => 'GBP'
)
)->send();
if($response->isSuccessful()){
print_r($response);
}elseif($response->isRedirect()){
$response->redirect();
}else{
echo $response->getMessage();
}
}
catch(\Exception $e){
$this->payment(1,$e->getMessage());
}
I recommend that you switch from PayPal_Express to PayPal_Rest. You will find better support for this in future.
Replace this code:
$response->redirect();
... with some code that is specific to your framework. e.g if you are using Laravel or Symfony they each have RedirectResponse classes. You can get the redirect URL from the response using $response->getRedirectUrl() instead of using the redirect() method (which is what is displaying the redirect flash on your screen).