Omnipay Paypal Express redirect displays redirecting message

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());
}

Answers


  1. I recommend that you switch from PayPal_Express to PayPal_Rest. You will find better support for this in future.

  2. 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).


Need Your Help

Flash: Accessing private files from Amazon S3

flash security amazon-s3

I have flash (AIR) application running on a single controlled system (there is only one computer running it and nobody has access to it).

Add a UIMenuItem for a specific UITextView?

ios objective-c uitextview uimenucontroller uimenuitem

I have a lot of UITextViews in my screen and i want to add a new custom UIMenuItem for one of them.