【问题标题】:How to call GetExpressCheckoutDetails from Omnipay/PayPal?如何从 Omnipay/PayPal 调用 GetExpressCheckoutDetails?
【发布时间】:2014-07-22 11:42:05
【问题描述】:

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

omnipay paypal express not returning address

receive more response data in ci-merchant library codeigniter

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

在此先感谢您提供任何帮助。

【问题讨论】:

    标签: php codeigniter paypal laravel-4 omnipay


    【解决方案1】:

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

    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. 在composer.json中添加psr-4autoload

      "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',
      

    现在更新就没有问题了

    【讨论】:

    • 警告:在实施这些步骤并使用“$gateway = new App\Omnipay\PayPal\ExtendedExpressGateway();”之后代替“Omnipay::create('PayPal_Express');”我发现 ExtendedExpressGateway::fetchExpressCheckoutDetail() 返回的信息与 Omnipay 内置的“$data = $gateway->fetchCheckout($params)->send()->getData();”相同所以这可能是不值得的麻烦。无论如何,如果您在 psr-4 自动加载器找不到 ExtendedExpressGateway 时遇到问题,请记住将“
    • 谢谢@ZackMorris,这帮了我很多忙,理想情况下应该是公认的最佳答案,请写一个完整的回复,这样我就可以投票了。使用这种方法的好处是,如果 payer_id 或 transaction_id 没有保存,您只有交易参考 id,这是您以编程方式获取这些详细信息的唯一方法。
    【解决方案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();
    

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

    【讨论】:

    • tomsowerby 在link 的拉取请求中实施了另一个解决方案。它有效,我希望它会被合并。
    【解决方案3】:

    Omnipay 不支持 GetExpressCheckoutDetails(目前)。目前有一个 pull request 对此开放。

    但它确实实现了GetTransactionDetails,您可能会觉得这很有用,因为它可以返回有关现有交易的大部分信息。

    【讨论】:

    • 拉取请求已经安静了几个月。知道延迟是什么吗?我尝试通过 completePurchase 调用 GetTransactionDetails,但它没有返回购买者的联系方式。
    • 只是这是一个很大的拉取请求,我真的很忙,所以没有时间自己做这项工作。如果它被分解为 GetExpressCheckoutDetails 的单独 PR,并且根据该线程中的 cmets 改进 API,那么合并将相当容易。
    猜你喜欢
    • 2021-02-09
    • 2014-02-07
    • 2015-04-08
    • 2018-11-16
    • 2019-11-09
    • 2013-04-17
    • 2014-11-01
    • 2014-03-29
    • 2013-09-13
    相关资源
    最近更新 更多