2006-01-19 14:57:23 +00:00
|
|
|
<?php // $Id$
|
2005-12-09 12:00:28 +00:00
|
|
|
|
2006-04-28 07:20:25 +00:00
|
|
|
if (!defined('MOODLE_INTERNAL')) {
|
2006-05-13 08:53:34 +00:00
|
|
|
die('Direct access to this script is forbidden.');
|
2006-04-28 07:20:25 +00:00
|
|
|
}
|
|
|
|
|
2006-01-06 12:14:17 +00:00
|
|
|
define('AN_APPROVED', '1');
|
|
|
|
define('AN_DECLINED', '2');
|
2006-04-28 07:20:25 +00:00
|
|
|
define('AN_ERROR', '3');
|
|
|
|
define('AN_DELIM', '|');
|
|
|
|
define('AN_ENCAP', '"');
|
|
|
|
|
2006-07-25 17:38:32 +00:00
|
|
|
require_once($CFG->dirroot.'/enrol/authorize/const.php');
|
|
|
|
require_once($CFG->dirroot.'/enrol/authorize/enrol.php');
|
2005-12-14 15:47:37 +00:00
|
|
|
|
2005-12-22 15:24:05 +00:00
|
|
|
/**
|
|
|
|
* Gets settlement date and time
|
|
|
|
*
|
* Update record as soon as possible. If update/insert record fails email to admin to have update manually.
* ignore_user_abort(true) at critical section (before fwrite($fp, "POST /gateway/transact.dll).
This is last change to ignore request for user.
* Made some functions "static" to call function directly. So, no need new enrolment_plugin_authorize() instance.
Now, these are static:
get_list_of_creditcards, zero_cost, get_course_cost, prevent_double_paid, email_to_admin, check_openssl_loaded
* Some mtrace cleanup. Removed default new line.
This is big work. When PHP5 is required for moodle in the future, I will add static modifier to functions.
Now and future, this plugin is/will unbreakable; Merged from MOODLE_16_STABLE. :)
2006-07-24 12:19:20 +00:00
|
|
|
* @param int $time Time processed, usually now.
|
|
|
|
* @return int Settlement date and time
|
2005-12-22 15:24:05 +00:00
|
|
|
*/
|
2006-07-10 10:17:23 +00:00
|
|
|
function authorize_getsettletime($time)
|
2005-12-22 15:24:05 +00:00
|
|
|
{
|
|
|
|
global $CFG;
|
|
|
|
|
2006-02-10 12:41:56 +00:00
|
|
|
$cutoff = intval($CFG->an_cutoff);
|
|
|
|
$mins = $cutoff % 60;
|
|
|
|
$hrs = ($cutoff - $mins) / 60;
|
2005-12-22 15:24:05 +00:00
|
|
|
$cutofftime = strtotime("$hrs:$mins", $time);
|
|
|
|
if ($cutofftime < $time) {
|
|
|
|
$cutofftime = strtotime("$hrs:$mins", $time + (24 * 3600));
|
|
|
|
}
|
|
|
|
return $cutofftime;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is order settled? Status must be auth_captured or credited.
|
|
|
|
*
|
|
|
|
* @param object $order Order details
|
|
|
|
* @return bool true, if settled, false otherwise.
|
|
|
|
*/
|
2006-07-10 10:17:23 +00:00
|
|
|
function authorize_settled($order)
|
2005-12-22 15:24:05 +00:00
|
|
|
{
|
2006-01-02 09:30:35 +00:00
|
|
|
return (($order->status == AN_STATUS_AUTHCAPTURE || $order->status == AN_STATUS_CREDIT) &&
|
2006-01-19 14:57:23 +00:00
|
|
|
($order->settletime > 0) && ($order->settletime < time()));
|
2005-12-22 15:24:05 +00:00
|
|
|
}
|
|
|
|
|
2006-07-10 10:17:23 +00:00
|
|
|
/**
|
|
|
|
* Is order expired? 'Authorized/Pending Capture' transactions are expired after 30 days.
|
|
|
|
*
|
|
|
|
* @param object &$order Order details.
|
|
|
|
* @return bool true, transaction is expired, false otherwise.
|
|
|
|
*/
|
|
|
|
function authorize_expired(&$order)
|
|
|
|
{
|
|
|
|
static $timediff30;
|
|
|
|
|
|
|
|
if ($order->status == AN_STATUS_EXPIRE) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
elseif ($order->status != AN_STATUS_AUTH) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
* Update record as soon as possible. If update/insert record fails email to admin to have update manually.
* ignore_user_abort(true) at critical section (before fwrite($fp, "POST /gateway/transact.dll).
This is last change to ignore request for user.
* Made some functions "static" to call function directly. So, no need new enrolment_plugin_authorize() instance.
Now, these are static:
get_list_of_creditcards, zero_cost, get_course_cost, prevent_double_paid, email_to_admin, check_openssl_loaded
* Some mtrace cleanup. Removed default new line.
This is big work. When PHP5 is required for moodle in the future, I will add static modifier to functions.
Now and future, this plugin is/will unbreakable; Merged from MOODLE_16_STABLE. :)
2006-07-24 12:19:20 +00:00
|
|
|
if (empty($timediff30)) {
|
|
|
|
$timediff30 = authorize_getsettletime(time()) - (30 * 24 * 3600);
|
|
|
|
}
|
2006-07-10 10:17:23 +00:00
|
|
|
|
* Update record as soon as possible. If update/insert record fails email to admin to have update manually.
* ignore_user_abort(true) at critical section (before fwrite($fp, "POST /gateway/transact.dll).
This is last change to ignore request for user.
* Made some functions "static" to call function directly. So, no need new enrolment_plugin_authorize() instance.
Now, these are static:
get_list_of_creditcards, zero_cost, get_course_cost, prevent_double_paid, email_to_admin, check_openssl_loaded
* Some mtrace cleanup. Removed default new line.
This is big work. When PHP5 is required for moodle in the future, I will add static modifier to functions.
Now and future, this plugin is/will unbreakable; Merged from MOODLE_16_STABLE. :)
2006-07-24 12:19:20 +00:00
|
|
|
$isexpired = (authorize_getsettletime($order->timecreated) < $timediff30);
|
|
|
|
if ($isexpired) {
|
2006-07-10 10:17:23 +00:00
|
|
|
$order->status = AN_STATUS_EXPIRE;
|
|
|
|
update_record('enrol_authorize', $order);
|
|
|
|
}
|
* Update record as soon as possible. If update/insert record fails email to admin to have update manually.
* ignore_user_abort(true) at critical section (before fwrite($fp, "POST /gateway/transact.dll).
This is last change to ignore request for user.
* Made some functions "static" to call function directly. So, no need new enrolment_plugin_authorize() instance.
Now, these are static:
get_list_of_creditcards, zero_cost, get_course_cost, prevent_double_paid, email_to_admin, check_openssl_loaded
* Some mtrace cleanup. Removed default new line.
This is big work. When PHP5 is required for moodle in the future, I will add static modifier to functions.
Now and future, this plugin is/will unbreakable; Merged from MOODLE_16_STABLE. :)
2006-07-24 12:19:20 +00:00
|
|
|
return $isexpired;
|
2006-07-10 10:17:23 +00:00
|
|
|
}
|
|
|
|
|
2005-12-09 12:00:28 +00:00
|
|
|
/**
|
* Update record as soon as possible. If update/insert record fails email to admin to have update manually.
* ignore_user_abort(true) at critical section (before fwrite($fp, "POST /gateway/transact.dll).
This is last change to ignore request for user.
* Made some functions "static" to call function directly. So, no need new enrolment_plugin_authorize() instance.
Now, these are static:
get_list_of_creditcards, zero_cost, get_course_cost, prevent_double_paid, email_to_admin, check_openssl_loaded
* Some mtrace cleanup. Removed default new line.
This is big work. When PHP5 is required for moodle in the future, I will add static modifier to functions.
Now and future, this plugin is/will unbreakable; Merged from MOODLE_16_STABLE. :)
2006-07-24 12:19:20 +00:00
|
|
|
* Performs an action on authorize.net and updates/inserts records. If record update fails,
|
|
|
|
* sends email to admin.
|
2005-12-09 12:00:28 +00:00
|
|
|
*
|
2006-01-02 09:30:35 +00:00
|
|
|
* @param object &$order Which transaction data will be sent. See enrol_authorize table.
|
* Update record as soon as possible. If update/insert record fails email to admin to have update manually.
* ignore_user_abort(true) at critical section (before fwrite($fp, "POST /gateway/transact.dll).
This is last change to ignore request for user.
* Made some functions "static" to call function directly. So, no need new enrolment_plugin_authorize() instance.
Now, these are static:
get_list_of_creditcards, zero_cost, get_course_cost, prevent_double_paid, email_to_admin, check_openssl_loaded
* Some mtrace cleanup. Removed default new line.
This is big work. When PHP5 is required for moodle in the future, I will add static modifier to functions.
Now and future, this plugin is/will unbreakable; Merged from MOODLE_16_STABLE. :)
2006-07-24 12:19:20 +00:00
|
|
|
* @param string &$message Information about error message if this function returns false.
|
|
|
|
* @param object &$extra Extra data that used for refunding and credit card information.
|
2005-12-09 12:00:28 +00:00
|
|
|
* @param int $action Which action will be performed. See AN_ACTION_*
|
2006-08-30 14:06:40 +00:00
|
|
|
* @param string $method Transaction method. AN_METHOD_CC or AN_METHOD_ECHECK
|
* Update record as soon as possible. If update/insert record fails email to admin to have update manually.
* ignore_user_abort(true) at critical section (before fwrite($fp, "POST /gateway/transact.dll).
This is last change to ignore request for user.
* Made some functions "static" to call function directly. So, no need new enrolment_plugin_authorize() instance.
Now, these are static:
get_list_of_creditcards, zero_cost, get_course_cost, prevent_double_paid, email_to_admin, check_openssl_loaded
* Some mtrace cleanup. Removed default new line.
This is big work. When PHP5 is required for moodle in the future, I will add static modifier to functions.
Now and future, this plugin is/will unbreakable; Merged from MOODLE_16_STABLE. :)
2006-07-24 12:19:20 +00:00
|
|
|
* @return bool true Transaction was successful, false otherwise. Use $message for reason.
|
2005-12-09 12:00:28 +00:00
|
|
|
* @author Ethem Evlice <ethem a.t evlice d.o.t com>
|
|
|
|
* @uses $CFG
|
|
|
|
*/
|
2006-08-30 10:29:10 +00:00
|
|
|
function authorize_action(&$order, &$message, &$extra, $action=AN_ACTION_NONE, $method=AN_METHOD_CC)
|
2005-12-09 12:00:28 +00:00
|
|
|
{
|
|
|
|
global $CFG;
|
|
|
|
static $conststring;
|
2005-12-12 17:32:00 +00:00
|
|
|
|
2005-12-22 15:24:05 +00:00
|
|
|
if (!isset($conststring)) {
|
2006-08-30 10:29:10 +00:00
|
|
|
$constdata = array(
|
2005-12-22 15:24:05 +00:00
|
|
|
'x_version' => '3.1',
|
|
|
|
'x_delim_data' => 'True',
|
|
|
|
'x_delim_char' => AN_DELIM,
|
|
|
|
'x_encap_char' => AN_ENCAP,
|
2006-01-06 12:14:17 +00:00
|
|
|
'x_relay_response' => 'FALSE',
|
2006-08-30 10:29:10 +00:00
|
|
|
'x_login' => $CFG->an_login
|
2005-12-09 12:00:28 +00:00
|
|
|
);
|
|
|
|
$str = '';
|
2006-08-30 10:29:10 +00:00
|
|
|
foreach($constdata as $ky => $vl) {
|
2005-12-14 15:47:37 +00:00
|
|
|
$str .= $ky . '=' . urlencode($vl) . '&';
|
|
|
|
}
|
2005-12-09 12:00:28 +00:00
|
|
|
$str .= (!empty($CFG->an_tran_key)) ?
|
2005-12-22 15:24:05 +00:00
|
|
|
'x_tran_key=' . urlencode($CFG->an_tran_key):
|
|
|
|
'x_password=' . urlencode($CFG->an_password);
|
2005-12-09 12:00:28 +00:00
|
|
|
|
2005-12-12 17:32:00 +00:00
|
|
|
$conststring = $str;
|
2006-08-30 10:29:10 +00:00
|
|
|
$str = '';
|
2005-12-09 12:00:28 +00:00
|
|
|
}
|
2005-12-12 17:32:00 +00:00
|
|
|
|
* Update record as soon as possible. If update/insert record fails email to admin to have update manually.
* ignore_user_abort(true) at critical section (before fwrite($fp, "POST /gateway/transact.dll).
This is last change to ignore request for user.
* Made some functions "static" to call function directly. So, no need new enrolment_plugin_authorize() instance.
Now, these are static:
get_list_of_creditcards, zero_cost, get_course_cost, prevent_double_paid, email_to_admin, check_openssl_loaded
* Some mtrace cleanup. Removed default new line.
This is big work. When PHP5 is required for moodle in the future, I will add static modifier to functions.
Now and future, this plugin is/will unbreakable; Merged from MOODLE_16_STABLE. :)
2006-07-24 12:19:20 +00:00
|
|
|
if (empty($order) or empty($order->id)) {
|
2006-01-19 14:57:23 +00:00
|
|
|
$message = "Check order->id!";
|
2005-12-09 12:00:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
2006-08-30 10:29:10 +00:00
|
|
|
|
|
|
|
if (empty($method)) {
|
|
|
|
$method = AN_METHOD_CC;
|
|
|
|
}
|
|
|
|
elseif ($method != AN_METHOD_CC && $method != AN_METHOD_ECHECK) {
|
2006-08-30 14:06:40 +00:00
|
|
|
$message = "Invalid method: $method";
|
2006-08-30 10:29:10 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-08-30 14:06:40 +00:00
|
|
|
$action = intval($action);
|
2006-08-30 10:29:10 +00:00
|
|
|
if ($method == AN_METHOD_ECHECK) {
|
|
|
|
if ($action != AN_ACTION_AUTH_CAPTURE && $action != AN_ACTION_CREDIT) {
|
|
|
|
$message = "Please perform AUTH_CAPTURE or CREDIT for echecks";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($action <= AN_ACTION_NONE or $action > AN_ACTION_VOID) {
|
* Update record as soon as possible. If update/insert record fails email to admin to have update manually.
* ignore_user_abort(true) at critical section (before fwrite($fp, "POST /gateway/transact.dll).
This is last change to ignore request for user.
* Made some functions "static" to call function directly. So, no need new enrolment_plugin_authorize() instance.
Now, these are static:
get_list_of_creditcards, zero_cost, get_course_cost, prevent_double_paid, email_to_admin, check_openssl_loaded
* Some mtrace cleanup. Removed default new line.
This is big work. When PHP5 is required for moodle in the future, I will add static modifier to functions.
Now and future, this plugin is/will unbreakable; Merged from MOODLE_16_STABLE. :)
2006-07-24 12:19:20 +00:00
|
|
|
$message = "Invalid action!";
|
2005-12-09 12:00:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
2005-12-12 17:32:00 +00:00
|
|
|
|
2005-12-09 12:00:28 +00:00
|
|
|
$poststring = $conststring;
|
2006-08-30 14:06:40 +00:00
|
|
|
$poststring .= '&x_method=' . $method;
|
|
|
|
|
|
|
|
$test = !empty($CFG->an_test);
|
2006-08-30 10:29:10 +00:00
|
|
|
$poststring .= '&x_test_request=' . ($test ? 'TRUE' : 'FALSE');
|
2005-12-22 15:24:05 +00:00
|
|
|
|
2005-12-09 12:00:28 +00:00
|
|
|
switch ($action) {
|
|
|
|
case AN_ACTION_AUTH_ONLY:
|
2006-06-13 07:58:04 +00:00
|
|
|
case AN_ACTION_CAPTURE_ONLY:
|
2005-12-09 12:00:28 +00:00
|
|
|
case AN_ACTION_AUTH_CAPTURE:
|
|
|
|
{
|
|
|
|
if ($order->status != AN_STATUS_NONE) {
|
2006-01-19 14:57:23 +00:00
|
|
|
$message = "Order status must be AN_STATUS_NONE(0)!";
|
2005-12-09 12:00:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
2006-07-20 14:48:03 +00:00
|
|
|
elseif (empty($extra)) {
|
2006-01-19 14:57:23 +00:00
|
|
|
$message = "Need extra fields!";
|
2005-12-12 17:32:00 +00:00
|
|
|
return false;
|
2005-12-09 12:00:28 +00:00
|
|
|
}
|
2006-07-20 14:48:03 +00:00
|
|
|
elseif (($action == AN_ACTION_CAPTURE_ONLY) and empty($extra->x_auth_code)) {
|
|
|
|
$message = "x_auth_code is required for capture only transactions!";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-12-09 12:00:28 +00:00
|
|
|
$ext = (array)$extra;
|
2006-06-13 07:58:04 +00:00
|
|
|
$poststring .= '&x_type=' . (($action==AN_ACTION_AUTH_ONLY)
|
|
|
|
? 'AUTH_ONLY' :( ($action==AN_ACTION_CAPTURE_ONLY)
|
|
|
|
? 'CAPTURE_ONLY' : 'AUTH_CAPTURE'));
|
2005-12-09 12:00:28 +00:00
|
|
|
foreach($ext as $k => $v) {
|
2005-12-22 15:24:05 +00:00
|
|
|
$poststring .= '&' . $k . '=' . urlencode($v);
|
2005-12-09 12:00:28 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case AN_ACTION_PRIOR_AUTH_CAPTURE:
|
|
|
|
{
|
|
|
|
if ($order->status != AN_STATUS_AUTH) {
|
2006-01-19 14:57:23 +00:00
|
|
|
$message = "Order status must be authorized!";
|
2005-12-09 12:00:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
2006-07-10 10:17:23 +00:00
|
|
|
if (authorize_expired($order)) {
|
2005-12-12 17:32:00 +00:00
|
|
|
$message = "Transaction must be captured within 30 days. EXPIRED!";
|
|
|
|
return false;
|
|
|
|
}
|
2005-12-22 15:24:05 +00:00
|
|
|
$poststring .= '&x_type=PRIOR_AUTH_CAPTURE&x_trans_id=' . urlencode($order->transid);
|
2005-12-12 17:32:00 +00:00
|
|
|
break;
|
2005-12-09 12:00:28 +00:00
|
|
|
}
|
2005-12-12 17:32:00 +00:00
|
|
|
|
|
|
|
case AN_ACTION_CREDIT:
|
2005-12-09 12:00:28 +00:00
|
|
|
{
|
2005-12-22 15:24:05 +00:00
|
|
|
if ($order->status != AN_STATUS_AUTHCAPTURE) {
|
2006-01-19 14:57:23 +00:00
|
|
|
$message = "Order status must be authorized/captured!";
|
2005-12-22 15:24:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
2006-07-10 10:17:23 +00:00
|
|
|
if (!authorize_settled($order)) {
|
2006-01-19 14:57:23 +00:00
|
|
|
$message = "Order must be settled. Try VOID, check Cut-Off time if it fails!";
|
2005-12-12 17:32:00 +00:00
|
|
|
return false;
|
|
|
|
}
|
2006-07-10 10:17:23 +00:00
|
|
|
$timenowsettle = authorize_getsettletime(time());
|
2005-12-22 15:24:05 +00:00
|
|
|
$timediff = $timenowsettle - (120 * 3600 * 24);
|
|
|
|
if ($order->settletime < $timediff) {
|
2006-01-19 14:57:23 +00:00
|
|
|
$message = "Order must be credited within 120 days!";
|
2005-12-12 17:32:00 +00:00
|
|
|
return false;
|
|
|
|
}
|
2005-12-22 15:24:05 +00:00
|
|
|
if (empty($extra)) {
|
* Update record as soon as possible. If update/insert record fails email to admin to have update manually.
* ignore_user_abort(true) at critical section (before fwrite($fp, "POST /gateway/transact.dll).
This is last change to ignore request for user.
* Made some functions "static" to call function directly. So, no need new enrolment_plugin_authorize() instance.
Now, these are static:
get_list_of_creditcards, zero_cost, get_course_cost, prevent_double_paid, email_to_admin, check_openssl_loaded
* Some mtrace cleanup. Removed default new line.
This is big work. When PHP5 is required for moodle in the future, I will add static modifier to functions.
Now and future, this plugin is/will unbreakable; Merged from MOODLE_16_STABLE. :)
2006-07-24 12:19:20 +00:00
|
|
|
$message = "Need extra fields to REFUND!";
|
2005-12-22 15:24:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
2006-01-19 14:57:23 +00:00
|
|
|
$total = floatval($extra->sum) + floatval($extra->amount);
|
2005-12-14 15:47:37 +00:00
|
|
|
if (($extra->amount == 0) || ($total > $order->amount)) {
|
2005-12-12 17:32:00 +00:00
|
|
|
$message = "Can be credited up to original amount.";
|
|
|
|
return false;
|
|
|
|
}
|
2005-12-22 15:24:05 +00:00
|
|
|
$poststring .= '&x_type=CREDIT&x_trans_id=' . urlencode($order->transid);
|
|
|
|
$poststring .= '&x_card_num=' . sprintf("%04d", intval($order->cclastfour));
|
|
|
|
$poststring .= '&x_currency_code=' . urlencode($order->currency);
|
|
|
|
$poststring .= '&x_amount=' . urlencode($extra->amount);
|
2005-12-12 17:32:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case AN_ACTION_VOID:
|
|
|
|
{
|
2005-12-14 15:47:37 +00:00
|
|
|
if ($order->status == AN_STATUS_AUTH) {
|
2006-07-10 10:17:23 +00:00
|
|
|
if (authorize_expired($order)) {
|
2006-01-19 14:57:23 +00:00
|
|
|
$message = "Authorized transaction must be voided within 30 days. EXPIRED!";
|
2005-12-14 15:47:37 +00:00
|
|
|
return false;
|
|
|
|
}
|
2005-12-22 15:24:05 +00:00
|
|
|
}
|
2006-07-10 10:17:23 +00:00
|
|
|
elseif ($order->status == AN_STATUS_AUTHCAPTURE or $order->status == AN_STATUS_CREDIT) {
|
|
|
|
if (authorize_settled($order)) {
|
2005-12-22 15:24:05 +00:00
|
|
|
$message = "Settled transaction cannot be voided. Check Cut-Off time!";
|
2005-12-14 15:47:37 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2005-12-22 15:24:05 +00:00
|
|
|
else {
|
* Update record as soon as possible. If update/insert record fails email to admin to have update manually.
* ignore_user_abort(true) at critical section (before fwrite($fp, "POST /gateway/transact.dll).
This is last change to ignore request for user.
* Made some functions "static" to call function directly. So, no need new enrolment_plugin_authorize() instance.
Now, these are static:
get_list_of_creditcards, zero_cost, get_course_cost, prevent_double_paid, email_to_admin, check_openssl_loaded
* Some mtrace cleanup. Removed default new line.
This is big work. When PHP5 is required for moodle in the future, I will add static modifier to functions.
Now and future, this plugin is/will unbreakable; Merged from MOODLE_16_STABLE. :)
2006-07-24 12:19:20 +00:00
|
|
|
$message = "Order status must be authorized/pending capture or captured-refunded/pending settlement!";
|
2005-12-22 15:24:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$poststring .= '&x_type=VOID&x_trans_id=' . urlencode($order->transid);
|
|
|
|
break;
|
2005-12-09 12:00:28 +00:00
|
|
|
}
|
|
|
|
|
2006-01-19 14:57:23 +00:00
|
|
|
default: {
|
* Update record as soon as possible. If update/insert record fails email to admin to have update manually.
* ignore_user_abort(true) at critical section (before fwrite($fp, "POST /gateway/transact.dll).
This is last change to ignore request for user.
* Made some functions "static" to call function directly. So, no need new enrolment_plugin_authorize() instance.
Now, these are static:
get_list_of_creditcards, zero_cost, get_course_cost, prevent_double_paid, email_to_admin, check_openssl_loaded
* Some mtrace cleanup. Removed default new line.
This is big work. When PHP5 is required for moodle in the future, I will add static modifier to functions.
Now and future, this plugin is/will unbreakable; Merged from MOODLE_16_STABLE. :)
2006-07-24 12:19:20 +00:00
|
|
|
$message = "Invalid action: $action";
|
2005-12-09 12:00:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2005-12-12 17:32:00 +00:00
|
|
|
|
2006-01-19 14:57:23 +00:00
|
|
|
$referer = '';
|
2005-12-22 15:24:05 +00:00
|
|
|
if (! (empty($CFG->an_referer) || $CFG->an_referer == "http://")) {
|
2006-01-19 14:57:23 +00:00
|
|
|
$referer = "Referer: $CFG->an_referer\r\n";
|
2005-12-09 12:00:28 +00:00
|
|
|
}
|
2005-12-12 17:32:00 +00:00
|
|
|
|
2006-01-20 16:04:52 +00:00
|
|
|
$host = $test ? 'certification.authorize.net' : 'secure.authorize.net';
|
|
|
|
$fp = fsockopen("ssl://$host", 443, $errno, $errstr, 60);
|
2005-12-09 12:00:28 +00:00
|
|
|
if (!$fp) {
|
|
|
|
$message = "no connection: $errstr ($errno)";
|
|
|
|
return false;
|
|
|
|
}
|
2005-12-12 17:32:00 +00:00
|
|
|
|
2006-07-24 16:32:38 +00:00
|
|
|
// critical section
|
|
|
|
@ignore_user_abort(true);
|
|
|
|
if (intval(ini_get('max_execution_time')) > 0) {
|
|
|
|
@set_time_limit(300);
|
|
|
|
}
|
|
|
|
|
2006-01-20 16:04:52 +00:00
|
|
|
fwrite($fp, "POST /gateway/transact.dll HTTP/1.0\r\n" .
|
2006-01-19 14:57:23 +00:00
|
|
|
"Host: $host\r\n" . $referer .
|
2005-12-22 15:24:05 +00:00
|
|
|
"Content-type: application/x-www-form-urlencoded\r\n" .
|
|
|
|
"Connection: close\r\n" .
|
|
|
|
"Content-length: " . strlen($poststring) . "\r\n\r\n" .
|
|
|
|
$poststring . "\r\n"
|
2005-12-09 12:00:28 +00:00
|
|
|
);
|
2005-12-12 17:32:00 +00:00
|
|
|
|
2005-12-09 12:00:28 +00:00
|
|
|
$tmpstr = '';
|
|
|
|
while(!feof($fp) && !stristr($tmpstr, 'content-length')) {
|
|
|
|
$tmpstr = fgets($fp, 4096);
|
|
|
|
}
|
|
|
|
if (!stristr($tmpstr, 'content-length')) {
|
|
|
|
$message = "content-length error";
|
|
|
|
@fclose($fp);
|
|
|
|
return false;
|
|
|
|
}
|
2005-12-22 15:24:05 +00:00
|
|
|
$length = trim(substr($tmpstr, strpos($tmpstr,'content-length')+15));
|
2005-12-09 12:00:28 +00:00
|
|
|
fgets($fp, 4096);
|
|
|
|
$data = fgets($fp, $length);
|
|
|
|
@fclose($fp);
|
|
|
|
$response = explode(AN_ENCAP.AN_DELIM.AN_ENCAP, $data);
|
|
|
|
if ($response === false) {
|
|
|
|
$message = "response error";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$rcount = count($response) - 1;
|
|
|
|
if ($response[0]{0} == AN_ENCAP) {
|
|
|
|
$response[0] = substr($response[0], 1);
|
|
|
|
}
|
|
|
|
if (substr($response[$rcount], -1) == AN_ENCAP) {
|
|
|
|
$response[$rcount] = substr($response[$rcount], 0, -1);
|
|
|
|
}
|
2005-12-12 17:32:00 +00:00
|
|
|
|
2005-12-22 15:24:05 +00:00
|
|
|
if ($response[0] == AN_APPROVED)
|
|
|
|
{
|
2006-01-19 14:57:23 +00:00
|
|
|
$transid = intval($response[6]);
|
2006-01-20 16:04:52 +00:00
|
|
|
if ($test || $transid == 0) {
|
2005-12-26 19:21:37 +00:00
|
|
|
return true; // don't update original transaction in test mode.
|
|
|
|
}
|
2005-12-09 12:00:28 +00:00
|
|
|
switch ($action) {
|
|
|
|
case AN_ACTION_AUTH_ONLY:
|
2006-06-13 07:58:04 +00:00
|
|
|
case AN_ACTION_CAPTURE_ONLY:
|
2005-12-09 12:00:28 +00:00
|
|
|
case AN_ACTION_AUTH_CAPTURE:
|
2005-12-22 15:24:05 +00:00
|
|
|
case AN_ACTION_PRIOR_AUTH_CAPTURE:
|
|
|
|
{
|
2006-01-19 14:57:23 +00:00
|
|
|
$order->transid = $transid;
|
2005-12-22 15:24:05 +00:00
|
|
|
if ($action == AN_ACTION_AUTH_ONLY) {
|
|
|
|
$order->status = AN_STATUS_AUTH;
|
2006-08-29 09:04:03 +00:00
|
|
|
// don't update order->settletime
|
2005-12-22 15:24:05 +00:00
|
|
|
} else {
|
|
|
|
$order->status = AN_STATUS_AUTHCAPTURE;
|
2006-07-10 10:17:23 +00:00
|
|
|
$order->settletime = authorize_getsettletime(time());
|
2005-12-22 15:24:05 +00:00
|
|
|
}
|
* Update record as soon as possible. If update/insert record fails email to admin to have update manually.
* ignore_user_abort(true) at critical section (before fwrite($fp, "POST /gateway/transact.dll).
This is last change to ignore request for user.
* Made some functions "static" to call function directly. So, no need new enrolment_plugin_authorize() instance.
Now, these are static:
get_list_of_creditcards, zero_cost, get_course_cost, prevent_double_paid, email_to_admin, check_openssl_loaded
* Some mtrace cleanup. Removed default new line.
This is big work. When PHP5 is required for moodle in the future, I will add static modifier to functions.
Now and future, this plugin is/will unbreakable; Merged from MOODLE_16_STABLE. :)
2006-07-24 12:19:20 +00:00
|
|
|
if (! update_record('enrol_authorize', $order)) {
|
|
|
|
enrolment_plugin_authorize::email_to_admin("Error while trying to update data " .
|
|
|
|
"in table enrol_authorize. Please edit manually this record: ID=$order->id.", $order);
|
|
|
|
}
|
2005-12-22 15:24:05 +00:00
|
|
|
break;
|
2005-12-12 17:32:00 +00:00
|
|
|
}
|
2005-12-22 15:24:05 +00:00
|
|
|
case AN_ACTION_CREDIT:
|
|
|
|
{
|
|
|
|
// Credit generates new transaction id.
|
|
|
|
// So, $extra must be updated, not $order.
|
|
|
|
$extra->status = AN_STATUS_CREDIT;
|
2006-01-19 14:57:23 +00:00
|
|
|
$extra->transid = $transid;
|
2006-07-10 10:17:23 +00:00
|
|
|
$extra->settletime = authorize_getsettletime(time());
|
* Update record as soon as possible. If update/insert record fails email to admin to have update manually.
* ignore_user_abort(true) at critical section (before fwrite($fp, "POST /gateway/transact.dll).
This is last change to ignore request for user.
* Made some functions "static" to call function directly. So, no need new enrolment_plugin_authorize() instance.
Now, these are static:
get_list_of_creditcards, zero_cost, get_course_cost, prevent_double_paid, email_to_admin, check_openssl_loaded
* Some mtrace cleanup. Removed default new line.
This is big work. When PHP5 is required for moodle in the future, I will add static modifier to functions.
Now and future, this plugin is/will unbreakable; Merged from MOODLE_16_STABLE. :)
2006-07-24 12:19:20 +00:00
|
|
|
unset($extra->sum); // this is not used in refunds table.
|
|
|
|
if (! $extra->id = insert_record('enrol_authorize_refunds', $extra)) {
|
|
|
|
enrolment_plugin_authorize::email_to_admin("Error while trying to insert data " .
|
|
|
|
"into table enrol_authorize_refunds. Please add manually this record:", $extra);
|
|
|
|
}
|
2005-12-22 15:24:05 +00:00
|
|
|
break;
|
2005-12-12 17:32:00 +00:00
|
|
|
}
|
|
|
|
case AN_ACTION_VOID:
|
2005-12-22 15:24:05 +00:00
|
|
|
{
|
2006-08-29 09:04:03 +00:00
|
|
|
$tableupdate = ($order->status == AN_STATUS_CREDIT) ? 'enrol_authorize_refunds' : 'enrol_authorize';
|
* Update record as soon as possible. If update/insert record fails email to admin to have update manually.
* ignore_user_abort(true) at critical section (before fwrite($fp, "POST /gateway/transact.dll).
This is last change to ignore request for user.
* Made some functions "static" to call function directly. So, no need new enrolment_plugin_authorize() instance.
Now, these are static:
get_list_of_creditcards, zero_cost, get_course_cost, prevent_double_paid, email_to_admin, check_openssl_loaded
* Some mtrace cleanup. Removed default new line.
This is big work. When PHP5 is required for moodle in the future, I will add static modifier to functions.
Now and future, this plugin is/will unbreakable; Merged from MOODLE_16_STABLE. :)
2006-07-24 12:19:20 +00:00
|
|
|
$order->status = AN_STATUS_VOID;
|
2006-08-29 09:04:03 +00:00
|
|
|
// don't update order->settletime
|
* Update record as soon as possible. If update/insert record fails email to admin to have update manually.
* ignore_user_abort(true) at critical section (before fwrite($fp, "POST /gateway/transact.dll).
This is last change to ignore request for user.
* Made some functions "static" to call function directly. So, no need new enrolment_plugin_authorize() instance.
Now, these are static:
get_list_of_creditcards, zero_cost, get_course_cost, prevent_double_paid, email_to_admin, check_openssl_loaded
* Some mtrace cleanup. Removed default new line.
This is big work. When PHP5 is required for moodle in the future, I will add static modifier to functions.
Now and future, this plugin is/will unbreakable; Merged from MOODLE_16_STABLE. :)
2006-07-24 12:19:20 +00:00
|
|
|
if (! update_record($tableupdate, $order)) {
|
|
|
|
enrolment_plugin_authorize::email_to_admin("Error while trying to update data " .
|
|
|
|
"in table $tableupdate. Please edit manually this record: ID=$order->id.", $order);
|
|
|
|
}
|
2005-12-22 15:24:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: return false;
|
2005-12-09 12:00:28 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2005-12-22 15:24:05 +00:00
|
|
|
else
|
|
|
|
{
|
2006-01-19 14:57:23 +00:00
|
|
|
$reason = "reason" . $response[2];
|
|
|
|
$message = get_string($reason, "enrol_authorize");
|
|
|
|
if ($message == '[[' . $reason . ']]') {
|
|
|
|
$message = isset($response[3]) ? $response[3] : 'unknown error';
|
|
|
|
}
|
2006-08-30 14:06:40 +00:00
|
|
|
if ($method == AN_METHOD_CC and !empty($CFG->an_avs)) {
|
2006-01-19 14:57:23 +00:00
|
|
|
$avs = "avs" . strtolower($response[5]);
|
|
|
|
$stravs = get_string($avs, "enrol_authorize");
|
2006-05-13 08:53:34 +00:00
|
|
|
$message .= "<br />" . get_string("avsresult", "enrol_authorize", $stravs);
|
2006-01-19 14:57:23 +00:00
|
|
|
}
|
2005-12-09 12:00:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|