classname.".cfg.php" );
}
/**
* Returns the "is_readable" status of the configuration file
* @param void
* @returns boolean True when the configuration file is writeable, false when not
*/
function configfile_readable() {
return is_readable( CLASSPATH."payment/".$this->classname.".cfg.php" );
}
/**
* Writes the configuration file for this payment method
* @param array An array of objects
* @returns boolean True when writing was successful
*/
function write_configuration( &$d ) {
$my_config_array = array("ECK_TEST_REQUEST" => $d['ECK_TEST_REQUEST'],
"ECK_LOGIN" => $d['ECK_LOGIN'],
"ECK_TYPE" => $d['ECK_TYPE'],
"ECK_ECHECK_TYPE" => $d['ECK_ECHECK_TYPE'],
"ECK_RECURRING" => $d['ECK_RECURRING']
);
$config = " $value ) {
$config .= "define ('$key', '$value');\n";
}
$config .= "?>";
if ($fp = fopen(CLASSPATH ."payment/".$this->classname.".cfg.php", "w")) {
fputs($fp, $config, strlen($config));
fclose ($fp);
return true;
}
else
return false;
}
/**************************************************************************
** name: process_payment()
** created by: jep
** description: process transaction authorize.net
** parameters: $order_number, the number of the order, we're processing here
** $order_total, the total $ of the order
** returns:
***************************************************************************/
function process_payment($order_number, $order_total, &$d) {
global $vendor_mail, $vendor_currency, $VM_LAN, $vmLogger;
$database = new ps_DB();
$ps_vendor_id = $_SESSION["ps_vendor_id"];
$auth = $_SESSION['auth'];
$ps_checkout = new ps_checkout;
/*** Get the Configuration File for authorize.net ***/
require_once(CLASSPATH ."payment/".$this->classname.".cfg.php");
// Get the Transaction Key securely from the database
$database->query( "SELECT DECODE(payment_passkey,'".ENCODE_KEY."') as passkey FROM #__{sc}_payment_method WHERE payment_class='".$this->classname."'" );
$transaction = $database->record[0];
if( empty($transaction->passkey)) {
$vmLogger->err($VM_LANG->_PHPSHOP_PAYMENT_ERROR);
return false;
}
// Get user billing information
$dbbt = new ps_DB;
$qt = "SELECT * FROM #__{sc}_user_info WHERE user_id='".$auth["user_id"]."' AND address_type='BT'";
$dbbt->query($qt);
$dbbt->next_record();
$user_info_id = $dbbt->f("user_info_id");
if( $user_info_id != $d["ship_to_info_id"]) {
// Get user billing information
$dbst =& new ps_DB;
$qt = "SELECT * FROM #__{sc}_user_info WHERE user_info_id='".$d["ship_to_info_id"]."' AND address_type='ST'";
$dbst->query($qt);
$dbst->next_record();
}
else {
$dbst = $dbbt;
}
$host = "secure.authorize.net";
$port = 443;
$path = "/gateway/transact.dll";
//Authnet vars to send
$formdata = array (
'x_version' => '3.1',
'x_login' => ECK_LOGIN,
'x_tran_key' => $transaction->passkey,
'x_test_request' => ECK_TEST_REQUEST,
'x_delim_data' => 'TRUE',
'x_delim_char' => '|',
'x_relay_response' => 'FALSE',
'x_first_name' => substr($dbbt->f("first_name"), 0, 50),
'x_last_name' => substr($dbbt->f("last_name"), 0, 50),
'x_company' => substr($dbbt->f("company"), 0, 50),
'x_address' => substr($dbbt->f("address_1"), 0, 60),
'x_city' => substr($dbbt->f("city"), 0, 40),
'x_state' => substr($dbbt->f("state"), 0, 40),
'x_zip' => substr($dbbt->f("zip"), 0, 20),
'x_country' => substr($dbbt->f("country"), 0, 60),
'x_phone' => substr($dbbt->f("phone_1"), 0, 25),
'x_fax' => substr($dbbt->f("fax"), 0, 25),
'x_ship_to_first_name' => substr($dbst->f("first_name"), 0, 50),
'x_ship_to_last_name' => substr($dbst->f("last_name"), 0, 50),
'x_ship_to_company' => substr($dbst->f("company"), 0, 50),
'x_ship_to_address' => substr($dbst->f("address_1"), 0, 60),
'x_ship_to_city' => substr($dbst->f("city"), 0, 40),
'x_ship_to_state' => substr($dbst->f("state"), 0, 40),
'x_ship_to_zip' => substr($dbst->f("zip"), 0, 20),
'x_ship_to_country' => substr($dbst->f("country"), 0, 60),
'x_cust_id' => $auth['user_id'],
'x_customer_ip' => $_SERVER["REMOTE_ADDR"],
'x_customer_tax_id' => $dbbt->f("tax_id"),
'x_email' => $dbbt->f("email"),
'x_email_customer' => 'True',
'x_merchant_email' => $vendor_mail,
'x_invoice_num' => substr($order_number, 0, 20),
'x_description' => '',
'x_amount' => $order_total,
'x_currency_code' => $vendor_currency,
'x_method' => 'ECHECK',
'x_type' => ECK_TYPE,
'x_echeck_type' => ECK_ECHECK_TYPE,
'x_recurring_billing' => ECK_RECURRING,
'x_bank_aba_code' => $dbbt->f("bank_iban"),
'x_bank_acct_num' => $dbbt->f("bank_account_nr"),
'x_bank_acct_type' => $dbbt->f("bank_account_type"),
'x_bank_name' => $dbbt->f("bank_name"),
'x_bank_acct_name' => $dbbt->f("bank_account_holder"),
// Level 2 data
'x_po_num' => substr($order_number, 0, 20),
'x_tax' => substr($d['order_tax'], 0, 15),
'x_tax_exempt' => "FALSE",
'x_freight' => $d['order_shipping'],
'x_duty' => 0
);
//build the post string
$poststring = '';
foreach($formdata AS $key => $val){
$poststring .= urlencode($key) . "=" . urlencode($val) . "&";
}
// strip off trailing ampersand
$poststring = substr($poststring, 0, -1);
if( function_exists( "curl_init" )) {
$CR = curl_init();
curl_setopt($CR, CURLOPT_URL, "https://".$host.$path);
curl_setopt($CR, CURLOPT_POST, 1);
curl_setopt($CR, CURLOPT_FAILONERROR, true);
curl_setopt($CR, CURLOPT_POSTFIELDS, $poststring);
curl_setopt($CR, CURLOPT_RETURNTRANSFER, 1);
// No PEER certificate validation...as we don't have
// a certificate file for it to authenticate the host www.ups.com against!
curl_setopt($CR, CURLOPT_SSL_VERIFYPEER, 0);
//curl_setopt($CR, CURLOPT_SSLCERT , "/usr/locale/xxxx/clientcertificate.pem");
$result = curl_exec( $CR );
$error = curl_error( $CR );
if( !empty( $error )) {
$vmLogger->err( curl_error( $CR ) );
$html = "