Reply
Highlighted
Member
Posts: 4
Registered: ‎09-08-2011
Accepted Solution

PHP ARB

So, this should not be too difficult I would not think to set up but I am having trouble. I now have a SSL all set up on my site and that works great, but everytime i try a PHP ARB request it does not work. I have tried the developer tools example as well as this link.

 

Can anyone offer me some suggestions as to wht i am doing wrong? I just can not imagine things should be this difficult to set up.

 

Thanks in advance everyone.


Accepted Solutions
Highlighted
Solution
Accepted by topic author tunespring11
‎08-21-2015 01:58 AM
Posts: 1,609
Topics: 15
Kudos: 201
Solutions: 121
Registered: ‎06-23-2011

Re: PHP ARB

(referring to the copy of my code)

 

I notice sandbox is still set to false. Are you running this on a live account? I'm also assuming the $GLOBALS values in the second line are correct login codes, and that you're filling in all the $_POST values correctly. You might try doing print_r($result) at the end to make sure it's actually making it there and not dying along the way for some strange reason.

View solution in original post


All Replies
Highlighted
Contributor
Posts: 23
Registered: ‎09-01-2011

Re: PHP ARB

When you say that it doesn't work, can you be more specific? Exactly what is happening?

 

I'm very new to this, too, but have learned a lot in the last couple of weeks (yes, the 15-minute integration has taken close to two weeks to get set up!). If you post the code you're working with, I (and/or one of the others) look through and see if I can figure out what's failing.

Highlighted
Member
Posts: 4
Registered: ‎09-08-2011

Re: PHP ARB

[ Edited ]

Thank you for the quick response. The code I tried from the SDK Can be found in the demo and below is the code I have from the other posted link in my thread.

 

<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
include("../../ts_site/processForms/file_with_errors.php");


// Include AuthnetCIM class. Nothing works without it!
require('AuthnetARB.class.php');
 
// Use try/catch so if an exception is thrown we can catch it and figure out what happened
try{
    // Set up the subscription. Use the developer account for testing..
    $subscription = new AuthnetARB('***', '*&#$%');
 
    // Set subscription information
    $subscription->setParameter('amount', 29.99);
    $subscription->setParameter('cardNumber', '4111111111111111');
    $subscription->setParameter('expirationDate', '2016-16');
    $subscription->setParameter('firstName', 'Johns');
    $subscription->setParameter('lastName', 'Conde');
    $subscription->setParameter('address', '123 Main Street');
    $subscription->setParameter('city', 'Townsville');
    $subscription->setParameter('state', 'NJ');
    $subscription->setParameter('zip', '12345');
    $subscription->setParameter('email', 'fakemail@example.com');
 
    // Set the billing cycle for every three months
    $subscription->setParameter('interval_length', 1);
    $subscription->setParameter('startDate', date("Y-m-d", strtotime("+ 1 months")));
 
    // Set up a trial subscription for three months at a reduced price
    $subscription->setParameter('trialOccurrences', 1);
    $subscription->setParameter('trialAmount', 0.00);
	
	//notices
	$subscription->setParameter('refID', 0.00);
	$subscription->setParameter('subscrName', 0.00);
	$subscription->setParameter('orderInvoiceNumber', 0.00);
	$subscription->setParameter('orderDescription', 0.00);
	$subscription->setParameter('customerId', 0.00);
	$subscription->setParameter('customerEmail', 0.00);
	$subscription->setParameter('customerPhoneNumber', 0.00);
	$subscription->setParameter('customerFaxNumber', 0.00);
	$subscription->setParameter('company', 0.00);
	$subscription->setParameter('shipCompany', 0.00);
	$subscription->setParameter('shipFirstName', 0.00);
	$subscription->setParameter('shipLastName', 0.00);
	$subscription->setParameter('shipAddress', 0.00);
	$subscription->setParameter('shipCity', 0.00);
	$subscription->setParameter('shipState', 0.00);
	$subscription->setParameter('shipZip', 0.00);
 
    // Create the subscription
    $subscription->createAccount();
 
    // Check the results of our API call
    if ($subscription->isSuccessful())
    {
        // Get the subscription ID
        $subscription_id = $subscription->getSubscriberID();
    }
    else
    {
		//echo $subscription;
        // The subscription was not created!
		echo '<br /><br />THIS DID NOT WORK<br /><br />';
    }
}catch (AuthnetARBException $e){
    echo $e;
    echo $subscription;
}
?>

 So everytime I try to process it, i get this notice "THIS DID NOT WORK". If there is a better method to doing form submission for ARB, I would love to have any suggestions. I agree, the 15 minute setup is not a reality. 

 

