Skip to content
Permalink
Browse files

Moving some constants to const.php.

  • Loading branch information
ethem
ethem committed Jan 6, 2006
1 parent 07ce491 commit 66ba9796d4ded849f92dbc53c6901d64d14ce47a
@@ -1,50 +1,16 @@
<?php // $Id$
/**
* No action.
*/
define('AN_ACTION_NONE', 0x00);
/**
* Used to authorize only, don't capture.
*/
define('AN_ACTION_AUTH_ONLY', 0x01);
/**
* Used to capture, it was authorized before.
*/
define('AN_ACTION_PRIOR_AUTH_CAPTURE', 0x02);
/**
* Used to authorize and capture.
*/
define('AN_ACTION_AUTH_CAPTURE', 0x03);
/**
* Used to return funds to a customer's credit card.
*
* - Can be credited within 120 days after the original authorization was obtained.
* - Amount can be any amount up to the original amount charged.
* - Captured/pending settlement transactions cannot be credited,
* instead a void must be issued to cancel the settlement.
* NOTE: Assigns a new transactionID to the original transaction.
* SAVE IT, so we can cancel new refund if it is a fault return.
*/
define('AN_ACTION_CREDIT', 0x04);
/**
* Used to cancel an exiting transaction with a status of
* authorized/pending capture, captured/pending settlement or
* settled/refunded.
*
* - Void requests effectively cancel the Capture request
* that would start the funds transfer process.
* - Also used to cancel existing transaction with a status of
* settled/refunded. Credited mistakenly, so cancel it
* and return funds to our account.
*/
define('AN_ACTION_VOID', 0x08);
define('AN_HOST', 'secure.authorize.net');
define('AN_HOST_TEST', 'certification.authorize.net');
define('AN_PORT', 443);
define('AN_PATH', '/gateway/transact.dll');
define('AN_APPROVED', '1');
define('AN_DECLINED', '2');
define('AN_ERROR', '3');
define('AN_DELIM', '|');
define('AN_ENCAP', '"');
require_once("const.php");
/**
* Gets settlement date and time
@@ -103,7 +69,7 @@ function authorizenet_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE
'x_delim_data' => 'True',
'x_delim_char' => AN_DELIM,
'x_encap_char' => AN_ENCAP,
'x_relay_response' => 'False',
'x_relay_response' => 'FALSE',
'x_method' => 'CC',
'x_login' => $CFG->an_login,
'x_test_request' => $an_test ? 'TRUE' : 'FALSE'
@@ -1,128 +1,126 @@
<?php // $Id$
/************************************************************************
*
* CCVal - Credit Card Validation function.
*
* Copyright (c) 1999, 2003 Holotech Enterprises. All rights reserved.
* You may freely modify and use this function for your own purposes. You
* may freely distribute it, without modification and with this notice
* and entire header intact.
*
* This function accepts a credit card number and, optionally, a code for
* a credit card name. If a Name code is specified, the number is checked
* against card-specific criteria, then validated with the Luhn Mod 10
* formula. Otherwise it is only checked against the formula. Valid name
* codes are:
*
* mcd - Master Card
* vis - Visa
* amx - American Express
* dsc - Discover
* dnc - Diners Club
* jcb - JCB
* swi - Switch
* dlt - Delta
* enr - EnRoute
*
* You can also optionally specify an expiration date in the formay mmyy.
* If the validation fails on the date, the function returns 0. If it
* fails on the number validation, it returns false.
*
* A description of the criteria used in this function can be found at
* http://www.paylib.net/ccval.html. If you have any questions or
* comments, please direct them to ccval@holotech.net
*
* Alan Little
* Holotech Enterprises
* http://www.holotech.net/
* August 2003
*
************************************************************************/
function CCVal($Num, $Name = "n/a", $Exp = "") {
// Check the expiration date first
if (strlen($Exp)) {
$Month = substr($Exp, 0, 2);
$Year = substr($Exp, -2);
$WorkDate = "$Month/01/$Year";
$WorkDate = strtotime($WorkDate);
$LastDay = date("t", $WorkDate);
$Expires = strtotime("$Month/$LastDay/$Year 11:59:59");
if ($Expires < time()) return 0;
*
* CCVal - Credit Card Validation function.
*
* Copyright (c) 1999, 2003 Holotech Enterprises. All rights reserved.
* You may freely modify and use this function for your own purposes. You
* may freely distribute it, without modification and with this notice
* and entire header intact.
*
* This function accepts a credit card number and, optionally, a code for
* a credit card name. If a Name code is specified, the number is checked
* against card-specific criteria, then validated with the Luhn Mod 10
* formula. Otherwise it is only checked against the formula. Valid name
* codes are:
*
* mcd - Master Card
* vis - Visa
* amx - American Express
* dsc - Discover
* dnc - Diners Club
* jcb - JCB
* swi - Switch
* dlt - Delta
* enr - EnRoute
*
* You can also optionally specify an expiration date in the formay mmyy.
* If the validation fails on the date, the function returns 0. If it
* fails on the number validation, it returns false.
*
* A description of the criteria used in this function can be found at
* http://www.paylib.net/ccval.html. If you have any questions or
* comments, please direct them to ccval@holotech.net
*
* Alan Little
* Holotech Enterprises
* http://www.holotech.net/
* August 2003
*
************************************************************************/
function CCVal($Num, $Name = "n/a", $Exp = "")
{
// Check the expiration date first
if (strlen($Exp))
{
$Month = substr($Exp, 0, 2);
$Year = substr($Exp, -2);
$WorkDate = "$Month/01/$Year";
$WorkDate = strtotime($WorkDate);
$LastDay = date("t", $WorkDate);
$Expires = strtotime("$Month/$LastDay/$Year 11:59:59");
if ($Expires < time()) return 0;
}
// Innocent until proven guilty
// Innocent until proven guilty
$GoodCard = true;
// Get rid of any non-digits
// Get rid of any non-digits
$Num = ereg_replace("[^0-9]", "", $Num);
// Perform card-specific checks, if applicable
switch ($Name) {
// Perform card-specific checks, if applicable
switch ($Name)
{
case "mcd" :
$GoodCard = ereg("^5[1-5].{14}$", $Num);
break;
case "mcd" :
$GoodCard = ereg("^5[1-5].{14}$", $Num);
break;
case "vis" :
$GoodCard = ereg("^4.{15}$|^4.{12}$", $Num);
break;
case "vis" :
$GoodCard = ereg("^4.{15}$|^4.{12}$", $Num);
break;
case "amx" :
$GoodCard = ereg("^3[47].{13}$", $Num);
break;
case "amx" :
$GoodCard = ereg("^3[47].{13}$", $Num);
break;
case "dsc" :
$GoodCard = ereg("^6011.{12}$", $Num);
break;
case "dsc" :
$GoodCard = ereg("^6011.{12}$", $Num);
break;
case "dnc" :
$GoodCard = ereg("^30[0-5].{11}$|^3[68].{12}$", $Num);
break;
case "dnc" :
$GoodCard = ereg("^30[0-5].{11}$|^3[68].{12}$", $Num);
break;
case "jcb" :
$GoodCard = ereg("^3.{15}$|^2131|1800.{11}$", $Num);
break;
case "jcb" :
$GoodCard = ereg("^3.{15}$|^2131|1800.{11}$", $Num);
break;
case "dlt" :
$GoodCard = ereg("^4.{15}$", $Num);
break;
case "dlt" :
$GoodCard = ereg("^4.{15}$", $Num);
break;
case "swi" :
$GoodCard = ereg("^[456].{15}$|^[456].{17,18}$", $Num);
break;
case "swi" :
$GoodCard = ereg("^[456].{15}$|^[456].{17,18}$", $Num);
break;
case "enr" :
$GoodCard = ereg("^2014.{11}$|^2149.{11}$", $Num);
break;
case "enr" :
$GoodCard = ereg("^2014.{11}$|^2149.{11}$", $Num);
break;
}
// The Luhn formula works right to left, so reverse the number.
// The Luhn formula works right to left, so reverse the number.
$Num = strrev($Num);
$Total = 0;
for ($x=0; $x<strlen($Num); $x++) {
$digit = substr($Num,$x,1);
// If it's an odd digit, double it
if ($x/2 != floor($x/2)) {
$digit *= 2;
for ($x=0; $x < strlen($Num); $x++)
{
$digit = substr($Num, $x, 1);
// If the result is two digits, add them
if (strlen($digit) == 2)
$digit = substr($digit,0,1) + substr($digit,1,1);
}
// If it's an odd digit, double it
if ($x/2 != floor($x/2)) {
$digit *= 2;
// Add the current digit, doubled and added if applicable, to the Total
$Total += $digit;
// If the result is two digits, add them
if (strlen($digit) == 2)
$digit = substr($digit, 0, 1) + substr($digit, 1, 1);
}
// Add the current digit, doubled and added if applicable, to the Total
$Total += $digit;
}
// If it passed (or bypassed) the card-specific check and the Total is
// evenly divisible by 10, it's cool!
if ($GoodCard && $Total % 10 == 0) return true; else return false;
}
// If it passed (or bypassed) the card-specific check and the Total is
// evenly divisible by 10, it's cool!
return ($GoodCard && $Total % 10 == 0);
}
?>
@@ -0,0 +1,83 @@
<?php // $Id$
/**
* New order. No transaction was made.
*/
define('AN_STATUS_NONE', 0x00);
/**
* Authorized.
*/
define('AN_STATUS_AUTH', 0x01);
/**
* Captured.
*/
define('AN_STATUS_CAPTURE', 0x02);
/**
* AN_STATUS_AUTH|AN_STATUS_CAPTURE.
*/
define('AN_STATUS_AUTHCAPTURE', 0x03);
/**
* Refunded.
*/
define('AN_STATUS_CREDIT', 0x04);
/**
* Voided.
*/
define('AN_STATUS_VOID', 0x08);
/**
* Expired.
*/
define('AN_STATUS_EXPIRE', 0x10);
/**
* No action.
*/
define('AN_ACTION_NONE', 0x00);
/**
* Used to authorize only, don't capture.
*/
define('AN_ACTION_AUTH_ONLY', 0x01);
/**
* Used to capture, it was authorized before.
*/
define('AN_ACTION_PRIOR_AUTH_CAPTURE', 0x02);
/**
* Used to authorize and capture.
*/
define('AN_ACTION_AUTH_CAPTURE', 0x03);
/**
* Used to return funds to a customer's credit card.
*
* - Can be credited within 120 days after the original authorization was obtained.
* - Amount can be any amount up to the original amount charged.
* - Captured/pending settlement transactions cannot be credited,
* instead a void must be issued to cancel the settlement.
* NOTE: Assigns a new transactionID to the original transaction.
* SAVE IT, so we can cancel new refund if it is a fault return.
*/
define('AN_ACTION_CREDIT', 0x04);
/**
* Used to cancel an exiting transaction with a status of
* authorized/pending capture, captured/pending settlement or
* settled/refunded.
*
* - Void requests effectively cancel the Capture request
* that would start the funds transfer process.
* - Also used to cancel existing transaction with a status of
* settled/refunded. Credited mistakenly, so cancel it
* and return funds to our account.
*/
define('AN_ACTION_VOID', 0x08);
?>

0 comments on commit 66ba979

Please sign in to comment.
You can’t perform that action at this time.