<?php

// Include the paypal library
include_once 'Authorize.php';
// Create an instance of the authorize.net library
$myAuthorize = new Authorize();
// Specify your authorize.net login and secret
$myAuthorize->setUserInfo('YOUR_LOGIN', 'YOUR_SECRET_KEY');
// Specify the url where authorize.net will send the user on success/failure
$myAuthorize->addField('x_Receipt_Link_URL', 'http://YOUR_HOST/payment/authorize_success.php');
// Specify the url where authorize.net will send the IPN
$myAuthorize->addField('x_Relay_URL', 'http://YOUR_HOST/payment/authorize_ipn.php');
// Specify the product information
$myAuthorize->addField('x_Description', 'T-Shirt');
$myAuthorize->addField('x_Amount', '9.99');
$myAuthorize->addField('x_Invoice_num', rand(1, 100));
$myAuthorize->addField('x_Cust_ID', 'muri-khao');
// Enable test mode if needed
$myAuthorize->enableTestMode();
// Let's start the train!
$myAuthorize->submitPayment();
function espresso_display_authnet($payment_data)
{
    extract($payment_data);
    // Setup class
    include_once 'Authorize.php';
    global $org_options;
    $myAuthorize = new Authorize();
    // initiate an instance of the class
    echo '<!--Event Espresso Authorize.net Gateway Version ' . $myAuthorize->gateway_version . '-->';
    $authnet_settings = get_option('event_espresso_authnet_settings');
    $authnet_login_id = empty($authnet_settings['authnet_login_id']) ? '' : $authnet_settings['authnet_login_id'];
    $authnet_transaction_key = empty($authnet_settings['authnet_transaction_key']) ? '' : $authnet_settings['authnet_transaction_key'];
    $button_type = empty($authnet_settings['button_type']) ? '' : $authnet_settings['button_type'];
    //$button_url = $authnet_settings['button_url'];
    $image_url = empty($authnet_settings['image_url']) ? '' : $authnet_settings['image_url'];
    $use_sandbox = $authnet_settings['use_sandbox'];
    $use_testmode = $authnet_settings['test_transactions'];
    if ($use_testmode == true) {
        // Enable test mode if needed
        $myAuthorize->enableTestMode();
    }
    if ($use_sandbox) {
        // Enable test mode if needed
        $myAuthorize->useTestServer();
    }
    $quantity = !empty($quantity) ? $quantity : espresso_count_attendees_for_registration($attendee_id);
    $myAuthorize->setUserInfo($authnet_login_id, $authnet_transaction_key);
    $myAuthorize->addField('x_Relay_URL', home_url() . '/?page_id=' . $org_options['notify_url']);
    $myAuthorize->addField('x_Description', stripslashes_deep($event_name) . ' | ' . __('Reg. ID:', 'event_espresso') . ' ' . $attendee_id . ' | ' . __('Name:', 'event_espresso') . ' ' . stripslashes_deep($fname . ' ' . $lname) . ' | ' . __('Total Registrants:', 'event_espresso') . ' ' . $quantity);
    $myAuthorize->addField('x_Amount', number_format($event_cost, 2));
    $myAuthorize->addField('x_Logo_URL', $image_url);
    $myAuthorize->addField('x_Invoice_num', 'au-' . event_espresso_session_id());
    //Post variables
    $myAuthorize->addField('x_cust_id', $attendee_id);
    $myAuthorize->addField('x_first_name', $fname);
    $myAuthorize->addField('x_last_name', $lname);
    $myAuthorize->addField('x_Email', $attendee_email);
    $myAuthorize->addField('x_Address', $address);
    $myAuthorize->addField('x_City', $city);
    $myAuthorize->addField('x_State', $state);
    $myAuthorize->addField('x_Zip', $zip);
    //Enable this function if you want to send payment notification before the person has paid.
    //This function is copied on the payment processing page
    //event_espresso_send_payment_notification($attendee_id, $txn_id, $amount_pd);
    //Decide if you want to auto redirect to your payment website or display a payment button.
    if (!empty($authnet_settings['bypass_payment_page']) && $authnet_settings['bypass_payment_page'] == 'Y') {
        $myAuthorize->submitPayment();
        //Enable auto redirect to payment site
    } else {
        if (empty($authnet_settings['button_url'])) {
            //$button_url = EVENT_ESPRESSO_GATEWAY_URL . "authnet/btn_cc_vmad.gif";
            if (file_exists(EVENT_ESPRESSO_GATEWAY_DIR . "/authnet/btn_cc_vmad.gif")) {
                $button_url = EVENT_ESPRESSO_GATEWAY_DIR . "/authnet/btn_cc_vmad.gif";
            } else {
                $button_url = EVENT_ESPRESSO_PLUGINFULLURL . "gateways/authnet/btn_cc_vmad.gif";
            }
        } elseif (file_exists($authnet_settings['button_url'])) {
            $button_url = $authnet_settings['button_url'];
        } else {
            //If no other buttons exist, then use the default location
            $button_url = EVENT_ESPRESSO_PLUGINFULLURL . "gateways/authnet/btn_cc_vmad.gif";
        }
        $myAuthorize->submitButton($button_url, 'authnet');
        //Display payment button
    }
    if ($use_sandbox) {
        echo '<p>Test credit card # 4007000000027</p>';
        echo '<h3 style="color:#ff0000;" title="Payments will not be processed">' . __('Debug Mode Is Turned On', 'event_espresso') . '</h3>';
        $myAuthorize->dump_fields();
        // for debugging, output a table of all the fields
    }
}
Exemple #3
0
 public function pay_new($id = '', $gate_id = '')
 {
     if (intval($id) == 0 or intval($gate_id) == 0) {
         show_404();
     }
     $user = $this->db->get_where('users', array('id' => $id))->row();
     if (!$user or $user->status != 0) {
         show_404();
     }
     $group = $this->db->get_where('groups', array('id' => $user->group))->row();
     if (!$group) {
         show_404();
     }
     $gate = $this->db->get_where('gateways', array('id' => $gate_id))->row();
     if (!$gate) {
         show_404();
     }
     // get payment gateway settings
     $gate_conf = unserialize($gate->settings);
     // load payment libs
     include_once APPPATH . 'libraries/payment/PaymentGateway.php';
     // which payment system to use?
     if ($gate->name == 'paypal') {
         // Include the paypal library
         include_once APPPATH . 'libraries/payment/Paypal.php';
         // Create an instance of the paypal library
         $myPaypal = new Paypal();
         // Specify your paypal email
         $myPaypal->addField('business', $gate_conf['email']);
         // Specify the currency
         $myPaypal->addField('currency_code', $gate_conf['currency']);
         // Specify the url where paypal will send the user on success/failure
         $myPaypal->addField('return', site_url('user/pay_complete'));
         $myPaypal->addField('cancel_return', site_url('user/pay_cancel'));
         // Specify the url where paypal will send the IPN
         $myPaypal->addField('notify_url', site_url('payment/ipn/paypal'));
         // Specify the product information
         $myPaypal->addField('item_name', $this->startup->site_config['sitename'] . ' ' . $this->lang->line('user_controller_14'));
         $myPaypal->addField('amount', $group->price);
         $myPaypal->addField('item_number', rand(1, 1000) . '-' . $user->id);
         // Specify any custom value
         $myPaypal->addField('custom', base64_encode(serialize(array('user_id' => $user->id, 'type' => 'reg'))));
         // Enable test mode if needed
         if (defined('XUDEBUG') and XUDEBUG == true) {
             $myPaypal->enableTestMode();
         }
         // Let's start the train!
         $data['form'] = $myPaypal->submitPayment($this->lang->line('user_controller_paypal_submitpayment'));
     } else {
         if ($gate->name == 'authorize') {
             // Include the paypal library
             include_once APPPATH . 'libraries/payment/Authorize.php';
             // Create an instance of the authorize.net library
             $myAuthorize = new Authorize();
             // Specify your authorize.net login and secret
             $myAuthorize->setUserInfo($gate_conf['login'], $gate_conf['secret']);
             // Specify the url where authorize.net will send the user on success/failure
             $myAuthorize->addField('x_Receipt_Link_URL', site_url('user/pay_complete'));
             // Specify the url where authorize.net will send the IPN
             $myAuthorize->addField('x_Relay_URL', site_url('payment/ipn/authorize'));
             // Specify the product information
             $myAuthorize->addField('x_Description', $this->startup->site_config['sitename'] . ' ' . $this->lang->line('user_controller_14'));
             $myAuthorize->addField('x_Amount', $group->price);
             $myAuthorize->addField('x_Invoice_num', rand(1, 1000) . '-' . $user->id);
             $myAuthorize->addField('x_Cust_ID', base64_encode(serialize(array('user_id' => $user->id, 'type' => 'reg'))));
             // Enable test mode if needed
             if (defined('XUDEBUG') and XUDEBUG == true) {
                 $myAuthorize->enableTestMode();
             }
             // Let's start the train!
             $data['form'] = $myAuthorize->submitPayment($this->lang->line('user_controller_paypal_submitpayment'));
         } else {
             if ($gate->name = '2co') {
                 // Include the paypal library
                 include_once APPPATH . 'libraries/payment/TwoCo.php';
                 // Create an instance of the authorize.net library
                 $my2CO = new TwoCo();
                 // Specify your 2CheckOut vendor id
                 $my2CO->addField('sid', $gate_conf['vendor_id']);
                 // Specify the order information
                 $my2CO->addField('cart_order_id', rand(1, 1000) . '-' . $user->id);
                 $my2CO->addField('total', $group->price);
                 // Specify the url where authorize.net will send the IPN
                 $my2CO->addField('x_Receipt_Link_URL', site_url('payment/ipn/two_checkout'));
                 $my2CO->addField('tco_currency', $gate_conf['currency']);
                 $my2CO->addField('custom', base64_encode(serialize(array('user_id' => $user->id, 'type' => 'reg'))));
                 // Enable test mode if needed
                 if (defined('XUDEBUG') and XUDEBUG == true) {
                     $my2CO->enableTestMode();
                 }
                 // Let's start the train!
                 $data['form'] = $my2CO->submitPayment($this->lang->line('user_controller_paypal_submitpayment'));
             }
         }
     }
     $this->load->view($this->startup->skin . '/header', array('headerTitle' => $this->lang->line('user_controller_15')));
     $this->load->view($this->startup->skin . '/user/register/pay_new', array('ammount' => $group, 'user' => $id, 'form' => $data['form']));
     $this->load->view($this->startup->skin . '/footer');
 }
