Habitat
Habitat

Reputation: 709

Very new to authorize.net, trying to set up ARB, Set-up of initial sample page

trying to get ARB working on my site and I just threw together a test page to the sandbox account I made and a few things aren't making sense to me. I copied this sample code from the a.net getting started page and tried to get it to run on my site but no-dice, it seems that although AuthorizeNetARB.php extends AuthorizeNetRequest it still cannot find that class as per my error log:

[17-Jul-2015 15:14:40 America/Denver] PHP Fatal error:  Class 'AuthorizeNetRequest' not found in /home1/hospitl1/public_html/an-php/lib/AuthorizeNetARB.php on line 18
[17-Jul-2015 15:23:49 America/Denver] PHP Fatal error:  Class 'AuthorizeNetXMLResponse' not found in /home1/hospitl1/public_html/an-php/lib/AuthorizeNetARB.php on line 154

Heres the code I have so far for this test page:

<?php
include($_SERVER['DOCUMENT_ROOT']. '/an-php/lib/AuthorizeNetARB.php');
define("AUTHORIZENET_API_LOGIN_ID", "[removed]");
define("AUTHORIZENET_TRANSACTION_KEY", "[removed]");
$subscription                          = new AuthorizeNet_Subscription;
$subscription->name                    = "HDS Yearly Sub";
$subscription->intervalLength          = "1";
$subscription->intervalUnit            = "years";
$subscription->startDate               = "2015-07-17";
$subscription->totalOccurrences        = "12";
$subscription->amount                  = "12.99";
$subscription->creditCardCardNumber    = "6011000000000012";
$subscription->creditCardExpirationDate= "2018-10";
$subscription->creditCardCardCode      = "123";
$subscription->billToFirstName         = "Rasmus";
$subscription->billToLastName          = "Doe";

// Create the subscription.
$request         = new AuthorizeNetARB;
$response        = $request->createSubscription($subscription);
$subscription_id = $response->getSubscriptionId();
?>

I'm a little embarassed because I'm not new to php at all, but this api is really racking my brain. All the examples I've seen use what seems like a completely different SDK layout (with a central AuthorizeNet.php file) while the one I have here has been seemingly updated in a different manner with a new directory structure.

What is my sample page missing that would allow me to add a test subscription to my sandbox account?

Thanks

Upvotes: 1

Views: 648

Answers (1)

mim.
mim.

Reputation: 677

If you installed via composer you only need to

<?php
include_once '/path/to/vendor/autoload.php';
$request = new AuthorizeNetARB;

This will just work. I see you cloned it from github, in that case you need to include or require sdk's autoload file.

<?php
require '/path/to/anet_php_sdk/autoload.php';
$request = new AuthorizeNetARB;

Without autoload files it won't work. You can check how autoload works from php.net.

Upvotes: 2

Related Questions