php - 使用 Paypal Express 的 Omnipay

标签 php paypal omnipay

我有一个使用 Omnipay 重定向到 Paypal 快速结账的电子商务网站。它会正确地将用户重定向到 Paypal,并返回带有 payerID 和所有内容的成功消息。然而,它实际上并没有收取任何款项,也没有在我们的 paypal 账户上显示为已收取的任何款项。我不确定这是 paypal 问题还是 Omnipay 的配置问题。我想 Paypal 会处理这部分,但因为它不起作用(在我们的旧网站上它工作正常但我们不使用 Omnipay。)

    $gateway = Omnipay::gateway('paypal');

    //production
    $gateway->setUsername('11111111');
    $gateway->setPassword('1111111111');
    $gateway->setSignature('111111111');

    $cardInput = array(
        'firstName' => $info['first_name_bill'],
        'lastName' => $info['last_name_bill'],
        'billingAddress1' => $info['street_address_1_bill'],
        'billingAddress2' => $info['street_address_2_bill'],
        'billingPhone' => $info['phone_bill'],
        'billingCity' => $info['city_bill'],
        'billingState' => $info['state_bill'],
        'billingPostCode' => $info['zip_bill'],
        'shippingAddress1' => $info['street_address_1_ship'],
        'shippingAddress2' => $info['street_address_2_ship'],
        'shippingPhone' => $info['phone_ship'],
        'shippingCity' => $info['city_ship'],
        'shippingState' => $info['state_ship'],
        'shippingPostCode' => $info['zip_ship'],
    );

    $card = Omnipay::creditCard($cardInput);

    //live
    $response = Omnipay::purchase(
        array(
            'cancelUrl' => 'http://store.site.com/cart/cancel-payment',
            'returnUrl' => 'http://store.site.com/cart/successful-payment',
            'amount' => Input::get('total'),
            'currency' => 'USD',
            'card' => $card,
            'description' => 'Stuff'
        )
    )->send();

    if ($response->isSuccessful()) {
        return Redirect('cart/successful-payment');
    } elseif ($response->isRedirect()) {
        $response->redirect(); // this will automatically forward the customer
    } else {
        return Redirect::back()->with('error', 'There was a problem. Please try again.');
    }
} else {
    return Redirect::to('cart/successful-payment');
}

所以基本上这将做的是将他们重定向到 Paypal 进行付款,然后重定向回我们的商店。一切正常。他们可以输入他们的卡号,然后在提交后返回我们的商店。问题是在它返回后通过 paypal 没有任何反应。不交换订单或付款。

最佳答案

在您的返回函数中,执行此 URL 时调用的函数:http://store.site.com/cart/successful-payment您需要调用 completePurchase。像这样:

        $gateway = Omnipay::gateway('paypal');

        //production
        $gateway->setUsername('11111111');
        $gateway->setPassword('1111111111');
        $gateway->setSignature('111111111');
        $purchaseId = $_GET['PayerID'];
        $response = $gateway->completePurchase([
            'transactionReference' => $purchaseId
        ])->send();
        // .. check $response here.

关于php - 使用 Paypal Express 的 Omnipay,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25727921/

相关文章:

php - Symfony & Paypal = 错误

php - Omnipay PayPal Express 中是否存在信用卡功能?还是仅在 PayPal Pro 中?

php - 如何在 xampp shell 中运行 $curl?

php - Omnipay 与 PayPal 快速结账

php - 在 macOS 上更新 XAMPP 的 PHP 版本

php - 更改 Woocommerce 中产品循环上的 "view cart"产品覆盖按钮

php - 如何制作带有自定义字段的 PayPal 加密立即购买按钮?

php - Paypal 自适应支付 - 产品名称

php - 从多个数据库行构建 HTML 表 php

php - 在 PHP 中回显嵌套数组中的值