Beispiel #1
0
/**
 * authorize_get_status_action
 *
 * @param object $order Order details.
 * @return object
 */
function authorize_get_status_action($order)
{
    global $CFG;
    static $newordertime = 0;
    if (0 == $newordertime) {
        $newordertime = time() - 120;
        // -2 minutes. Order may be still in process.
    }
    $ret = new stdClass();
    $ret->actions = array();
    $canmanage = has_capability('enrol/authorize:managepayments', context_course::instance($order->courseid));
    if (floatval($order->transid) == 0) {
        // test transaction or new order
        if ($order->timecreated < $newordertime) {
            if ($canmanage) {
                $ret->actions = array(ORDER_DELETE);
            }
            $ret->status = 'tested';
        } else {
            $ret->status = 'new';
        }
        return $ret;
    }
    switch ($order->status) {
        case AN_STATUS_AUTH:
            if (AuthorizeNet::expired($order)) {
                if ($canmanage) {
                    $ret->actions = array(ORDER_DELETE);
                }
                $ret->status = 'expired';
            } else {
                if ($canmanage) {
                    $ret->actions = array(ORDER_CAPTURE, ORDER_VOID);
                }
                $ret->status = 'authorizedpendingcapture';
            }
            return $ret;
        case AN_STATUS_AUTHCAPTURE:
            if (AuthorizeNet::settled($order)) {
                if ($canmanage) {
                    if ($order->paymentmethod == AN_METHOD_CC || $order->paymentmethod == AN_METHOD_ECHECK && !empty($order->refundinfo)) {
                        $ret->actions = array(ORDER_REFUND);
                    }
                }
                $ret->status = 'settled';
            } else {
                if ($order->paymentmethod == AN_METHOD_CC && $canmanage) {
                    $ret->actions = array(ORDER_VOID);
                }
                $ret->status = 'capturedpendingsettle';
            }
            return $ret;
        case AN_STATUS_CREDIT:
            if (AuthorizeNet::settled($order)) {
                $ret->status = 'settled';
            } else {
                if ($order->paymentmethod == AN_METHOD_CC && $canmanage) {
                    $ret->actions = array(ORDER_VOID);
                }
                $ret->status = 'refunded';
            }
            return $ret;
        case AN_STATUS_VOID:
            $ret->status = 'cancelled';
            return $ret;
        case AN_STATUS_EXPIRE:
            if ($canmanage) {
                $ret->actions = array(ORDER_DELETE);
            }
            $ret->status = 'expired';
            return $ret;
        case AN_STATUS_UNDERREVIEW:
            $ret->status = 'underreview';
            return $ret;
        case AN_STATUS_APPROVEDREVIEW:
            $ret->status = 'approvedreview';
            return $ret;
        case AN_STATUS_REVIEWFAILED:
            if ($canmanage) {
                $ret->actions = array(ORDER_DELETE);
            }
            $ret->status = 'reviewfailed';
            return $ret;
        default:
            return $ret;
    }
}