Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PayPal Express Checkout with Omnipay not showing order in Sandbox account

I have used the Omnipay PayPal_Express checkout script on my site and everything works fine when I pay for an order except the order doesn't show in the PayPal Sandbox account.

It does show when I use the same script for PayPal_Pro.

My code is as follows:

use Omnipay\Omnipay;

// PayPal Express:

if(isset($_POST['paypalexpress'])) {

$gateway = GatewayFactory::create('PayPal_Express');
$gateway->setUsername('{myusername}');
$gateway->setPassword('{mypassword}');
$gateway->setSignature('{mysignauture}');
$gateway->setTestMode(true);

$response = $gateway->purchase(
array(
    'cancelUrl'=>'http://www.mysite.com/?cancelled',
    'returnUrl'=>'http://www.mysite.com/?success',
    'amount' =>  "12.99",
    'currency' => 'GBP',
    'Description' => 'Test Purchase for 12.99'
    )

 )->send();

$response->redirect();
}

I have created two test accounts in my Sandbox, one is for the above API and one I use to pay with. I have tried paying with the test card details and the login but the order detail doesn't show in the account.

Can anyone help?

like image 246
Pete Naylor Avatar asked Feb 26 '14 13:02

Pete Naylor


1 Answers

It looks like you're missing the completePurchase() part when Paypal returns to your returnUrl. My code assumes that you have the order details in a variable $order, but it may look something like this:

if(isset($_GET['success'])) {
    $response = $gateway->completePurchase(array(
        'transactionId' => $order->transaction,
        'transactionReference' => $order->reference,
        'amount' => $order->total,
        'currency' => $order->currency,
    ))->send();

    if ( ! $response->isSuccessful())
    {
        throw new Exception($response->getMessage());
    }
}

Let me know if you need any help retrieving the order details on return. It can be stored in a session before you redirect, or in a database. If you haven't done already, take a look at the example code: https://github.com/omnipay/example/blob/master/index.php

like image 195
beech Avatar answered Oct 29 '22 13:10

beech