1

我需要接受来自 Laravel-4 应用程序的 PayPal Express 付款,因此我正在尝试确定 Omnipay 是否是最佳解决方案。症结在于它似乎没有实现 GetExpressCheckoutDetails,因此无法访问购买者的联系方式。我看过这些关于这个问题的讨论:

omn​​ipay paypal express 没有返回地址

在 ci-merchant 库 codeigniter 中接收更多响应数据

但是,两者都没有给出明确的解决方案。如果我使用 Omnipay,我是否还必须安装 PayPal 的 Classic API(在这种情况下,为什么要使用 Omnipay),或者我可以在 Omnipay 中实现 GetExpressCheckoutDetails,如果可以,如何实现?

提前感谢您对此的任何帮助。

4

3 回答 3

2

omnipay\paypal\ProGateway.php添加新功能

public function fetchExpressCheckoutDetail(array $parameters = array())
{
    return $this->createRequest('\Omnipay\PayPal\Message\FetchExpressCheckoutRequest', $parameters);
}

omnipay\paypal\src\Message添加新文件FetchExpressCheckoutRequest.php

namespace Omnipay\PayPal\Message;
class FetchExpressCheckoutRequest extends AbstractRequest
{
    public function getData()
    {
        $data = $this->getBaseData('GetExpressCheckoutDetails');

        $this->validate('transactionReference');
        $data['TOKEN'] = $this->getTransactionReference();
        $url = $this->getEndpoint()."?USER={$data['USER']}&PWD={$data['PWD']}&SIGNATURE={$data['SIGNATURE']}&METHOD=GetExpressCheckoutDetails&VERSION={$data['VERSION']}&TOKEN={$data['TOKEN']}";
        parse_str (file_get_contents( $url ),$output);
        $data = array_merge($data,$output);
        return $data;
    }
}

用法:

$response = $gateway->completePurchase($params)->send();
$data = $response->getData();
$gateway->fetchExpressCheckoutDetail(array('transactionReference'=>$data['TOKEN']))->getData();

这不会是最好的。但它有效。:)

于 2014-06-16T04:18:51.790 回答
0

基于基。回答我建议在应用程序中添加以下内容:

  1. 创建新路径app/omnipay/paypal/Message/
  2. 创建新文件app/omnipay/paypal/ExtendedExpressGateway.php

    namespace App\Omnipay\PayPal;
    
    use Omnipay\PayPal\ExpressGateway;
    
    /**
     * PayPal Express extended Class
     */
    class ExtendedExpressGateway extends ExpressGateway
    {
        public function getName()
        {
            return 'PayPal Express extended';
        }
    
        public function fetchExpressCheckoutDetail(array $parameters = array())
        {
            return $this->createRequest('\\App\\Omnipay\\PayPal\\Message\\FetchExpressCheckoutRequest', $parameters);
        }
    }
    
  3. 创建新文件app/omnipay/paypal/Message/FetchExpressCheckoutRequest.php

    namespace App\Omnipay\PayPal\Message;
    
    use Omnipay\PayPal\Message\AbstractRequest;
    
    class FetchExpressCheckoutRequest extends AbstractRequest
    {
        public function getData()
        {
            $data = $this->getBaseData('GetExpressCheckoutDetails');
    
            $this->validate('transactionReference');
    
            $data['TOKEN'] = $this->getTransactionReference();
            $url = $this->getEndpoint() . "?USER={$data['USER']}&PWD={$data['PWD']}&SIGNATURE={$data['SIGNATURE']}&METHOD=GetExpressCheckoutDetails&VERSION={$data['VERSION']}&TOKEN={$data['TOKEN']}";
            parse_str(file_get_contents($url), $output);
            $data = array_merge($data, $output);
    
            return $data;
        }
    }
    
  4. 添加到psr-4 autoloadcomposer.json

    "autoload": {
        "classmap": [
            ...
        ],
        "psr-4": {
            "App\\Omnipay\\PayPal\\": "app/omnipay/paypal/"
        }
    },
    
  5. 跑:

    php artisan dump-autoload
    
  6. 现在app/config/packages/ignited/laravel-omnipay/config.php你可以写:

    'driver' => '\\App\\Omnipay\\PayPal\\ExtendedExpressGateway',
    

现在当你更新将没有问题

于 2014-09-22T13:29:56.073 回答
0

Omnipay(尚)不支持 GetExpressCheckoutDetails。目前对此有一个拉取请求

但是,它确实实现了您可能会发现有用的GetTransactionDetails,因为它可以返回有关现有事务的大部分信息。

于 2014-06-03T16:19:26.007 回答