Where there settings in Authorize.net, that you needed to set? Testing mode is off.

 

 

Thanks again.

Highlighted
Posts: 1,609
Topics: 15
Kudos: 201
Solutions: 121
Registered: ‎06-23-2011

Re: PHP ARB

Be more helpful if we knew what error you were getting. Also, I notice that your code says "Include AuthnetCIM class. Nothing works without it!" and then includes ARB, and there are a number of other odd things as well. My suggestion is to look at the ARB.markdown file in the doc folder of your SDK, and also at the following code, which I know works because it's on an actual live web site I set up a few months ago. Note, incidently, that I calculate and fill in some of these $_POST values myself - it's obviously not good from a security standpoint to allow the user to directly set price or start date or so on without at least validating first.

 

$authorize = new AuthorizeNetARB(
    $GLOBALS['_authorize_id'], $GLOBALS['_authorize_key']);
$authorize->setSandbox(false);
// SET TO TRUE IF USING SANDBOX ACCOUNT

$subscription = new AuthorizeNet_Subscription;

$subscription->customerId = $idn;

$subscription->billToFirstName = $_POST['first'];
$subscription->billToLastName = $_POST['last'];
$subscription->billToCompany = $_POST['company'];
$subscription->billToAddress = $_POST['address'];
$subscription->billToCity = $_POST['city'];
$subscription->billToState = $_POST['state'];
$subscription->billToZip = $_POST['zip'];
$subscription->billToCountry = 'US';

$subscription->customerPhoneNumber = $_POST['phone'];
$subscription->customerEmail = $_POST['email'];

$subscription->name = "{$_POST['type']} Subscription";
$subscription->orderDescription = 'For ' . count($_POST['zips']) . " zip codes with {$population} total estimated population";
$subscription->amount = $_POST['price'];

$subscription->startDate = $_POST['payment_due'];
$subscription->intervalLength = '1';
$subscription->intervalUnit = 'months';
$subscription->totalOccurrences = '9999';

$subscription->creditCardCardNumber = $_POST['card_number'];
$subscription->creditCardExpirationDate = sprintf('%04d-%02d', $_POST['card_exp_year'], $_POST['card_exp_month']);
$subscription->creditCardCardCode = $_POST['card_ccv'];

$result = $authorize->createSubscription($subscription);

// We want to delay this error until later
if ($result->xml->messages->resultCode != 'Ok')
    $errors[] = "Recurring billing could not be initiated - {$result->xml->messages->message->text}";

 

Highlighted
Member
Posts: 4
Registered: ‎09-08-2011

Re: PHP ARB

TJPride,

Thank you for the responce, you are much better at this than I. I tried your code, and did not receive any error at all, but I also do not see anything in my "Merchant Login", that would indicate a transaction. I have pasted the code I am trying, incase I have made a really dumb mistake. Again, thank you for your help in resolving this issue.

 

<?php
require_once 'AuthorizeNet.php';
$authorize = new AuthorizeNetARB($GLOBALS['123'], $GLOBALS['abcd']);
$authorize->setSandbox(false);
// SET TO TRUE IF USING SANDBOX ACCOUNT

