【问题标题】:authorize.net PHP Hello World bugauthorize.net PHP Hello World 错误
【发布时间】:2017-03-20 07:34:46
【问题描述】:

我正在尝试让PHP Hello World example 工作。我从 authorize.net 站点下载了代码,并使用了 Composer 和给定的 composer.json 文件。

当我运行命令 composer update 时,我收到一条警告消息:

goetas/xsd2php 包被废弃了,你应该避免使用它。请改用 goetas-webservices/xsd2php。

goetas/xsd-reader 包被废弃了,你应该避免使用它。请改用 goetas-webservices/xsd-reader。

尽管有警告,我还是尝试运行 charge-credit-card.php 程序,但出现此错误:

致命错误:在 /var/www/public/newsite/vendor/authorizenet/authorizenet/lib/net/authorize/api/controller/base/ 中找不到类 'Goetas\Xsd\XsdToPhp\Jms\Handler\BaseTypesHandler'第 82 行的 ApiOperationBase.php

我尝试纠正 composer.json 文件以消除该错误,但我只是给自己挖了一个更深的洞。

这是 composer.json 文件供参考。

{  
"require": 
       {  "php": ">=5.2.0",  
           "ext-curl": "*",  
           "authorizenet/authorizenet": "1.8.8",  
           "jms/serializer": "xsd2php-dev as 0.18.0"},
"require-dev": 
           {  
                   "goetas/xsd2php": "2.*@dev",  
                   "goetas/xsd-reader": "2.*@dev"},
"repositories": 
            [{    
                     "type": "vcs",    
                     "url": "https://github.com/goetas/serializer.git"    
}]}

这是我正在运行的 PHP 程序...

<?php
require 'vendor/autoload.php'; 
use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;
define("AUTHORIZENET_LOG_FILE","phplog");

// Common setup for API credentials  
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();   
$merchantAuthentication->setName("123456789");   
$merchantAuthentication->setTransactionKey("abcdefghijklmnop"); 
$refId = 'ref' . time();

// Create the payment data for a credit card
$creditCard = new AnetAPI\CreditCardType();
$creditCard->setCardNumber("4111111111111111" );  
$creditCard->setExpirationDate( "2038-12");
$paymentOne = new AnetAPI\PaymentType();
$paymentOne->setCreditCard($creditCard);

// Create a transaction
$transactionRequestType = new AnetAPI\TransactionRequestType();
$transactionRequestType->setTransactionType("authCaptureTransaction");   
$transactionRequestType->setAmount(151.51);
$transactionRequestType->setPayment($paymentOne);
$request = new AnetAPI\CreateTransactionRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$request->setRefId( $refId);
$request->setTransactionRequest($transactionRequestType);
// if I comment out the line below, no error occurs
$controller = new AnetController\CreateTransactionController($request);
//  $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);   

echo "<p>Hello there 10. The reference id is " . $refId . "</p>";
?>

这是运行 composer install 的控制台输出

Loading composer repositories with package information
Reading composer.json of jms/serializer (0.16.0)      
Reading composer.json of jms/serializer (0.15.0)
Reading composer.json of jms/serializer (0.14.0)
Reading composer.json of jms/serializer (0.13.0)
Reading composer.json of jms/serializer (0.12.0)
Reading composer.json of jms/serializer (0.11.0)
Reading composer.json of jms/serializer (event-sdispatcher)
Reading composer.json of jms/serializer (graph-refactor)   
Reading composer.json of jms/serializer (master)        
Reading composer.json of jms/serializer (ok-for-lignano)
Reading composer.json of jms/serializer (patch-1)       
Reading composer.json of jms/serializer (psr4)   
Reading composer.json of jms/serializer (remove-hndl)
Reading composer.json of jms/serializer (serializer-master)
Reading composer.json of jms/serializer (xsd2php)

