Source for file AuthNet.class.php
-
-
-
* This class encapsulates transaction processing with Authorize.Net.
-
-
-
-
-
-
-
/* Test Credit Card Numbers
-
370000000000002 - American Express
-
6011000000000012 - Discover
-
5424000000000015 - MasterCard
-
-
4222222222222 - Forced Failure
-
-
-
-
-
-
//////////////////// public variables ////////////////////////////
-
-
-
-
* Required. Sets the billing street address.
-
-
-
-
-
-
* Required. Sets the Amount to Charge
-
-
-
-
-
-
* Gets the returned apprival code.
-
-
-
-
-
-
* Required. Sets the Authorize.Net API Login ID
-
-
-
-
-
-
* Required. Sets the Authorize.Net API Transaction Key
-
-
-
-
-
-
* Required. Sets the Credit Card Number. All non-numeric characters will be removed.
-
-
-
-
-
-
* Required. Sets the billing city.
-
-
-
-
-
-
* Optional. Sets the billing country.
-
-
-
-
-
-
* Optional. Sets any custom information to be sent to Authorize.Net.
-
-
-
-
-
-
* Options. Sets the Customer ID.
-
-
-
-
-
-
* Required. Sets the transaction description.
-
-
-
-
-
-
* Optional. Sets the time window (in seconds) to prevent duplicate transactions. Default is 120 seconds.
-
-
-
-
-
-
* Optional. Sets the billing email address.
-
-
-
-
-
-
* Required. Sets the credit card expiration date. Format: MMYY.
-
-
-
-
-
-
* Required. Sets the billing first name.
-
-
-
-
-
-
* Optional. Sets the invoice number.
-
-
-
-
-
-
* Gets the error returned, if any.
-
-
-
-
-
-
* Required. Sets the billing last name.
-
-
-
-
-
-
* Gets the raw text of the last request sent to Authorize.Net
-
-
-
-
-
-
* Gets the raw text of the last response from Authorize.Net
-
-
-
-
-
-
* Optional. The billing phone number.
-
-
-
-
-
-
* Gets the reason for the last response.
-
-
-
-
-
-
* Optional. Sets an email address to receive a copy of the confirmation.
-
-
-
-
-
-
* Required. Sets the credit card security code.
-
-
-
-
-
-
* Required. Sets the billing state.
-
-
-
-
-
-
* Optional. If true, the transaction will be processed in test mode.
-
-
-
-
-
-
* Gets the returned Transaction ID.
-
-
-
-
-
-
* Required. Gets the transaction Type. Possible values are: AUTH_CAPTURE, AUTH_ONLY, CAPTURE_ONLY, CREDIT, VOID, PRIOR_AUTH_CAPTURE
-
-
-
-
-
-
* Sets the billing zip code.
-
-
-
-
-
-
-
///////////////////// private_variables ///////////////////////////////////
-
-
-
* The URL to use in LIVE mdoe.
-
-
-
-
var $_live_url=
"https://secure.authorize.net/gateway/transact.dll";
-
-
-
* The URL to use in TEST mdoe.
-
-
-
-
var $_test_url=
"https://test.authorize.net/gateway/transact.dll";
-
-
-
-
//////////////////////// public functions ////////////////////////////////
-
-
-
* Constructor for the class.
-
-
-
-
-
-
* Processes the transaction
-
* @return bool Returns true on success, false on error.
-
-
-
-
-
//validate the expiration date
-
-
-
-
-
-
-
if($this->Test) $url=
$this->_test_url;
-
else $url=
$this->_live_url;
-
-
-
-
-
-
-
"x_delim_data" =>
"TRUE",
-
-
-
-
-
"x_relay_response" =>
"FALSE",
-
-
-
-
-
-
-
-
-
-
-
"x_state" =>
$this->State,
-
-
-
"x_phone" =>
$this->Phone,
-
"x_email" =>
$this->Email,
-
"x_email_customer" =>
"FALSE",
-
"SpecialCode" =>
$this->Custom,
-
-
-
-
-
-
if($this->Test) $authnet_values["x_test_request"]=
"TRUE";
-
else $authnet_values["x_test_request"]=
"FALSE";
-
-
foreach($authnet_values as $key =>
$value) $params[]=
$key.
"=".
urlencode($value);
-
-
//connect and send the request
-
-
curl_setopt($ch, CURLOPT_HEADER, 0); // set to 0 to eliminate header info from response
-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1)
-
curl_setopt($ch, CURLOPT_POSTFIELDS, implode("&",$params )); // use HTTP POST to send form data
-
$resp =
curl_exec($ch); //execute post and get results
-
-
-
-
-
-
-
$response_parts=
explode("|",$resp);
-
if($response_parts[0]==
1) //approved
-
-
-
-
-
-
-
-
-
switch($response_parts[2])
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
$this->ResponseReason=
"An authorization code is required but not present.";
-
-
-
$this->ResponseReason=
"The merchant API login ID is invalid or the account is inactive.";
-
-
-
-
-
-
-
-
-
$this->ResponseReason=
"The merchant does not accept this type of credit card.";
-
-
-
$this->ResponseReason=
"The transaction resulted in an AVS mismatch. The address provided does not match billing address of cardholder.";
-
-
-
$this->ResponseReason=
"The merchant does not accept this type of credit card.";
-
-
-
$this->ResponseReason=
"The authorization was approved, but settlement failed.";
-
-
-
-
-
-
$this->ResponseReason=
"There is missing or invalid information in a required field.";
-
-
-
$this->ResponseReason=
"The amount requested for settlement may not be greater than the original amount authorized.";
-
-
-
$this->ResponseReason=
"This processor does not accept partial reversals.";
-
-
-
$this->ResponseReason=
"This transaction is awaiting settlement and cannot be refunded.";
-
-
-
$this->ResponseReason=
"The sum of all credits against this transaction is greater than the original transaction amount.";
-
-
-
$this->ResponseReason=
"The transaction was authorized, but the client could not be notified; the transaction will not be settled.";
-
-
-
$this->ResponseReason=
"The sum of credits against the referenced transaction would exceed the original debit amount.";
-
-
-
-
-
-
-
-
-
-
-
-