/**
  * {@inheritDoc}
  *
  * @param GetCustomerProfile $request
  */
 public function execute($request)
 {
     RequestNotSupportedException::assertSupports($this, $request);
     $model = ArrayObject::ensureArrayObject($request->getModel());
     $model->validateNotEmpty(['customerProfileId']);
     $response = $this->api->getCustomerProfile($model->get('customerProfileId'));
     $model->replace(get_object_vars($response));
 }
Пример #2
0
 private function getPaymentHandler()
 {
     $payment = new AuthorizeNet($this->details);
     $payment->setConfigValue('login', 'cnpdev4444');
     $payment->setConfigValue('transactionKey', '623P88zxd6Pj3Pz6');
     $payment->setConfigValue('gateway', 'https://test.authorize.net/gateway/transact.dll');
     $payment->setCardData('4007000000027', '12', '2010', '000');
     $payment->setCardType('Visa');
     return $payment;
 }
Пример #3
0
function authorize_verify_account()
{
    global $USER, $SITE;
    $plugin = enrol_get_plugin('authorize');
    require_once 'authorizenet.class.php';
    $original_antest = $plugin->get_config('an_test');
    $plugin->set_config('an_test', 1);
    // Test mode
    $shortname = format_string($SITE->shortname, true, array('context' => context_course::instance(SITEID)));
    $order = new stdClass();
    $order->id = -1;
    $order->paymentmethod = AN_METHOD_CC;
    $order->refundinfo = '1111';
    $order->ccname = 'Test User';
    $order->courseid = $SITE->id;
    $order->userid = $USER->id;
    $order->status = AN_STATUS_NONE;
    $order->settletime = 0;
    $order->transid = 0;
    $order->timecreated = time();
    $order->amount = '0.01';
    $order->currency = 'USD';
    $extra = new stdClass();
    $extra->x_card_num = '4111111111111111';
    $extra->x_card_code = '123';
    $extra->x_exp_date = "12" . intval(date("Y")) + 5;
    $extra->x_currency_code = $order->currency;
    $extra->x_amount = $order->amount;
    $extra->x_first_name = 'Test';
    $extra->x_last_name = 'User';
    $extra->x_country = $USER->country;
    $extra->x_invoice_num = $order->id;
    $extra->x_description = $shortname . ' - Authorize.net Merchant Account Verification Test';
    $ret = '';
    $message = '';
    if (AN_APPROVED == AuthorizeNet::process($order, $message, $extra, AN_ACTION_AUTH_CAPTURE)) {
        $ret = get_string('verifyaccountresult', 'enrol_authorize', get_string('success'));
    } else {
        $ret = get_string('verifyaccountresult', 'enrol_authorize', $message);
    }
    $plugin->set_config('an_test', $original_antest);
    return $ret;
}
Пример #4
0
 /**
  * Daily cron. It executes at settlement time (default is 00:05).
  *
  * @access private
  */
 private function cron_daily()
 {
     global $CFG, $SITE, $DB;
     $oneday = 86400;
     $timenow = time();
     $onepass = $timenow - $oneday;
     $settlementtime = AuthorizeNet::getsettletime($timenow);
     $timediff30 = $settlementtime - 30 * $oneday;
     $select = "(status=?) AND (timecreated<?)";
     $params = array(AN_STATUS_NONE, $timediff30);
     if ($DB->delete_records_select('enrol_authorize', $select, $params)) {
         mtrace("        orders no transaction made have deleted");
     }
     $select = "(status=?) AND (timecreated<?)";
     $params = array(AN_STATUS_EXPIRE, AN_STATUS_AUTH, $timediff30);
     if ($DB->execute("UPDATE {enrol_authorize} SET status=? WHERE {$select}", $params)) {
         mtrace("        pending orders to expire have updated");
     }
     $timediff60 = $settlementtime - 60 * $oneday;
     $select = "(status=?) AND (timecreated<?)";
     $params = array(AN_STATUS_EXPIRE, $timediff60);
     if ($DB->delete_records_select('enrol_authorize', $select, $params)) {
         mtrace("        orders expired older than 60 days have deleted");
     }
     $adminuser = get_admin();
     $select = "status IN(?,?) AND (timecreated<?) AND (timecreated>?)";
     $params = array(AN_STATUS_UNDERREVIEW, AN_STATUS_APPROVEDREVIEW, $onepass, $timediff60);
     if (($count = $DB->count_records_select('enrol_authorize', $select, $params)) && ($csvusers = get_users_by_capability(get_context_instance(CONTEXT_SYSTEM), 'enrol/authorize:uploadcsv'))) {
         $a = new stdClass();
         $a->count = $count;
         $a->course = $SITE->shortname;
         $subject = get_string('pendingechecksubject', 'enrol_authorize', $a);
         $a = new stdClass();
         $a->count = $count;
         $a->url = $CFG->wwwroot . '/enrol/authorize/uploadcsv.php';
         $message = get_string('pendingecheckemail', 'enrol_authorize', $a);
         foreach ($csvusers as $csvuser) {
             $eventdata = new object();
             $eventdata->modulename = 'moodle';
             $eventdata->userfrom = $adminuser;
             $eventdata->userto = $csvuser;
             $eventdata->subject = $subject;
             $eventdata->fullmessage = $message;
             $eventdata->fullmessageformat = FORMAT_PLAIN;
             $eventdata->fullmessagehtml = '';
             $eventdata->smallmessage = '';
             events_trigger('message_send', $eventdata);
         }
         mtrace("        users who have 'enrol/authorize:uploadcsv' were mailed");
     }
     mtrace("        early pending order warning email for manual capture", ": ");
     if (empty($CFG->an_emailexpired)) {
         mtrace("not enabled");
         return;
     }
     $timediffem = $settlementtime - (30 - intval($CFG->an_emailexpired)) * $oneday;
     $select = "(status=?) AND (timecreated<?) AND (timecreated>?)";
     $params = array(AN_STATUS_AUTH, $timediffem, $timediff30);
     $count = $DB->count_records_select('enrol_authorize', $select, $params);
     if (!$count) {
         mtrace("no orders prior to {$CFG->an_emailexpired} days");
         return;
     }
     mtrace("{$count} orders prior to {$CFG->an_emailexpired} days");
     $a = new stdClass();
     $a->pending = $count;
     $a->days = $CFG->an_emailexpired;
     $a->course = $SITE->shortname;
     $subject = get_string('pendingorderssubject', 'enrol_authorize', $a);
     $a = new stdClass();
     $a->pending = $count;
     $a->days = $CFG->an_emailexpired;
     $a->course = $SITE->fullname;
     $a->enrolurl = "{$CFG->wwwroot}/{$CFG->admin}/enrol_config.php?enrol=authorize";
     $a->url = $CFG->wwwroot . '/enrol/authorize/index.php?status=' . AN_STATUS_AUTH;
     $message = get_string('pendingordersemail', 'enrol_authorize', $a);
     $eventdata = new object();
     $eventdata->modulename = 'moodle';
     $eventdata->userfrom = $adminuser;
     $eventdata->userto = $adminuser;
     $eventdata->subject = $subject;
     $eventdata->fullmessage = $message;
     $eventdata->fullmessageformat = FORMAT_PLAIN;
     $eventdata->fullmessagehtml = '';
     $eventdata->smallmessage = '';
     events_trigger('message_send', $eventdata);
     // Email to payment managers
     if (empty($CFG->an_emailexpiredteacher)) {
         return;
         // email feature disabled for teachers.
     }
     $sorttype = empty($CFG->an_sorttype) ? 'ttl' : $CFG->an_sorttype;
     $sql = "SELECT e.courseid, e.currency, c.fullname, c.shortname,\n                  COUNT(e.courseid) AS cnt, SUM(e.amount) as ttl\n                FROM {enrol_authorize} e\n                  INNER JOIN {course} c ON c.id = e.courseid\n                WHERE (e.status = ?)\n                  AND (e.timecreated < ?)\n                  AND (e.timecreated > ?)\n                GROUP BY e.courseid\n                ORDER BY {$sorttype} DESC";
     $params = array(AN_STATUS_AUTH, $timediffem, $timediff30);
     $rs = $DB->get_recordset_sql($sql, $params);
     foreach ($rs as $courseinfo) {
         $lastcourse = $courseinfo->courseid;
         $context = get_context_instance(CONTEXT_COURSE, $lastcourse);
         if ($paymentmanagers = get_users_by_capability($context, 'enrol/authorize:managepayments')) {
             $a = new stdClass();
             $a->course = $courseinfo->shortname;
             $a->pending = $courseinfo->cnt;
             $a->days = $CFG->an_emailexpired;
             $subject = get_string('pendingorderssubject', 'enrol_authorize', $a);
             $a = new stdClass();
             $a->course = $courseinfo->fullname;
             $a->pending = $courseinfo->cnt;
             $a->currency = $courseinfo->currency;
             $a->sumcost = $courseinfo->ttl;
             $a->days = $CFG->an_emailexpired;
             $a->url = $CFG->wwwroot . '/enrol/authorize/index.php?course=' . $lastcourse . '&amp;status=' . AN_STATUS_AUTH;
             $message = get_string('pendingordersemailteacher', 'enrol_authorize', $a);
             foreach ($paymentmanagers as $paymentmanager) {
                 $eventdata = new object();
                 $eventdata->modulename = 'moodle';
                 $eventdata->userfrom = $adminuser;
                 $eventdata->userto = $paymentmanager;
                 $eventdata->subject = $subject;
                 $eventdata->fullmessage = $message;
                 $eventdata->fullmessageformat = FORMAT_PLAIN;
                 $eventdata->fullmessagehtml = '';
                 $eventdata->smallmessage = '';
                 events_trigger('message_send', $eventdata);
             }
         }
     }
     $rs->close();
 }
Пример #5
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;
    }
}
    margin: 20px 0px 0px 20px;
  }
</style>
</head>
<body>
  <header id="header">
    <h1>Authorize.Net</h1>
  </header>

  <div id="content">
    <?php 
require_once 'Class.AuthorizeNet.php';
/** 
 * Create new Regular Transaction.
 */
$Auth = new AuthorizeNet('YOUR_LOGIN_ID', 'YOUR_TRANS_KEY');
// Merchant's unique API Login ID and Transaction Key
$Auth->setEnvironment('test');
// 'test' (default) or 'live'
$Auth->setTransactionType('AUTH_CAPTURE');
// AUTH_CAPTURE (default), AUTH_ONLY, CAPTURE_ONLY, CREDIT, PRIOR_AUTH_CAPTURE, VOID
$Auth->setPaymentMethod('CC');
// Payment Method - CC (default) or ECHECK
$Auth->setAmount('160.25', TRUE);
// Amount
$Auth->setCCNumber('378282246310005');
// Credit card number
$Auth->setCVV('4685');
// The three- or four-digit number on the back of a credit card
$Auth->setExpiration('11/12');
// Expiration date - MMYY, MM/YY, MM-YY, MMYYYY, MM/YYYY, MM-YYYY