$subscription = new AuthorizeNet_Subscription;

$subscription->customerId = $idn;

$subscription->billToFirstName = 'kelly';
$subscription->billToLastName = 'cu';
$subscription->billToCompany = 'company';
$subscription->billToAddress = '123 walal';
$subscription->billToCity = 'ny';
$subscription->billToState = 'ny';
$subscription->billToZip = '60502';
$subscription->billToCountry = 'US';

$subscription->customerPhoneNumber = '6302914980';
$subscription->customerEmail = 'kelly.cu@email.com';

$subscription->name = "{$_POST['type']} Subscription";
$subscription->orderDescription = 'For ' . count($_POST['zips']) . " zip codes with {$population} total estimated population";
$subscription->amount = $_POST['price'];

$subscription->startDate = $_POST['payment_due'];
$subscription->intervalLength = '1';
$subscription->intervalUnit = 'months';
$subscription->totalOccurrences = '9999';

$subscription->creditCardCardNumber = $_POST['card_number'];
$subscription->creditCardExpirationDate = sprintf('%04d-%02d', $_POST['card_exp_year'], $_POST['card_exp_month']);
$subscription->creditCardCardCode = $_POST['card_ccv'];

$result = $authorize->createSubscription($subscription);

// We want to delay this error until later
if ($result->xml->messages->resultCode != 'Ok')
    $errors[] = "Recurring billing could not be initiated - {$result->xml->messages->message->text}";
    ?>

 

Highlighted
Member
Posts: 4
Registered: ‎09-08-2011

Re: PHP ARB

 

I also tried the below, which was in the SDK readme file. Same result (NOTHING)

 

require_once 'AuthorizeNet.php';
    define("AUTHORIZENET_API_LOGIN_ID", "123");
    define("AUTHORIZENET_TRANSACTION_KEY", "4567");
    $subscription                          = new AuthorizeNet_Subscription;
    $subscription->name                    = "PHP Monthly Magazine";
    $subscription->intervalLength          = "1";
    $subscription->intervalUnit            = "months";
    $subscription->startDate               = "2011-03-12";
    $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();
	echo $subscription_id.'_test';

 

Highlighted
Solution
Accepted by topic author tunespring11
‎08-21-2015 01:58 AM
Posts: 1,609
Topics: 15
Kudos: 201
Solutions: 121
Registered: ‎06-23-2011

Re: PHP ARB

(referring to the copy of my code)

 

I notice sandbox is still set to false. Are you running this on a live account? I'm also assuming the $GLOBALS values in the second line are correct login codes, and that you're filling in all the $_POST values correctly. You might try doing print_r($result) at the end to make sure it's actually making it there and not dying along the way for some strange reason.

Highlighted
Member
Posts: 1
Registered: ‎09-14-2011

Re: PHP ARB

I also have had lots of trouble attempting to complete an ARB transaction.  I used the code that is referenced to by the Integration Guide here: http://developer.authorize.net/samplecode.  I'm using the PHP sample code, slightly modified only a little.

 

The error I keep getting is E00003 - Which is the result of an xml parser error.  This doesn't make much sense to me, as my code is copied and pasted from the sample code.  The format for the xml was written by someone at Auth.net (I assume since it is an official example).

 

I noticed in this thread that the code looks quite a bit different than what I am using.  Is there a more updated version of the code?  Should the outdated version not work or should I be able to have some success using the older examples?  Please respond, thanks!

 

 

Highlighted
Posts: 1,609
Topics: 15
Kudos: 201
Solutions: 121
Registered: ‎06-23-2011

Re: PHP ARB

The sample code is from an XML viewpoint, meaning you have to create the XML yourself in your code. There's a lot more scope for error with that than with what I'm doing, which is using the API functions layered on top of the XML.

 

Short version - ignore the sample code unless you really love XML, and use the ARB.markdown file from the doc folder of the PHP SDK (see Downloads).