Reputation: 13
I'm trying to get the PHP Hello World example to work. I downloaded the code from the authorize.net site and I used Composer and the given composer.json
file.
When I run the command composer update, I get a warning message:
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.
I tried running the charge-credit-card.php program in spite of the warning, but I get this error:
Fatal error: Class 'Goetas\Xsd\XsdToPhp\Jms\Handler\BaseTypesHandler' not found in /var/www/public/newsite/vendor/authorizenet/authorizenet/lib/net/authorize/api/controller/base/ApiOperationBase.php on line 82
I tried my hand at correcting the composer.json file to get rid of that error, but I only dug myself a deeper hole.
Here's the composer.json file for reference.
{
"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"
}]}
And here's the PHP program I am running...
<?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>";
?>
Here is the console output from running 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
Upvotes: 1
Views: 1041
Reputation: 2093
I've recently started working with thie authorize.net api in php, installed with composer, here is my composer.json, which runs the Hello World example fine
{
"require": {
"symfony/console": "^3.3",
"authorizenet/authorizenet": ">=1.9.3"
}
}
Upvotes: 0
Reputation: 61
The version of the Authorize.Net PHP SDK that you're installing has a couple of dependencies on out of date components, as well as some namespace related problems that you're seeing once you run the "charge-credit-card.php" script. The latest version of the Authorize.Net PHP SDK (1.9.0) fixes these issues.
So, the big issue is just that the sample composer.json on the "Hello World" page doesn't install the newer version, but installs an older version of the SDK that no longer works.
Replacing the composer.json sample on the "Hello World" page with the following should make everything work just fine:
{
"require": {
"authorizenet/authorizenet": "1.9.0",
"jms/serializer": "dev-serializer-master as 1.0"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/goetas/serializer.git"
}
]
}
Just replace the composer.json, do composer update
or delete the "vendor" directory, then redo composer install
.
We'll hopefully get this changed on the "Hello World" page soon.
Upvotes: 0
Reputation: 20420
To solve this issue, I thought I'd see if anyone else had reported it, so I had a search about in GitHub. That revealed this bug report which sounds exactly right:
GoetasWebservices\Xsd\XsdToPhpRuntime\Jms\Handler\BaseTypesHandler does not exist any more?
In response to this, the author points to this documentation to solve unsatisfied dependencies using Composer. So I modified the composer.json
to add the missing line (and ran it through 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"
}
]
}
Unfortunately running composer install
results in a dependencies conflict:
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].
In plain English, this means that:
Since we only really control our own requirements, I wondered if we could bump up our own request for serializer
to 1.2, thus:
{
"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"
}
]
}
This is a bit risky since we do not know if this will cause a run-time failure in the Authorize.net demo script, but at least the install will run now. Unfortunately however the same runtime error is exhibited:
PHP Fatal error: Class 'Goetas\Xsd\XsdToPhp\Jms\Handler\BaseTypesHandler' not found in /home/jon/Development/Personal/authorize.net/vendor/authorizenet/authorizenet/lib/net/authorize/api/controller/base/ApiOperationBase.php on line 82
I wondered if this was an autoload failure, so let's look at that. We want Goetas\Xsd\XsdToPhp\Jms\Handler\BaseTypesHandler
, but if we look at our new dependency class, it turns out that the namespace was changed to GoetasWebservices\Xsd\XsdToPhpRuntime\Jms\Handler\BaseTypesHandler
. Normally we would just change the version 0.2.2 to an earlier version, but if you look at the release history, the earliest release is 0.1.0, which was pushed after the namespace change.
So we have two options at this point:
goetas-webservices/xsd2php-runtime
as a VCS dependency and specify a Git commit hash to check out at (this will result in an outdated and probably unsupported library);authorizenet
dependency, and then ask the Authorise.net folks to modify it upstream (better, but requires their cooperation, which may hinder your progress).My opinion is that this guide, which ought to be "quick start", has been somewhat abandoned by Authorize.net, and I would not be surprised if a little search-engine detective work revealed other people with the same woes. I personally would plump for the second option, since the fix in ApiOperationBase
is trivial.
Change these lines:
use Goetas\Xsd\XsdToPhp\Jms\Handler\BaseTypesHandler;
use Goetas\Xsd\XsdToPhp\Jms\Handler\XmlSchemaDateHandler;
to these:
use GoetasWebservices\Xsd\XsdToPhpRuntime\Jms\Handler\BaseTypesHandler;
use GoetasWebservices\Xsd\XsdToPhpRuntime\Jms\Handler\XmlSchemaDateHandler;
Now the program will run:
$ php pay.php
<p>Hello there 10. The reference id is ref1478722350</p>
I would advise you to contact Authorize.net and log a bug; if they use GitHub issues, create an issue there and point them to this answer. Hopefully they will swap out the two abandoned packages as well, and if they are really good, they will set up a continuous integration system that will break if these kinds of dependency issues crop up again in the future.
Upvotes: 1