More description, more documentation.
This commit is contained in:
+76
-55
@@ -4,48 +4,64 @@
|
||||
* No action.
|
||||
*/
|
||||
define('AN_ACTION_NONE', 0x00);
|
||||
|
||||
/**
|
||||
* Authorize only. Don't capture.
|
||||
* Used to authorize only, don't capture.
|
||||
*/
|
||||
define('AN_ACTION_AUTH_ONLY', 0x01);
|
||||
|
||||
/**
|
||||
* Authorized before, capture now.
|
||||
* Used to capture, it was authorized before.
|
||||
*/
|
||||
define('AN_ACTION_PRIOR_AUTH_CAPTURE', 0x02);
|
||||
|
||||
/**
|
||||
* Authorize and capture
|
||||
* Used to authorize and capture.
|
||||
*/
|
||||
define('AN_ACTION_AUTH_CAPTURE', 0x03);
|
||||
|
||||
/**
|
||||
* Refund it.
|
||||
* must be performed in 120 days after settled.
|
||||
* status must be auth_captured/settled.
|
||||
* can be credited up to original amount.
|
||||
* -- generates new transid. SAVE IT.
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* Cancel transaction in status
|
||||
* - authorized: don't settle.
|
||||
* - auth_captured/pending settle
|
||||
* - credited mistakenly, void it.
|
||||
* 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.
|
||||
*
|
||||
* @todo cut-off time
|
||||
*/
|
||||
define('AN_ACTION_VOID', 0x08);
|
||||
|
||||
|
||||
/**
|
||||
* authorizenet_action
|
||||
* Performs an action on authorize.net
|
||||
*
|
||||
* @param &object $order Which transaction data will be send. See enrol_authorize table.
|
||||
* @param &string $message Info about errors
|
||||
* @param &string $message Information about error messages.
|
||||
* @param int $action Which action will be performed. See AN_ACTION_*
|
||||
* @param object $extra Extra info
|
||||
* @return bool true, transaction was successful, false otherwise
|
||||
* @param object $extra Extra transaction data.
|
||||
* @param &int $reason Response reason code.
|
||||
* @return bool true, transaction was successful, false otherwise.
|
||||
* @author Ethem Evlice <ethem a.t evlice d.o.t com>
|
||||
* @uses $CFG
|
||||
* @todo cut-off time
|
||||
*/
|
||||
function authorizenet_action(&$order, &$message, $action=AN_ACTION_NONE, $extra = null)
|
||||
function authorizenet_action(&$order, &$message, $action=AN_ACTION_NONE, $extra = NULL, &$reason = 0)
|
||||
{
|
||||
global $CFG;
|
||||
static $conststring;
|
||||
@@ -64,10 +80,12 @@ function authorizenet_action(&$order, &$message, $action=AN_ACTION_NONE, $extra
|
||||
'x_test_request' => $an_test ? 'TRUE' : 'FALSE'
|
||||
);
|
||||
$str = '';
|
||||
foreach($consdata as $ky => $vl) { $str .= $ky . '=' . urlencode($vl) . '&'; }
|
||||
foreach($consdata as $ky => $vl) {
|
||||
$str .= $ky . '=' . urlencode($vl) . '&';
|
||||
}
|
||||
$str .= (!empty($CFG->an_tran_key)) ?
|
||||
"x_tran_key" . "=" . urlencode($CFG->an_tran_key):
|
||||
"x_password" . "=" . urlencode($CFG->an_password);
|
||||
"x_tran_key" . "=" . urlencode($CFG->an_tran_key):
|
||||
"x_password" . "=" . urlencode($CFG->an_password);
|
||||
|
||||
$conststring = $str;
|
||||
}
|
||||
@@ -98,7 +116,8 @@ function authorizenet_action(&$order, &$message, $action=AN_ACTION_NONE, $extra
|
||||
return false;
|
||||
}
|
||||
$ext = (array)$extra;
|
||||
$poststring .= "&" . "x_type=" . ($action==AN_ACTION_AUTH_ONLY ? "AUTH_ONLY" : "AUTH_CAPTURE");
|
||||
$poststring .= "&" . "x_type=" . ($action==AN_ACTION_AUTH_ONLY ?
|
||||
"AUTH_ONLY" : "AUTH_CAPTURE");
|
||||
foreach($ext as $k => $v) {
|
||||
$poststring .= "&" . $k . "=" . urlencode($v);
|
||||
}
|
||||
@@ -112,7 +131,7 @@ function authorizenet_action(&$order, &$message, $action=AN_ACTION_NONE, $extra
|
||||
return false;
|
||||
}
|
||||
// 30 days. +1 = cut-off time
|
||||
$timediff = time() - (31 * 3600 * 24);
|
||||
$timediff = time() - (31 * 3600 * 24);
|
||||
if ($order->timecreated < $timediff) {
|
||||
$message = "Transaction must be captured within 30 days. EXPIRED!";
|
||||
return false;
|
||||
@@ -129,20 +148,20 @@ function authorizenet_action(&$order, &$message, $action=AN_ACTION_NONE, $extra
|
||||
return false;
|
||||
}
|
||||
// 120 days
|
||||
$timediff = time() - (120 * 3600 * 24);
|
||||
$timediff = time() - (120 * 3600 * 24);
|
||||
if ($order->timecreated < $timediff) {
|
||||
$message = "Order can be credited within 120 days!";
|
||||
return false;
|
||||
}
|
||||
// up to original amount
|
||||
$total = doubleval($extra->sum) + doubleval($extra->amount);
|
||||
if ($total > $order->amount) {
|
||||
if (($extra->amount == 0) || ($total > $order->amount)) {
|
||||
$message = "Can be credited up to original amount.";
|
||||
return false;
|
||||
}
|
||||
$poststring .= "&" . "x_type=CREDIT";
|
||||
$poststring .= "&" . "x_trans_id=" . urlencode($order->transid);
|
||||
$poststring .= "&" . "x_card_num=" . urlencode(sprintf("%04d", intval($order->cclastfour)));
|
||||
$poststring .= "&" . "x_card_num=" . sprintf("%04d", intval($order->cclastfour));
|
||||
$poststring .= "&" . "x_currency_code=" . urlencode($extra->currency);
|
||||
$poststring .= "&" . "x_amount=" . urlencode($extra->amount);
|
||||
break;
|
||||
@@ -158,32 +177,32 @@ function authorizenet_action(&$order, &$message, $action=AN_ACTION_NONE, $extra
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($order->status == AN_STATUS_AUTH) {
|
||||
// 30 days for authonly, make it expired (***********timeupdated)
|
||||
$timediff = time() - (30 * 3600 * 24);
|
||||
if ($order->timecreated < $timediff) {
|
||||
$message = "Auth_only transaction can be voided within 30 days!";
|
||||
$order->status = AN_STATUS_EXPIRED;
|
||||
return false;
|
||||
}
|
||||
} elseif ($order->status == (AN_STATUS_AUTH | AN_STATUS_CAPTURE)) {
|
||||
// 1 day. Cancel pending settlement.
|
||||
$timediff = time() - (2 * 3600 * 24); // TO DO: Cut-off time
|
||||
if ($order->timecreated < $timediff) {
|
||||
$message = "Settled transaction cannot be voided. Try REFUND!";
|
||||
return false;
|
||||
}
|
||||
} elseif ($order->status == AN_STATUS_CREDIT) {
|
||||
// 120 days for credit
|
||||
$timediff = time() - (120 * 3600 * 24);
|
||||
if ($order->timecreated < $timediff) {
|
||||
$message = "Ops! Settled transaction must be credited within 120 days!";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// OK.
|
||||
$poststring .= "&" . "x_type=VOID";
|
||||
$poststring .= "&" . "x_trans_id=" . urlencode($order->transid);
|
||||
if ($order->status == AN_STATUS_AUTH) {
|
||||
// 30 days for authonly, make it expired (***********timeupdated)
|
||||
$timediff = time() - (30 * 3600 * 24);
|
||||
if ($order->timecreated < $timediff) {
|
||||
$message = "Auth_only transaction can be voided within 30 days!";
|
||||
$order->status = AN_STATUS_EXPIRED;
|
||||
return false;
|
||||
}
|
||||
} elseif ($order->status == (AN_STATUS_AUTH | AN_STATUS_CAPTURE)) {
|
||||
// 1 day. Cancel pending settlement.
|
||||
$timediff = time() - (2 * 3600 * 24); // TO DO: Cut-off time
|
||||
if ($order->timecreated < $timediff) {
|
||||
$message = "Settled transaction cannot be voided. Try REFUND!";
|
||||
return false;
|
||||
}
|
||||
} elseif ($order->status == AN_STATUS_CREDIT) {
|
||||
// 120 days for credit
|
||||
$timediff = time() - (120 * 3600 * 24);
|
||||
if ($order->timecreated < $timediff) {
|
||||
$message = "Ops! Settled transaction must be credited within 120 days!";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// OK.
|
||||
$poststring .= "&" . "x_type=VOID";
|
||||
$poststring .= "&" . "x_trans_id=" . urlencode($order->transid);
|
||||
}
|
||||
|
||||
default: { // ???
|
||||
@@ -194,8 +213,8 @@ function authorizenet_action(&$order, &$message, $action=AN_ACTION_NONE, $extra
|
||||
|
||||
// referer
|
||||
$anrefererheader = '';
|
||||
if (!(empty($CFG->an_referer) || $CFG->an_referer == "http://" || $CFG->an_referer == "https://")) {
|
||||
$anrefererheader = "Referer: " . $CFG->an_referer . "\r\n";
|
||||
if (!(empty($CFG->an_referer) || $CFG->an_referer == "http://")) {
|
||||
$anrefererheader = "Referer: " . $CFG->an_referer . "\r\n";
|
||||
}
|
||||
|
||||
$response = array();
|
||||
@@ -241,6 +260,8 @@ function authorizenet_action(&$order, &$message, $action=AN_ACTION_NONE, $extra
|
||||
$response[$rcount] = substr($response[$rcount], 0, -1);
|
||||
}
|
||||
|
||||
$reason = intval($response[2]);
|
||||
|
||||
if ($response[0] == AN_APPROVED) {
|
||||
$order->transid = strval($response[6]); // TransactionID.
|
||||
$order->timeupdated = time();
|
||||
@@ -250,10 +271,10 @@ function authorizenet_action(&$order, &$message, $action=AN_ACTION_NONE, $extra
|
||||
$order->authcode = strval($response[4]); // Authorization or Approval code
|
||||
$order->avscode = strval($response[5]); // Address Verification System code
|
||||
if ($action == AN_ACTION_AUTH_ONLY) {
|
||||
$order->status = AN_STATUS_AUTH;
|
||||
$order->status = AN_STATUS_AUTH;
|
||||
}
|
||||
else {
|
||||
$order->status = AN_STATUS_AUTH | AN_STATUS_CAPTURE;
|
||||
$order->status = AN_STATUS_AUTH | AN_STATUS_CAPTURE;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -48,9 +48,18 @@ class enrolment_plugin extends enrolment_base
|
||||
* Credit card error message.
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $ccerrormsg;
|
||||
|
||||
/**
|
||||
* Cron log.
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $log;
|
||||
|
||||
|
||||
/**
|
||||
* Shows a credit card form for registration.
|
||||
@@ -70,7 +79,7 @@ class enrolment_plugin extends enrolment_base
|
||||
// check payment
|
||||
$this->prevent_double_paid($course);
|
||||
|
||||
// I want to paid on SSL.
|
||||
// I want to pay on SSL.
|
||||
if (empty($_SERVER['HTTPS'])) {
|
||||
if (empty($CFG->loginhttps)) {
|
||||
error(get_string("httpsrequired", "enrol_authorize"));
|
||||
@@ -207,7 +216,7 @@ class enrolment_plugin extends enrolment_base
|
||||
$extra->x_invoice_num = $order->id;
|
||||
$extra->x_description = $course->shortname;
|
||||
|
||||
$message = null;
|
||||
$message = NULL;
|
||||
$an_review = !empty($CFG->an_review);
|
||||
$action = $an_review ? AN_ACTION_AUTH_ONLY : AN_ACTION_AUTH_CAPTURE;
|
||||
$success = authorizenet_action($order, $message, $action, $extra);
|
||||
@@ -405,7 +414,7 @@ class enrolment_plugin extends enrolment_base
|
||||
// Admin can check (Accept|Deny) new transactions manually.
|
||||
|
||||
if ($count = count_records('enrol_authorize', 'status', AN_STATUS_AUTH)) {
|
||||
notify("CRON DISABLED. TRANSACTIONS WITH AN_STATUS_AUTH WILL BE CANCELLED UNLESS YOU CHECK IT. TOTAL $count");
|
||||
notify("CRON DISABLED. TRANSACTIONS WITH A STATUS OF AN_STATUS_AUTH WILL BE CANCELLED UNLESS YOU CHECK IT. TOTAL $count");
|
||||
}
|
||||
}
|
||||
// ***************************************************
|
||||
@@ -573,10 +582,10 @@ class enrolment_plugin extends enrolment_base
|
||||
$timediffcnf = $timenow - (intval($CFG->an_review_day) * 3600 * 24);
|
||||
$select = "(status = '" . AN_STATUS_AUTH . "') AND (timeupdated = '0') AND (timecreated < '$timediffcnf') AND (timecreated > '$timediff30')";
|
||||
if ($orders = get_records_select('enrol_authorize', $select)) {
|
||||
set_time_limit(0);
|
||||
require_once("$CFG->dirroot/enrol/authorize/action.php");
|
||||
@set_time_limit(0);
|
||||
$this->log = "AUTHORIZE.NET AUTOCAPTURE CRON: " . userdate($timenow) . "\n";
|
||||
$message = null;
|
||||
$message = NULL;
|
||||
foreach ($orders as $order) {
|
||||
$success = authorizenet_action($order, $message, AN_ACTION_PRIOR_AUTH_CAPTURE);
|
||||
if ($success) {
|
||||
|
||||
Reference in New Issue
Block a user