cancel
Showing results for 
Search instead for 
Did you mean: 

ARB Help

Is there any reason why this code shouldn't work. The Aim part works, the credit card gets charge, but there is no subscription being created, but there are no error codes saying it doesnt work.

 

 

<?php

	                require_once('anet_php_sdk/AuthorizeNet.php');

		            // Live Credentials
	                $sale = new AuthorizeNetAIM('***', '***');
	                $sale->setSandbox(true);
	                $sale->amount = "20";
					$sale->card_num = $card;
					$sale->exp_date = $exp_date;
					$customer = (object)array();
					$customer->first_name = $fn;
					$customer->last_name = $ln;
					$customer->email = $email;
					$customer->address = $address;
					$customer->city = $city;
					$customer->state = $state;
					$customer->zip = $zip;
					//$customer->country = "US";
					$sale->setFields($customer);

	                $response = $sale->authorizeAndCapture();

	                if ($response->approved) {
	                  $card_response = "<p>Your credit card has been charged</p>";
	                  $transaction_id =  "<p>Transaction ID: " . $response->transaction_id ."</p>";

		                //Run the ARB Code
		                require_once('anet_php_sdk/AuthorizeNet.php');

		                $subscription                          = new AuthorizeNet_Subscription('***', '***');
		                $subscription->name                    = "I4F Yearly Membership";
		                $subscription->intervalLength          = "12";
		                $subscription->intervalUnit            = "months";
		                $subscription->startDate               = date("Y-m-d");//, strtotime("+ 1 year"));
		                $subscription->totalOccurrences        = "5";
		                $subscription->amount                  = "20";
		                $subscription->creditCardCardNumber    = $card;
		                $subscription->creditCardExpirationDate= $exp_date;
		                $subscription->creditCardCardCode      = $code;
		                $subscription->billToFirstName         = $fn;
		                $subscription->billToLastName          = $ln;

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

?>

 

 

 

triplewhat
Member
1 ACCEPTED SOLUTION

Accepted Solutions

That's probably not going to work, since at least part of the current day is going to be after the charge time. And the start date should be when you want your first charge to go through, which if you're doing the initial charge immediately via AIM, would actually be one month from now (however you want to calculate that).

 

If you're not sure if it's working, do a print_r($response) and look for error text. It'll also give you an error code, which you can use here to get more detailed information:

http://developer.authorize.net/tools/responsereasoncode/

View solution in original post

4 REPLIES 4

If you'd printed out the response for the ARB request, you'd probably have seen the answer. Short version is that at minimum, you're setting the login ID and transaction key on the subscription, not the ARB request, and you're not setting sandbox on the ARB request either. I also don't understand what you're doing with the start date. If you want it set to start as soon as possible, set it to tomorrow date('Y-m-d', time() + 86400) or if you want it a year from now, date('Y-m-d', time() + 86400 * 365);

TJPride
Expert

Sorry, I am new to all this. I am just happy that part of it works. I see what your saying. Well I was trying to set the start date for the same day as they sign up. Is this not possible they I am doing it?

 

That's probably not going to work, since at least part of the current day is going to be after the charge time. And the start date should be when you want your first charge to go through, which if you're doing the initial charge immediately via AIM, would actually be one month from now (however you want to calculate that).

 

If you're not sure if it's working, do a print_r($response) and look for error text. It'll also give you an error code, which you can use here to get more detailed information:

http://developer.authorize.net/tools/responsereasoncode/

Thank you very much TJ