9

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?

Pete Naylor
  • 776
  • 2
  • 14
  • 33

1 Answers1

12

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

beech
  • 1,034
  • 8
  • 13
  • Thanks for this, I believe the "transactionId" is the token from PayPal but what is "transactionReference". Although I have passed a unique key to "transactionReference" and it works fine but I just need to be sure. Can you clarify? Thanks. – Shina Mar 09 '14 at 09:47
  • Hi Shina. It's a reference returned by Paypal. After sending the purchase request, but before the redirect you call $response->getTransactionReference() to get the reference. – beech Mar 09 '14 at 16:05
  • Thanks beech, now I have noticed that my token is the same as $response->getTransactionReference(). So what is transactionId? my random key? – Shina Mar 09 '14 at 22:13
  • Yep, you shouldn't be setting your own reference, I think you've got ID and reference the wrong way around. The ID can be anything unique you like though. – beech Mar 10 '14 at 10:10
  • Thanks for the clarification, I got the same response from the developer. – Shina Mar 10 '14 at 15:39
  • FYI, you should not store information in a session when completing your purchase through paypal express. Paypal will destroy the session. It's better to store the information in a database and then reference it with an id on return. – Lynx Sep 12 '14 at 14:28