我试图让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 程序,尽管有警告,但我收到此错误:
致命错误:Class' Goetas \ Xsd \ XsdToPhp \ Jms \ Handler \ BaseTypesHandler'在第82行的/var/www/public/newsite/vendor/authorizenet/authorizenet/lib/net/authorize/api/controller/base/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
答案 0 :(得分:1)
为了解决这个问题,我想我是否有其他人报告过它,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].
用简单的英语,这意味着:
由于我们只是真正控制自己的要求,我想知道我们是否可以将我们自己的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致命错误:Class&#39; Goetas \ Xsd \ XsdToPhp \ Jms \ Handler \ BaseTypesHandler&#39;在第82行的/home/jon/Development/Personal/authorize.net/vendor/authorizenet/authorizenet/lib/net/authorize/api/controller/base/ApiOperationBase.php中找不到
我想知道这是否是自动加载失败,所以让我们看一下。我们想要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问题,请在那里创建一个问题并指出他们的答案。希望他们也可以换掉两个废弃的软件包,如果它们真的很好,他们将建立一个持续的集成系统,如果将来再次出现这种依赖性问题,它将会破裂。
答案 1 :(得分:0)
您正在安装的Authorize.Net PHP SDK的版本对过期组件有一些依赖性,以及一旦您运行&#,您将看到的一些与命名空间相关的问题34;电荷信用card.php&#34;脚本。最新版本的Authorize.Net PHP SDK(1.9.0)修复了这些问题。
所以,最大的问题就是&#34; Hello World&#34;上的示例composer.json。页面不安装较新版本,但安装较旧版本的SDK不再有效。
替换&#34; Hello World&#34;上的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
或删除&#34;供应商&#34;目录,然后重做composer install
。
我们希望在&#34; Hello World&#34;很快。
答案 2 :(得分:0)
我最近开始使用php中的authorize.net api,与作曲家一起安装,这是我的composer.json,它运行Hello World示例很好
{
"require": {
"symfony/console": "^3.3",
"authorizenet/authorizenet": ">=1.9.3"
}
}