【发布时间】: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 -> 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 -> satisfiable by authorizenet/authorizenet[1.9.0].我不知道要使用什么 composer.json 文件。或者也许我只是做错了......似乎这应该工作。
标签: php authorize.net