Updating dependencies (including require-dev)

   - Installing doctrine/lexer (v1.0.1)
    Loading from cache

   - Installing doctrine/annotations (v1.3.0)
     Loading from cache

   - Installing phpoption/phpoption (1.5.0)
    Loading from cache

   - Installing phpcollection/phpcollection (0.5.0)
    Loading from cache

   - Installing jms/parser-lib (1.0.0)
    Loading from cache

   - Installing jms/metadata (1.5.1)
    Loading from cache

   - Installing jms/serializer (dev-xsd2php f339d96)
    Cloning f339d96f7e359e2837ed8b752348cc84823a9966

   - Installing goetas-webservices/xsd-reader (v0.1.2)
    Loading from cache

   - Installing zendframework/zend-eventmanager (3.0.1)
    Loading from cache

   - Installing zendframework/zend-code (2.6.3)
    Loading from cache

   - Installing doctrine/inflector (v1.1.0)
    Loading from cache

   - Installing symfony/yaml (v3.1.6)
    Loading from cache

   - Installing psr/log (1.0.2)
    Loading from cache

   - Installing symfony/debug (v3.1.6)
    Loading from cache

   - Installing symfony/polyfill-mbstring (v1.2.0)
    Loading from cache

   - Installing symfony/console (v3.1.6)
    Loading from cache

   - Installing goetas/xsd2php (dev-master 7e1ab0a)
    Cloning 7e1ab0a2d007991b0c6d326e9f67ec90c020b5e5

   - Installing goetas/xsd-reader (dev-master c5bcc02)
    Cloning c5bcc02d1a07f26533991e7b0d6c51a98d78c02c

   - Installing authorizenet/authorizenet (1.8.8)
    Loading from cache

    zendframework/zend-eventmanager suggests installing container-interop/container-interop (^1.1.0, to use the lazy listeners feature)

    zendframework/zend-eventmanager suggests installing zendframework/zend-stdlib (^2.7.3 || ^3.0, to use the FilterChain feature)

    zendframework/zend-code suggests installing zendframework/zend-stdlib (Zend\Stdlib component)

    symfony/console suggests installing symfony/event-dispatcher ()

    symfony/console suggests installing symfony/process ()

    authorizenet/authorizenet suggests installing phpdocumentor/phpdocumentor (For generating API documentation)

    Package goetas/xsd2php is abandoned, you should avoid using it. Use goetas-webservices/xsd2php instead.

    Package goetas/xsd-reader is abandoned, you should avoid using it. Use goetas-webservices/xsd-reader instead.

    Writing lock file

    Generating autoload files

【问题讨论】:

  • .. 通常是一个有效的结构——它在目录树上向上一层。在您的情况下,解析为/var/www/public/newsite/vendor/authorizenet/authorizenet/lib/net/authorize/api/contract/v1/MerchantAuthenticationType.php。您是否会在服务器上检查您的项目以查看该路径在什么时候不存在,并在这里告诉我们?
  • 可能是您的composer update 运行不正确。在项目文件夹中,使用 rm -rf vendor 销毁 vendor 文件夹并再次运行 Composer 命令,并将整个输出粘贴到问题中。
  • @halfer 谢谢,你在这里是正确的。我没有注意到该路径在 authorizenet 处发生故障,该路径不在供应商之下并且无处可寻。正如您所说,这可能是作曲家的问题。我实际上已经尝试了两个不同的 composer.json 文件,今天我看到了第三个看起来更简单的文件。我会试试那个,然后告诉你结果如何。
  • @halfer 我正在使用来自这里的 composer.json 文件:link 这是来自 Authorize.net sdk-php GIT 存储库。我注意到“require”对象中没有"authorizenet/authorizenet": "1.9.0",条目。 (就像在主存储库页面上的 composer.json 文件的描述中一样)。我尝试将它添加到这个 composer.json 文件中,但它根本没有运行,发现冲突。
  • @halfer 冲突是Your requirements could not be resolved to an installable set of packages. Problem 1 - Installation request for authorizenet/authorizenet dev-master -&gt; satisfiable by authorizenet/authorizenet[dev-master]. - Can only install one of: authorizenet/authorizenet[1.9.0, dev-master]. - Installation request for authorizenet/authorizenet 1.9.0 -&gt; satisfiable by authorizenet/authorizenet[1.9.0]. 我不知道要使用什么 composer.json 文件。或者也许我只是做错了......似乎这应该工作。

标签: php authorize.net


【解决方案1】:

我最近开始使用 php 中的 authorize.net api,与 composer 一起安装,这是我的 composer.json,它可以很好地运行 Hello World 示例

{
"require": {
    "symfony/console": "^3.3",
    "authorizenet/authorizenet": ">=1.9.3"    
}
}

