Пример #1
0
 public function testAdvancedAIM()
 {
     $auth = new AuthorizeNetAIM();
     $auth->amount = "45.00";
     // Use eCheck:
     $auth->setECheck('121042882', '123456789123', 'CHECKING', 'Bank of Earth', 'Jane Doe', 'WEB');
     // Set multiple line items:
     $auth->addLineItem('item1', 'Golf tees', 'Blue tees', '2', '5.00', 'N');
     $auth->addLineItem('item2', 'Golf shirt', 'XL', '1', '40.00', 'N');
     // Set Invoice Number:
     $auth->invoice_num = time();
     // Set a Merchant Defined Field:
     $auth->setCustomField("entrance_source", "Search Engine");
     // Authorize Only:
     $response = $auth->authorizeOnly();
     $this->assertTrue($response->approved);
     if ($response->approved) {
         $auth_code = $response->transaction_id;
         // Now capture:
         $capture = new AuthorizeNetAIM();
         $capture_response = $capture->priorAuthCapture($auth_code);
         $this->assertTrue($capture_response->approved);
         // Now void:
         $void = new AuthorizeNetAIM();
         $void_response = $void->void($capture_response->transaction_id);
         $this->assertTrue($void_response->approved);
     }
 }
Пример #2
0
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Need to process payment, record the transaction, update the order_contents table, and update the inventory.
    // Get the order information:
    $q = "SELECT customer_id, total, transaction_id FROM orders AS o JOIN transactions AS t ON (o.id=t.order_id AND t.type='auth_only' AND t.response_code=1) WHERE o.id={$order_id}";
    $r = mysqli_query($dbc, $q);
    if (mysqli_num_rows($r) === 1) {
        // Get the returned values:
        list($customer_id, $order_total, $trans_id) = mysqli_fetch_array($r, MYSQL_NUM);
        // Check for a positive order total:
        if ($order_total > 0) {
            // Make the request to the payment gateway:
            // Make the request to the payment gateway:
            require '../library/anet_php_sdk/AuthorizeNet.php';
            $aim = new AuthorizeNetAIM(API_LOGIN_ID, TRANSACTION_KEY);
            // Capture:
            $response = $aim->priorAuthCapture($trans_id . 1, $order_total / 100);
            // Add slashes to two text values:
            $reason = addslashes($response->response_reason_text);
            $full_response = addslashes($response->response);
            // Record the transaction:
            $r = mysqli_query($dbc, "CALL add_transaction({$order_id}, '{$response->transaction_type}', {$order_total}, {$response->response_code}, '{$reason}', {$response->transaction_id}, '{$full_response}')");
            // Upon success, update the order and the inventory:
            if ($response->approved) {
                $message = 'The payment has been made. You may now ship the order.';
                // Update order_contents:
                $q = "UPDATE order_contents SET ship_date=NOW() WHERE order_id={$order_id}";
                $r = mysqli_query($dbc, $q);
                // Update the inventory...
                $q = 'UPDATE specific_coffees AS sc, order_contents AS oc SET sc.stock=sc.stock-oc.quantity WHERE sc.id=oc.product_id AND oc.product_type="coffee" AND oc.order_id=' . $order_id;
                $r = mysqli_query($dbc, $q);
                $q = 'UPDATE non_coffee_products AS ncp, order_contents AS oc SET ncp.stock=ncp.stock-oc.quantity WHERE ncp.id=oc.product_id AND oc.product_type="goodies" AND oc.order_id=' . $order_id;
function authorizenet_capture_meta_box_action($order_id, $items)
{
    if (isset($items['_authorizenet_capture_charge']) && 1 == $items['_authorizenet_capture_charge']) {
        global $woocommerce;
        $wc_order = new WC_Order($order_id);
        $trx_id = get_post_meta($order_id, '_transaction_id', true);
        $amount = $wc_order->order_total;
        if (class_exists('WC_Authorizenet_Gateway')) {
            $authorizemetpg = new WC_Authorizenet_Gateway();
        }
        $capture = new AuthorizeNetAIM();
        $capturetrx = $capture->priorAuthCapture($trx_id, $amount);
        if (1 == $capturetrx->approved) {
            $wc_order->add_order_note(__($capturetrx->response_reason_text . 'on' . date("d-m-Y h:i:s e") . 'with Transaction ID = ' . $capturetrx->transaction_id . ' using ' . strtoupper($capturetrx->transaction_type) . ' and authorization code ' . $capturetrx->authorization_code, 'woocommerce'));
            update_post_meta($order_id, '_authorizenet_charge_status', 'charge_auth_captured_later');
        } else {
            $wc_order->add_order_note(__($capturetrx->response_reason_text . '-' . $capturetrx->error_message . ' on ' . date("d-m-Y h:i:s e") . ' using ' . strtoupper($capturetrx->transaction_type), 'woocommerce'));
        }
    }
}
Пример #4
0
<?php

session_start();
require_once 'AuthorizeNet.php';
define("AUTHORIZENET_API_LOGIN_ID", "86jrDx8naX49");
define("AUTHORIZENET_TRANSACTION_KEY", "8x88td44D8PFgeS5");
define("AUTHORIZENET_SANDBOX", true);
$capture = new AuthorizeNetAIM();
//authorize
require_once $_SERVER['DOCUMENT_ROOT'] . "/system/includes/dboperations.php";
$invoiceID = $_REQUEST['invoiceid'];
$query = "select id,TRANSACTIONID,AMT from transaction_details where id='{$invoiceID}' and CAPTURED<>1 limit 0,1";
$resultset = mysql_query($query);
if (mysql_num_rows($resultset) > 0) {
    while ($row = mysql_fetch_array($resultset)) {
        $capture->amount = $row['AMT'];
        $capture->trans_id = $row['TRANSACTIONID'];
        $response = $capture->priorAuthCapture();
        if ($response->approved) {
            $update = "update transaction_details set CAPTURED=1, CAPTURED_TIMESTAMP=now(),CAPTURED_ACK='{$response->response_reason_text}' where TRANSACTIONID='{$response->transaction_id}' and CORRELATIONID='{$response->authorization_code}'";
            $result = mysql_query($update) or die(mysql_error());
            if (mysql_affected_rows()) {
                return true;
            } else {
                return false;
            }
        } else {
            mysql_query("update transaction_details set CAPTURED_ACK='Failed' where id='{$invoiceID}'") or die(mysql_error());
        }
    }
}