function submit_to_authorize()
{
    $eStore_default_currency = get_option('cart_payment_currency');
    $eStore_return_url = get_option('cart_return_from_paypal_url');
    $eStore_sandbox_enabled = get_option('eStore_cart_enable_sandbox');
    $myAuthorize = new Authorize();
    $authorize_login_id = get_option('eStore_authorize_login');
    $authorize_tx_key = get_option('eStore_authorize_tx_key');
    $myAuthorize->setUserInfo($authorize_login_id, $authorize_tx_key);
    if (get_option('eStore_auto_product_delivery') != '') {
        $notify = WP_ESTORE_URL . '/eStore_auth_ipn.php';
        $myAuthorize->addField('x_Relay_URL', $notify);
    }
    global $wpdb;
    $products_table_name = WP_ESTORE_PRODUCTS_TABLE_NAME;
    $x_Description = "Cart Checkout: ";
    $count = 1;
    foreach ($_SESSION['eStore_cart'] as $item) {
        $id = $item['item_number'];
        $ret_product = $wpdb->get_row("SELECT * FROM {$products_table_name} WHERE id = '{$id}'", OBJECT);
        if ($count > 1) {
            $x_Description .= ", ";
        }
        $x_Description .= $item['item_number'];
        $rounded_price = round($item['price'], 2);
        $item_name = substr(htmlspecialchars($item['name']), 0, 30);
        $line_item_val = $item['item_number'] . "<|>" . $item_name . "<|><|>" . $item['quantity'] . "<|>" . $rounded_price . "<|>" . "N";
        $myAuthorize->addField('x_line_item-' . $count, $line_item_val);
        $count++;
    }
    //Specify the url where auth.net will return the customer after payment
    $total_items_in_cart = count($_SESSION['eStore_cart']);
    if ($total_items_in_cart == 1 && !empty($ret_product->return_url)) {
        //$myAuthorize->addField('x_receipt_link_URL', $ret_product->return_url);
        $eStore_return_url = $ret_product->return_url;
    }
    if (!empty($eStore_return_url)) {
        //Set the return URL
        $myAuthorize->addField('x_receipt_link_URL', $eStore_return_url);
    }
    //TODO - new auth.net redirection method
    if (WP_ESTORE_USE_AUTH_NET_ALT_REDIRECTION === '1') {
        $myAuthorize->addField('x_receipt_link_method', "GET");
        $myAuthorize->addField('x_receipt_link_text', "Click Here to Complete Transaction");
        $myAuthorize->addField('x_Relay_Response', "FALSE");
    }
    // Shipping
    $myAuthorize->addField('x_freight', $_SESSION['eStore_cart_postage_cost']);
    // Tax
    if (!empty($_SESSION['eStore_cart_total_tax'])) {
        $myAuthorize->addField('x_tax', round($_SESSION['eStore_cart_total_tax'], 2));
    } else {
        $myAuthorize->addField('x_tax', 0);
    }
    // Duty
    $myAuthorize->addField('x_duty', 0);
    // Total
    $total = round($_SESSION['eStore_cart_sub_total'] + $_SESSION['eStore_cart_postage_cost'] + $_SESSION['eStore_cart_total_tax'], 2);
    $myAuthorize->addField('x_Amount', $total);
    //If currency code is set then the "x_fp_hash" algorithm need to be updated to include this field.
    //$myAuthorize->addField('x_currency_code', $eStore_default_currency);
    // Description
    $myAuthorize->addField('x_Description', $x_Description);
    //$val = "item2<|>cricket bag<|>Wilson cricket carry bag, red<|>1<|>39.99<|>N";
    $myAuthorize->addField('x_Invoice_num', rand(1, 100));
    //Generate Customer ID
    $custId = uniqid();
    $myAuthorize->addField('x_Cust_ID', $custId);
    // Enable test mode if needed
    if ($eStore_sandbox_enabled) {
        $myAuthorize->enableTestMode();
    }
    // Save the order details
    eStore_save_order_details($custId);
    // Lets clear the cart
    reset_eStore_cart();
    // Let's start the train!
    $myAuthorize->submitPayment2(WP_ESTORE_CLICK_HERE);
}