【讨论】:

    【解决方案2】:

    您正在安装的 Authorize.Net PHP SDK 版本有几个对过期组件的依赖关系,以及在运行“charge-credit-card”时遇到的一些与命名空间相关的问题.php”脚本。最新版本的 Authorize.Net PHP SDK (1.9.0) 修复了这些问题。

    所以,最大的问题是“Hello World”页面上的示例 composer.json 没有安装新版本,而是安装了不再工作的旧版本 SDK。

    将“Hello World”页面上的 composer.json 示例替换为以下内容应该可以正常工作:

    {
        "require": {
                "authorizenet/authorizenet": "1.9.0",
                "jms/serializer": "dev-serializer-master as 1.0"
        },
            "repositories": [
            {
                 "type": "vcs",
                 "url": "https://github.com/goetas/serializer.git"
            }
        ]
    }
    

    只需替换composer.json,做composer update或删除“vendor”目录,然后重做composer install

    希望我们很快会在“Hello World”页面上对此进行更改。

    【讨论】:

      【解决方案3】:

      为了解决这个问题,我想看看有没有其他人报告过,so I had a search about in GitHub。这表明this bug report 听起来完全正确:

      GoetasWebservices\Xsd\XsdToPhpRuntime\Jms\Handler\BaseTypesHandler 不存在了吗?

      针对此,作者点to this documentation使用Composer解决不满足的依赖。所以我修改了composer.json 以添加缺失的行(并通过a formatter 运行它):

      {
        "require": {
          "php": ">=5.2.0",
          "ext-curl": "*",
          "authorizenet/authorizenet": "1.8.8",
          "jms/serializer": "xsd2php-dev as 0.18.0",
          "goetas-webservices/xsd2php-runtime":"^0.2.2"
        },
        "require-dev": {
          "goetas/xsd2php": "2.*@dev",
          "goetas/xsd-reader": "2.*@dev"
        },
        "repositories": [
          {
            "type": "vcs",
            "url": "https://github.com/goetas/serializer.git"
          }
        ]
      }
      

      不幸的是,运行 composer install 会导致依赖冲突:

      Updating dependencies (including require-dev)              
      Your requirements could not be resolved to an installable set of packages.
      
        Problem 1
          - Installation request for jms/serializer xsd2php-dev as 0.18.0 -> satisfiable by jms/serializer[dev-xsd2php].
          - goetas-webservices/xsd2php-runtime v0.2.2 requires jms/serializer ^1.2 -> satisfiable by jms/serializer[1.4.x-dev].
          - Can only install one of: jms/serializer[1.4.x-dev, dev-xsd2php].
          - Installation request for goetas-webservices/xsd2php-runtime ^0.2.2 -> satisfiable by goetas-webservices/xsd2php-runtime[v0.2.2].
      

      用简单的英语来说,这意味着:

      • xsd2php-runtime 希望序列化程序为 1.2
      • 我们已在 0.18.0 请求序列化程序

      由于我们只真正控制自己的要求,我想知道我们是否可以将自己对 serializer 的请求提高到 1.2,因此:

      {
        "require": {
          "php": ">=5.2.0",
          "ext-curl": "*",
          "authorizenet/authorizenet": "1.8.8",
          "jms/serializer": "xsd2php-dev as 1.2",
          "goetas-webservices/xsd2php-runtime":"^0.2.2"
        },
        "require-dev": {
          "goetas/xsd2php": "2.*@dev",
          "goetas/xsd-reader": "2.*@dev"
        },
        "repositories": [
          {
            "type": "vcs",
            "url": "https://github.com/goetas/serializer.git"
          }
        ]
      }
      

      这有点冒险,因为我们不知道这是否会导致 Authorize.net 演示脚本运行时失败,但至少现在可以运行安装。然而不幸的是,出现了相同的运行时错误:

      PHP 致命错误:在 /home/jon/Development/Personal/authorize.net/vendor/authorizenet/authorizenet/lib/net/authorize/api 中找不到类 'Goetas\Xsd\XsdToPhp\Jms\Handler\BaseTypesHandler' /controller/base/ApiOperationBase.php 第 82 行

      我想知道这是否是自动加载失败,所以让我们看看。我们想要Goetas\Xsd\XsdToPhp\Jms\Handler\BaseTypesHandler,但是如果我们查看我们的新依赖类,就会发现命名空间已更改为GoetasWebservices\Xsd\XsdToPhpRuntime\Jms\Handler\BaseTypesHandler。通常我们只是将版本 0.2.2 更改为更早的版本,但是如果您查看at the release history,最早的版本是 0.1.0,它是在命名空间更改后推送的。

      所以此时我们有两个选择:

      • goetas-webservices/xsd2php-runtime 添加为 VCS 依赖项并指定要在其中签出的 Git 提交哈希(这将导致库过时且可能不受支持);
      • 修改 authorizenet 依赖项中所需的库,然后请 Authorise.net 人员在上游修改它(更好,但需要他们的合作,这可能会阻碍您的进度)。

      我的观点是,本应该是“快速入门”的指南,已经被 Authorize.net 放弃了,如果搜索引擎的小侦探工作发现其他人有同样的困境,我不会感到惊讶。我个人会支持第二个选项,因为 ApiOperationBase 中的修复是微不足道的。

      更改这些行:

      use Goetas\Xsd\XsdToPhp\Jms\Handler\BaseTypesHandler;
      use Goetas\Xsd\XsdToPhp\Jms\Handler\XmlSchemaDateHandler;
      

      对这些:

      use GoetasWebservices\Xsd\XsdToPhpRuntime\Jms\Handler\BaseTypesHandler;
      use GoetasWebservices\Xsd\XsdToPhpRuntime\Jms\Handler\XmlSchemaDateHandler;
      

      现在程序将运行:

      $ php pay.php 
      <p>Hello there 10. The reference id is ref1478722350</p>
      

      我建议您联系 Authorize.net 并记录错误;如果他们使用 GitHub 问题,请在那里创建一个问题并将他们指向这个答案。希望他们也能把这两个废弃的包换掉,如果它们真的很好,他们会建立一个持续集成系统,如果这些依赖问题在未来再次出现,它将打破。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-12-31
        • 2010-10-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多