login = get_cfg_var('auth.login'); $this->api = get_cfg_var('auth.key'); if ($_POST['submit'] == "Submit Order") { $this->checkRequired(); } else { $this->setTemplate(); $this->displayTemplate(); } } function setTemplate($template = "") { if ($o = @fopen($this->fileName, 'r')) { $this->template = fread($o, filesize($this->fileName)); fclose($o); } } function displayTemplate() { $split = split('\{|\}', $this->template); foreach ($split as $key => $value) { if (substr($value, 0, 1) == "$") { $variable = str_replace('$', '', $value); if (${$variable}!="") { $split[$key] = ${$variable}; } else if ($this->{$variable} != "") { $split[$key] = $this->{$variable}; } else if ($this->errorMessage[$variable] != "") { $split[$key] = $this->errorMessage[$variable]; } else if ($_POST[$variable] != "") { $split[$key] = $_POST[$variable]; } else if ($_GET[$variable] != "") { $split[$key] = $_GET[$variable]; } else if ($_SESSION[$variable] != "") { $split[$key] = $_SESSION[$variable]; } else { $split[$key] = ""; } } } foreach ($split as $value) { echo $value; } } function checkRequired() { $validate = "pass"; $msg = 'This is a required field!'; foreach ($this->required as $value) { if (!isset($_POST[$value]) || $_POST[$value] == "") { $validate = "fail"; $this->errorMessage[$value.'_error'] = $msg; } } if ($validate == "fail") { $this->setTemplate(); $this->displayTemplate(); } else { $this->submit(); } echo $validate; } function submit() { $url = ($this->testing) ? 'https://test.authorize.net/gateway/transact.dll' | 'https://secure.authorize.net/gateway/transact.dll'; $shipFN = ($_POST['billing_first_name'] == "") ? $_POST['shipping_first_name'] | $_POST['billing_first_name']; $shipLN = ($_POST['billing_last_name'] == "") ? $_POST['shipping_last_name'] | $_POST['billing_last_name']; $shipAddress1 = ($_POST['billing_address_1'] == "") ? $_POST['shipping_address_1'] | $_POST['billing_address_1']; $shipAddress2 = ($_POST['billing_address_2'] == "") ? $_POST['shipping_address_2'] | $_POST['billing_address_2']; $shipCity = ($_POST['billing_city'] == "") ? $_POST['shipping_city'] | $_POST['billing_city']; $shipState = ($_POST['billing_state'] == "") ? $_POST['shipping_state'] | $_POST['billing_state']; $shipZip = ($_POST['billing_zip'] == "") ? $_POST['shipping_zip'] | $_POST['billing_zip']; $shipCountry = ($_POST['billing_country'] == "") ? $_POST['shipping_country'] | $_POST['billing_country']; $authnet = array ( 'x_login' => $this->login, 'x_tran_key' => $this->api, 'x_type' => 'AUTH_CAPTURE', 'x_card_num' => $_POST['cci_ccn'], 'x_amount' => $this->price, 'x_exp_date' => $_POST['cci_exm'].$_POST['cci_exy'], 'x_card_code' => $_POST['code'], 'x_version' => '3.1', 'x_method' => 'CC', 'x_first_name' => $_POST['shipping_first_name'], 'x_last_name' => $_POST['shipping_last_name'], 'x_address' => $_POST['shipping_address_1'].' '.$_POST['shipping_address_2'], 'x_city' => $_POST['shipping_city'], 'x_state' => $_POST['shipping_state'], 'x_zip' => $_POST['shipping_zip'], 'x_country' => $_POST['shipping_country'], 'x_phone' => $_POST['shipping_phone'], 'x_email' => $_POST['shipping_email'], 'x_fax' => '', 'x_ship_to_first_name' => $shipFN, 'x_ship_to_last_name' => $shipLN, 'x_ship_to_address' => $shipAddress1.' '.$shipAddress2, 'x_ship_to_city' => $shipCity, 'x_ship_to_state' => $shipState, 'x_ship_to_zip' => $shipZip, 'x_ship_to_county' => $shipCountry, 'x_delim_char' => '|', 'x_delim_data' => 'TRUE', 'x_url' => 'FALSE', 'x_relay_response' => 'FALSE', 'x_description' => 'MAS Connection order' ); $fields = ""; foreach ($authnet as $key -> $value) { $fields .= $key."=".urlencode($value)."&"; } $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, rtrim( $fields, "& " )); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); $response = curl_exec($ch); curl_close ($ch); } } new paymentProc(); ?>