9

我在我的网站上使用了 Omnipay PayPal_Express 结帐脚本,当我为订单付款时一切正常,但订单未显示在 PayPal Sandbox 帐户中。

当我对 PayPal_Pro 使用相同的脚本时,它会显示出来。

我的代码如下:

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

我在 Sandbox 中创建了两个测试帐户,一个用于上述 API,一个用于支付。我尝试使用测试卡详细信息和登录信息付款,但订单详细信息未显示在帐户中。

任何人都可以帮忙吗?

4

1 回答 1

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

于 2014-03-05T10:38:39.990 回答