$eway->setTransactionData("CustomerInvoiceDescription", "Testing");
	$eway->setTransactionData("CustomerInvoiceRef", "INV120394");
	$eway->setTransactionData("CardHoldersName", "John Smith"); //mandatory field
	$eway->setTransactionData("CardNumber", "4444333322221111"); //mandatory field
	$eway->setTransactionData("CardExpiryMonth", "08"); //mandatory field
	$eway->setTransactionData("CardExpiryYear", "10"); //mandatory field
	$eway->setTransactionData("TrxnNumber", "4230");
	$eway->setTransactionData("Option1", "");
	$eway->setTransactionData("Option2", "");
	$eway->setTransactionData("Option3", "");
	
	//for REAL_TIME_CVN
	$eway->setTransactionData("CVN", "123");

	//for GEO_IP_ANTI_FRAUD
	$eway->setTransactionData("CustomerIPAddress", $eway->getVisitorIP()); //mandatory field when using Geo-IP Anti-Fraud
	$eway->setTransactionData("CustomerBillingCountry", "AU"); //mandatory field when using Geo-IP Anti-Fraud
	
	
	//special preferences for php Curl
	$eway->setCurlPreferences(CURLOPT_SSL_VERIFYPEER, 0);  //pass a long that is set to a zero value to stop curl from verifying the peer's certificate 
	//$eway->setCurlPreferences(CURLOPT_CAINFO, "/usr/share/ssl/certs/my.cert.crt"); //Pass a filename of a file holding one or more certificates to verify the peer with. This only makes sense when used in combination with the CURLOPT_SSL_VERIFYPEER option. 
	//$eway->setCurlPreferences(CURLOPT_CAPATH, "/usr/share/ssl/certs/my.cert.path");
	//$eway->setCurlPreferences(CURLOPT_PROXYTYPE, CURLPROXY_HTTP); //use CURL proxy, for example godaddy.com hosting requires it
	//$eway->setCurlPreferences(CURLOPT_PROXY, "http://proxy.shr.secureserver.net:3128"); //use CURL proxy, for example godaddy.com hosting requires it
	
	$ewayResponseFields = $eway->doPayment();

	
	if($ewayResponseFields["EWAYTRXNSTATUS"]=="False"){
		print "Transaction Error: " . $ewayResponseFields["EWAYTRXNERROR"] . "<br>\n";		
$eway->setTransactionData("CardHoldersName", "John Smith");
//mandatory field
$eway->setTransactionData("CardNumber", "4444333322221111");
//mandatory field
$eway->setTransactionData("CardExpiryMonth", "08");
//mandatory field
$eway->setTransactionData("CardExpiryYear", "10");
//mandatory field
$eway->setTransactionData("TrxnNumber", "4230");
$eway->setTransactionData("Option1", "");
$eway->setTransactionData("Option2", "");
$eway->setTransactionData("Option3", "");
//for REAL_TIME_CVN
$eway->setTransactionData("CVN", "123");
//for GEO_IP_ANTI_FRAUD
$eway->setTransactionData("CustomerIPAddress", $eway->getVisitorIP());
//mandatory field when using Geo-IP Anti-Fraud
$eway->setTransactionData("CustomerBillingCountry", "AU");
//mandatory field when using Geo-IP Anti-Fraud
//special preferences for php Curl
$eway->setCurlPreferences(CURLOPT_SSL_VERIFYPEER, 0);
//pass a long that is set to a zero value to stop curl from verifying the peer's certificate
//$eway->setCurlPreferences(CURLOPT_CAINFO, "/usr/share/ssl/certs/my.cert.crt"); //Pass a filename of a file holding one or more certificates to verify the peer with. This only makes sense when used in combination with the CURLOPT_SSL_VERIFYPEER option.
//$eway->setCurlPreferences(CURLOPT_CAPATH, "/usr/share/ssl/certs/my.cert.path");
//$eway->setCurlPreferences(CURLOPT_PROXYTYPE, CURLPROXY_HTTP); //use CURL proxy, for example godaddy.com hosting requires it
//$eway->setCurlPreferences(CURLOPT_PROXY, "http://proxy.shr.secureserver.net:3128"); //use CURL proxy, for example godaddy.com hosting requires it
$ewayResponseFields = $eway->doPayment();
if ($ewayResponseFields["EWAYTRXNSTATUS"] == "False") {
    print "Transaction Error: " . $ewayResponseFields["EWAYTRXNERROR"] . "<br>\n";
    foreach ($ewayResponseFields as $key => $value) {
        print "\n<br>\$ewayResponseFields[\"{$key}\"] = {$value}";
Exemple #3
0
function gateway_eway($seperator, $sessionid)
{
    global $wpdb, $wpsc_cart;
    $purchase_log_sql = "SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid`= '" . $sessionid . "' LIMIT 1";
    $purchase_log = $wpdb->get_results($purchase_log_sql, ARRAY_A);
    $purchase_log = $purchase_log[0];
    $cart_sql = "SELECT * FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`='" . $purchase_log['id'] . "'";
    $cart = $wpdb->get_results($cart_sql, ARRAY_A);
    $member_subtype = get_product_meta($cart[0]['prodid'], 'is_permenant', true);
    $member_shiptype = get_product_meta($cart[0]['prodid'], 'membership_length', true);
    $member_shiptype = $member_shiptype[0];
    $status = get_product_meta($cart[0]['prodid'], 'is_membership', true);
    $is_member = $status;
    $is_perm = $member_subtype;
    if ($_POST['collected_data'][get_option('eway_form_first_name')] != '') {
        $data['first_name'] = esc_attr($_POST['collected_data'][get_option('eway_form_first_name')]);
    }
    if ($_POST['collected_data'][get_option('eway_form_last_name')] != '') {
        $data['last_name'] = esc_attr($_POST['collected_data'][get_option('eway_form_last_name')]);
    }
    if ($_POST['collected_data'][get_option('eway_form_address')] != '') {
        $address_rows = explode("\n\r", $_POST['collected_data'][get_option('eway_form_address')]);
        $data['address1'] = esc_attr(str_replace(array("\n", "\r"), '', $address_rows[0]));
        unset($address_rows[0]);
        if ($address_rows != null) {
            $data['address2'] = implode(", ", $address_rows);
        } else {
            $data['address2'] = '';
        }
    }
    //exit('<pre>'.print_r($wpsc_cart, true).'</pre>');
    foreach ($wpsc_cart->cart_items as $item) {
        $itemsName .= $item->product_name . ', ';
        //exit('<pre>'.print_r($item,true).'</pre>');
    }
    if ($_POST['collected_data'][get_option('eway_form_city')] != '') {
        $data['city'] = esc_attr($_POST['collected_data'][get_option('eway_form_city')]);
    }
    if (empty($_POST['collected_data'][get_option('eway_form_state')]) && isset($_POST['collected_data'][get_option('eway_form_country')][1]) && !empty($_POST['collected_data'][get_option('eway_form_country')][1])) {
        $data['state'] = $_POST['collected_data'][get_option('eway_form_country')][1];
    } elseif (!empty($_POST['collected_data'][get_option('eway_form_state')])) {
        $data['state'] = $_POST['collected_data'][get_option('eway_form_state')];
    }
    if ($_POST['collected_data'][get_option('eway_form_country')] != '') {
        $data['country'] = $_POST['collected_data'][get_option('eway_form_country')][0];
    }
    if (is_numeric($_POST['collected_data'][get_option('eway_form_post_code')])) {
        $data['zip'] = esc_attr($_POST['collected_data'][get_option('eway_form_post_code')]);
    }
    if ($_POST['collected_data'][get_option('eway_form_email')]) {
        $data['email'] = $_POST['collected_data'][get_option('eway_form_email')];
    }
    if ($_POST['collected_data'][get_option('email_form_field')] != null && $data['email'] == null) {
        $data['email'] = esc_attr($_POST['collected_data'][get_option('email_form_field')]);
    }
    // Live or Test Server?
    if (get_option('eway_test')) {
        $user = '******';
        $gateway = false;
    } else {
        $user = get_option('ewayCustomerID_id');
        $gateway = true;
    }
    if ($is_member[0]) {
        require_once WPSC_GOLD_FILE_PATH . '/ewaylib/GatewayConnector.php';
        $objRebill = new RebillPayment();
        $objRebill->CustomerRef($purchase_log['id']);
        $objRebill->CustomerTitle('');
        $objRebill->CustomerFirstName($data['first_name']);
        $objRebill->CustomerLastName($data['last_name']);
        $objRebill->CustomerCompany('');
        $objRebill->CustomerJobDesc('');
        $objRebill->CustomerEmail($data['email']);
        $objRebill->CustomerAddress($data['address1']);
        $objRebill->CustomerSuburb('');
        $objRebill->CustomerState($data['state']);
        $objRebill->CustomerPostCode($data['zip']);
        $objRebill->CustomerCountry($data['country']);
        $objRebill->CustomerPhone1($data['phone']);
        $objRebill->CustomerPhone2('');
        $objRebill->CustomerFax('');
        $objRebill->CustomerURL('');
        $objRebill->CustomerComments('');
        $objRebill->RebillInvRef('');
        $objRebill->RebillInvDesc('');
        $objRebill->RebillCCname($data['first_name'] . " " . $data['last_name']);
        $objRebill->RebillCCNumber($_POST['card_number']);
        $objRebill->RebillInitAmt($purchase_log['totalprice']);
        $objRebill->RebillInitDate(date('d/m/Y'));
        $objRebill->RebillRecurAmt($purchase_log['totalprice']);
        $objRebill->RebillStartDate(date('d/m/Y'));
        $objRebill->RebillEndDate(date("d/m/Y", mktime(0, 0, 0, date('m'), date('d'), (int) date('Y') + 1)));
        $objRebill->RebillCCExpMonth($_POST['expiry']['month']);
        $objRebill->RebillCCExpYear($_POST['expiry']['year']);
        $objRebill->RebillInterval($member_shiptype['length']);
        switch ($member_shiptype['unit']) {
            case 'd':
                $member_ship_unit = '1';
                break;
            case 'w':
                $member_ship_unit = '2';
                break;
            case 'm':
                $member_ship_unit = '3';
                break;
            case 'y':
                $member_ship_unit = '4';
                break;
        }
        $objRebill->RebillIntervalType($member_ship_unit);
        $objRebill->eWAYCustomerID($user);
        $objConnector = new GatewayConnector($gateway);
        if ($objConnector->ProcessRequest($objRebill)) {
            $objResponse = $objConnector->Response();
            if ($objResponse != null) {
                $lblResult = $objResponse->Result();
                if ($lblResult == 'Success') {
                    wpsc_member_activate_subscriptions($purchase_log['id']);
                    $_SESSION['nzshpcrt_cart'] = '';
                    $_SESSION['nzshpcrt_cart'] = array();
                    header("Location:" . get_option('product_list_url'));
                }
                $lblErrorDescription = $objResponse->ErrorDetails();
                $lblErrorSeverity = $objResponse->ErrorSeverity();
                // This is woefully inadequate!!!
                exit('An Error has occured >' . $lblResult . " " . $lblErrorDescription . " " . $lblErrorSeverity);
            }
        } else {
            exit("Rebill Gateway failed: " . $objConnector->Response());
        }
    } else {
        require WPSC_GOLD_FILE_PATH . '/merchants/ewaylib/EwayPaymentLive.php';
        //echo WPSC_GOLD_FILE_PATH.'/ewaylib/EwayPaymentLive.php';
        if (get_option('eway_cvn')) {
            $method = 'REAL_TIME_CVN';
        } else {
            $method = 'REAL_TIME';
        }
        $eway = new EwayPaymentLive($user, $method, $gateway);
        $amount = number_format($purchase_log['totalprice'], 2, '.', '') * 100;
        $eway->setTransactionData("TotalAmount", $amount);
        //mandatory field
        $eway->setTransactionData("CustomerFirstName", $data['first_name']);
        $eway->setTransactionData("CustomerLastName", $data['last_name']);
        $eway->setTransactionData("CustomerEmail", $data['email']);
        $eway->setTransactionData("CustomerAddress", $data['address1'] . ' ' . $data['state']);
        $eway->setTransactionData("CustomerPostcode", $data['zip']);
        $eway->setTransactionData("CustomerInvoiceDescription", $itemsName);
        $eway->setTransactionData("CustomerInvoiceRef", $purchase_log['id']);
        $eway->setTransactionData("CardHoldersName", $data['first_name'] . ' ' . $data['last_name']);
        //mandatory field
        $eway->setTransactionData("CardNumber", $_POST['card_number']);
        //mandatory field
        $eway->setTransactionData("CardExpiryMonth", $_POST['expiry']['month']);
        //mandatory field
        $eway->setTransactionData("CardExpiryYear", $_POST['expiry']['year']);
        //mandatory field
        $eway->setTransactionData("TrxnNumber", $purchase_log['id']);
        $eway->setTransactionData("Option1", "");
        $eway->setTransactionData("Option2", "");
        $eway->setTransactionData("Option3", "");
        //for REAL_TIME_CVN
        $eway->setTransactionData("CVN", $_POST['cvn']);
        //for GEO_IP_ANTI_FRAUD
        $eway->setTransactionData("CustomerIPAddress", $eway->getVisitorIP());
        //mandatory field when using Geo-IP Anti-Fraud
        $eway->setTransactionData("CustomerBillingCountry", $data['country']);
        //mandatory field when using Geo-IP Anti-Fraud
        //special preferences for php Curl
        $eway->setCurlPreferences(CURLOPT_SSL_VERIFYPEER, 0);
        //pass a long that is set to a zero value to stop curl from verifying the peer's certificate
        //$eway->setCurlPreferences(CURLOPT_CAINFO, "/usr/share/ssl/certs/my.cert.crt"); //Pass a filename of a file holding one or more certificates to verify the peer with. This only makes sense when used in combination with the CURLOPT_SSL_VERIFYPEER option.
        //$eway->setCurlPreferences(CURLOPT_CAPATH, "/usr/share/ssl/certs/my.cert.path");
        //$eway->setCurlPreferences(CURLOPT_PROXYTYPE, CURLPROXY_HTTP); //use CURL proxy, for example godaddy.com hosting requires it
        //$eway->setCurlPreferences(CURLOPT_PROXY, "http://proxy.shr.secureserver.net:3128"); //use CURL proxy, for example godaddy.com hosting requires it
        $ewayResponseFields = $eway->doPayment();
        //exit(print_r($ewayResponseFields,1));
        //print_r($ewayResponseFields);
        if ($ewayResponseFields["EWAYTRXNSTATUS"] == "False") {
            $message .= "<h3>Please Check the Payment Results</h3>";
            $message .= "Your transaction was not successful." . "<br><br>";
            $message .= $ewayResponseFields['EWAYTRXNERROR'] . "<br><br>";
            $message .= "<a href=" . get_option('shopping_cart_url') . ">Click here to go back to checkout page.</a>";
            $_SESSION['eway_message'] = $message;
            header("Location:" . get_option('transact_url') . $seperator . "eway=0&result=" . $sessionid . "&message=1");
            //exit();
        } else {
            if ($ewayResponseFields["EWAYTRXNSTATUS"] == "True") {
                $wpdb->query("UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET `processed`='2' WHERE `sessionid`='" . $sessionid . "' LIMIT 1");
                transaction_results($sessionid, false);
                $message .= "Your transaction was successful." . "<br><br>";
                $message .= $ewayResponseFields['EWAYTRXNERROR'] . "<br><br>";
                $_SESSION['eway_message'] = $message;
                header("Location:" . get_option('transact_url') . $seperator . "eway=1&result=" . $sessionid . "&message=1");
                //exit();
            }
        }
    }
    //echo $_SESSION['eway_message'];
    exit;
}
 function _doPayment()
 {
     global $messageStack;
     if (MODULE_PAYMENT_EWAY_AU_SSL_VERIFIER > 0 && $request_type == 'NONSSL') {
         echo 'TRANSACTION ERROR: INSECURE (solutions: make it https:// or change "SSL Verifier" to FALSE from "eWay Payment" module)';
         exit;
     }
     //live payment or hosted payment
     if (MODULE_PAYMENT_EWAYPAYMENT_PROCESSING_METHOD == REAL_TIME || MODULE_PAYMENT_EWAYPAYMENT_PROCESSING_METHOD == REAL_TIME_CVN || MODULE_PAYMENT_EWAYPAYMENT_PROCESSING_METHOD == GEO_IP_ANTI_FRAUD) {
         require_once 'ext/eway/eway_payment_live.php';
         $eway = new EwayPaymentLive(MODULE_PAYMENT_EWAY_AU_CUSTOMER_ID, MODULE_PAYMENT_EWAYPAYMENT_PROCESSING_METHOD, MODULE_PAYMENT_EWAYPAYMENT_GATEWAY_MODE == 'Live gateway' ? true : false);
         //        $eway->setTransactionData("TotalAmount", 1);
         $eway->setTransactionData("TotalAmount", $_POST['my_totalamount']);
         //mandatory field
         $eway->setTransactionData("CustomerFirstName", $_POST['my_firstname']);
         $eway->setTransactionData("CustomerLastName", $_POST['my_lastname']);
         $eway->setTransactionData("CustomerEmail", $_POST['my_email']);
         $eway->setTransactionData("CustomerAddress", $_POST['my_address']);
         $eway->setTransactionData("CustomerPostcode", $_POST['my_postcode']);
         $eway->setTransactionData("CustomerInvoiceDescription", $_POST['my_invoice_description']);
         $eway->setTransactionData("CustomerInvoiceRef", $_POST['my_invoice_ref']);
         $eway->setTransactionData("CardHoldersName", $_POST['my_card_name']);
         //mandatory field
         $eway->setTransactionData("CardNumber", $_POST['my_card_number']);
         //mandatory field
         $eway->setTransactionData("CardExpiryMonth", $_POST['my_card_exp_month']);
         //mandatory field
         $eway->setTransactionData("CardExpiryYear", $_POST['my_card_exp_year']);
         //mandatory field
         $eway->setTransactionData("TrxnNumber", "");
         $eway->setTransactionData("Option1", $_POST['my_ewayOption1']);
         $eway->setTransactionData("Option2", "");
         $eway->setTransactionData("Option3", "");
         //for REAL_TIME_CVN
         $eway->setTransactionData("CVN", $_POST['my_eway_cvn']);
         if (MODULE_PAYMENT_EWAYPAYMENT_PROCESSING_METHOD == GEO_IP_ANTI_FRAUD) {
             //for GEO_IP_ANTI_FRAUD
             $eway->setTransactionData("CustomerIPAddress", $eway->getVisitorIP());
             //mandatory field when using Geo-IP Anti-Fraud
             $eway->setTransactionData("CustomerBillingCountry", $_POST['my_country_code']);
             //mandatory field when using Geo-IP Anti-Fraud
         }
         //$eway->setCurlPreferences(CURLOPT_CAINFO, "/usr/share/ssl/certs/my.cert.crt"); //Pass a filename of a file holding one or more certificates to verify the peer with. This only makes sense when used in combination with the CURLOPT_SSL_VERIFYPEER option.
         //$eway->setCurlPreferences(CURLOPT_CAPATH, "/usr/share/ssl/certs/my.cert.path");
         if (MODULE_PAYMENT_EWAY_AU_SSL_VERIFIER < 0) {
             $eway->setCurlPreferences(CURLOPT_SSL_VERIFYPEER, 0);
         }
         //pass a long that is set to a zero value to stop curl from verifying the peer's certificate
         if (MODULE_PAYMENT_EWAY_AU_CURL_PROXY != "") {
             $eway->setCurlPreferences(CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
             //use CURL proxy, for example godaddy.com hosting requires it
             $eway->setCurlPreferences(CURLOPT_PROXY, MODULE_PAYMENT_EWAY_AU_CURL_PROXY);
             //use CURL proxy, for example godaddy.com hosting requires it
         }
         $response = $eway->doPayment();
         if ($response["EWAYTRXNSTATUS"] == "False") {
             $messageStack->add_session('checkout', $response[EWAYTRXNERROR], 'error');
             osc_redirect(osc_href_link(FILENAME_CHECKOUT, 'checkout&view=paymentInformationForm', 'SSL', null, null, true));
         } else {
             if ($response["EWAYTRXNSTATUS"] == "True") {
                 $comment = 'eWay ' . MODULE_PAYMENT_EWAYPAYMENT_PROCESSING_METHOD . ' Success[' . $response[EWAYTRXNERROR] . ']';
                 $this->_order_id = osC_Order::insert();
                 osC_Order::process($this->_order_id, $this->order_status, $comment);
             }
         }
     } else {
         //hosted payment
         require_once 'ext/eway/eway_payment_hosted.php';
         $eway = new EwayPaymentHosted(MODULE_PAYMENT_EWAY_AU_CUSTOMER_ID, MODULE_PAYMENT_EWAYPAYMENT_PROCESSING_METHOD, MODULE_PAYMENT_EWAYPAYMENT_GATEWAY_MODE == 'Live gateway' ? true : false);
         $orders_id = 0;
         if (isset($_SESSION['prepOrderID'])) {
             $_prep = explode('-', $_SESSION['prepOrderID']);
             $orders_id = $_prep[1];
         }
         $eway->setTransactionData("TotalAmount", $_POST['my_totalamount']);
         //mandatory field
         //        $eway->setTransactionData("TotalAmount", 1);
         $eway->setTransactionData("CustomerFirstName", $_POST['my_firstname']);
         $eway->setTransactionData("CustomerLastName", $_POST['my_lastname']);
         $eway->setTransactionData("CustomerEmail", $_POST['my_email']);
         $eway->setTransactionData("CustomerAddress", $_POST['my_address']);
         $eway->setTransactionData("CustomerPostcode", $_POST['my_postcode']);
         $eway->setTransactionData("CustomerInvoiceDescription", $_POST['my_invoice_description']);
         $eway->setTransactionData("CustomerInvoiceRef", $_POST['my_invoice_ref']);
         $eway->setTransactionData("URL", osc_href_link(FILENAME_CHECKOUT, 'callback&module=' . $this->_code . '&return=yes&orders_id=' . $orders_id, 'SSL', null, null, true));
         //the script that will receive the results: http://www.mywebsite.com.au/testewayhosted.php?return=yes
         $eway->setTransactionData("SiteTitle", STORE_NAME);
         $eway->setTransactionData("TrxnNumber", "");
         $eway->setTransactionData("Option1", $_POST['my_ewayOption1']);
         $eway->setTransactionData("Option2", "");
         $eway->setTransactionData("Option3", "");
         $eway->doPayment();
         exit;
     }
 }