📄 linkpoint_api.php
字号:
$cc_type = $cc_validation->cc_type;
$cc_number_clean = $cc_validation->cc_number;
$cc_expiry_month = $_POST['linkpoint_api_cc_expires_month'];
$cc_expiry_year = $_POST['linkpoint_api_cc_expires_year'];
$error_returned = $payment_error_return . $error_info2;
$cc_number = (strlen($cc_number_clean) > 8) ? substr($cc_number_clean, 0, 4) . str_repeat('X', (strlen($cc_number_clean) - 8)) . substr($cc_number_clean, -4) : substr($cc_number_clean, 0, 3) . '**short**';
while (strstr($error_returned, '%3A')) $error_returned = str_replace('%3A', ' ', $error_returned);
while (strstr($error_returned, '%2C')) $error_returned = str_replace('%2C', ' ', $error_returned);
while (strstr($error_returned, '+')) $error_returned = str_replace('+', ' ', $error_returned);
$error_returned = str_replace('&', ' &', $error_returned);
$cust_info = $error_returned;
$message = addslashes($message);
$cust_info = addslashes($cust_info);
$all_response_info = addslashes($all_response_info);
// Store Transaction history in Database
$sql_data_array= array(array('fieldName'=>'lp_trans_num', 'value'=>'', 'type'=>'string'),
array('fieldName'=>'order_id', 'value'=>0, 'type'=>'integer'),
array('fieldName'=>'approval_code', 'value'=>'N/A', 'type'=>'string'),
array('fieldName'=>'transaction_response_time', 'value'=>'N/A', 'type'=>'string'),
array('fieldName'=>'r_error', 'value'=>'**CC Info Failed Validation during pre-processing**', 'type'=>'string'),
array('fieldName'=>'customer_id', 'value'=>$_SESSION['customer_id'] , 'type'=>'integer'),
array('fieldName'=>'avs_response', 'value'=>'', 'type'=>'string'),
array('fieldName'=>'transaction_result', 'value'=>'*CUSTOMER ERROR*', 'type'=>'string'),
array('fieldName'=>'message', 'value'=>$message . ' -- ' . $all_response_info, 'type'=>'string'),
array('fieldName'=>'transaction_time', 'value'=>time(), 'type'=>'string'),
array('fieldName'=>'transaction_reference_number', 'value'=>'', 'type'=>'string'),
array('fieldName'=>'fraud_score', 'value'=>0, 'type'=>'integer'),
array('fieldName'=>'cc_number', 'value'=>$cc_number, 'type'=>'string'),
array('fieldName'=>'cust_info', 'value'=>$cust_info, 'type'=>'string'),
array('fieldName'=>'chargetotal', 'value'=>0, 'type'=>'string'),
array('fieldName'=>'cc_expire', 'value'=>$cc_month . '/' . $cc_year, 'type'=>'string'),
array('fieldName'=>'ordertype', 'value'=>'N/A', 'type'=>'string'),
array('fieldName'=>'date_added', 'value'=>'now()', 'type'=>'noquotestring'));
$db->perform(TABLE_LINKPOINT_API, $sql_data_array);
}
zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, $payment_error_return, 'SSL', true, false));
}
// if no error, continue with validated data:
$this->cc_card_type = $cc_validation->cc_type;
$this->cc_card_number = $cc_validation->cc_number;
$this->cc_expiry_month = $cc_validation->cc_expiry_month;
$this->cc_expiry_year = $cc_validation->cc_expiry_year;
}
// Display Credit Card Information on the Checkout Confirmation Page
function confirmation() {
$confirmation = array('title' => $this->title . ': ' . $this->cc_card_type,
'fields' => array(array('title' => MODULE_PAYMENT_LINKPOINT_API_TEXT_CREDIT_CARD_OWNER,
'field' => $_POST['linkpoint_api_cc_owner']),
array('title' => MODULE_PAYMENT_LINKPOINT_API_TEXT_CREDIT_CARD_NUMBER,
'field' => str_repeat('X', (strlen($this->cc_card_number) - 4)) . substr($this->cc_card_number, -4)),
array('title' => MODULE_PAYMENT_LINKPOINT_API_TEXT_CREDIT_CARD_EXPIRES,
'field' => strftime('%B, %Y', mktime(0,0,0,$_POST['linkpoint_api_cc_expires_month'], 1, '20' . $_POST['linkpoint_api_cc_expires_year'])))));
return $confirmation;
}
/**
* Prepare the hidden fields comprising the parameters for the Submit button on the checkout confirmation page
*/
function process_button() {
// These are hidden fields on the checkout confirmation page
$process_button_string = zen_draw_hidden_field('cc_owner', $_POST['linkpoint_api_cc_owner']) .
zen_draw_hidden_field('cc_expires', $this->cc_expiry_month . substr($this->cc_expiry_year, -2)) .
zen_draw_hidden_field('cc_expires_month', $this->cc_expiry_month) .
zen_draw_hidden_field('cc_expires_year', substr($this->cc_expiry_year, -2)) .
zen_draw_hidden_field('cc_type', $this->cc_card_type) .
zen_draw_hidden_field('cc_number', $this->cc_card_number) .
zen_draw_hidden_field('cc_cvv', $_POST['linkpoint_api_cc_cvv']);
$process_button_string .= zen_draw_hidden_field(zen_session_name(), zen_session_id());
return $process_button_string;
}
/**
* Prepare and submit the authorization to the gateway
*/
function before_process() {
global $order, $db, $messageStack, $lp_avs, $lp_trans_num;
$myorder = array();
//if ($this->code_debug) $order->info['cc_number'] = $_POST['cc_number'];
// Calculate the next expected order id
$last_order_id = $db->Execute("select * from " . TABLE_ORDERS . " order by orders_id desc limit 1");
$new_order_id = $last_order_id->fields['orders_id'];
$new_order_id = ($new_order_id + 1);
// add randomized suffix to order id to produce uniqueness ... since it's unwise to submit the same order-number twice to the gateway
$new_order_id = (string)$new_order_id . '-' . zen_create_random_value(6);
// Create a unique order id
//$oid = zen_create_random_value(16, 'digits'); // Create a UID for the order
// Build Info to send to Gateway
$myorder["result"] = "LIVE";
switch (MODULE_PAYMENT_LINKPOINT_API_TRANSACTION_MODE_RESPONSE) {
case "TESTING: Successful": $myorder["result"] = "GOOD"; break;
case "TESTING: Decline" : $myorder["result"] = "DECLINE"; break;
case "TESTING: Duplicate" : $myorder["result"] = "DUPLICATE"; break;
}
// "oid" - Order ID number must be unique. If not set, gateway will assign one.
$myorder["oid"] = $new_order_id; //""; // time(); ????
$myorder["ip"] = zen_get_ip_address();
$myorder["ponumber"] = "";
$myorder["subtotal"] = $order->info['subtotal'];
$myorder["tax"] = $order->info['tax'];
$myorder["shipping"] = $order->info['shipping_cost'];
$myorder["chargetotal"] = $order->info['total'];
// CARD INFO
$myorder["cardnumber"] = $_POST['cc_number'];
$myorder["cardexpmonth"] = $_POST['cc_expires_month'];
$myorder["cardexpyear"] = $_POST['cc_expires_year'];
$myorder["cvmindicator"] = "provided";
$myorder["cvmvalue"] = $_POST['cc_cvv'];
// BILLING INFO
$myorder["userid"] = $_SESSION['customer_id'];
$myorder["customerid"] = $_SESSION['customer_id'];
$myorder["name"] = htmlentities($_POST['cc_owner'], ENT_QUOTES, 'UTF-8'); //$order->billing['firstname'] . ' ' . $order->billing['lastname']);
$myorder["company"] = htmlentities($order->billing['company'], ENT_QUOTES, 'UTF-8');
$myorder["address1"] = htmlentities($order->billing['street_address'], ENT_QUOTES, 'UTF-8');
$myorder["address2"] = htmlentities($order->billing['suburb'], ENT_QUOTES, 'UTF-8');
$myorder["city"] = $order->billing['city'];
$myorder["state"] = $order->billing['state'];
$myorder["country"] = $order->billing['country']['iso_code_2'];
$myorder["phone"] = $order->customer['telephone'];
//$myorder["fax"] = $order->customer['fax'];
$myorder["email"] = $order->customer['email_address'];
$myorder["addrnum"] = $order->billing['street_address']; // Required for AVS. If not provided, transactions will downgrade.
$myorder["zip"] = $order->billing['postcode']; // Required for AVS. If not provided, transactions will downgrade.
// SHIPPING INFO
$myorder["sname"] = htmlentities($order->delivery['firstname'] . ' ' . $order->delivery['lastname'], ENT_QUOTES, 'UTF-8');
$myorder["saddress1"] = htmlentities($order->delivery['street_address'], ENT_QUOTES, 'UTF-8');
$myorder["saddress2"] = htmlentities($order->delivery['suburb'], ENT_QUOTES, 'UTF-8');
$myorder["scity"] = $order->delivery['city'];
$myorder["sstate"] = $order->delivery['state'];
$myorder["szip"] = $order->delivery['postcode'];
$myorder["scountry"] = $order->delivery['country']['iso_code_2'];
// MISC
$myorder["comments"] = "Website Order";
// $myorder["referred"] = "";
// itemized contents
for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
$myorder["items"][$i]['id'] = $order->products[$i]['id'];
$myorder["items"][$i]['description'] = substr(htmlentities($order->products[$i]['name'], ENT_QUOTES, 'UTF-8'), 0, 100);
$myorder["items"][$i]['quantity'] = $order->products[$i]['qty'];
$myorder["items"][$i]['price'] = number_format($order->products[$i]['price'], 2, '.', '');
if (isset($order->products[$i]['attributes'])) {
for ($j=0, $m=sizeof($order->products[$i]['attributes']); $j<$m; $j++) {
$myorder["items"][$i]['options' . $j]['name'] = $order->products[$i]['attributes'][$j]['option'];
$myorder["items"][$i]['options' . $j]['value'] = $order->products[$i]['attributes'][$j]['value'];
}
}
}
$myorder["ordertype"] = (MODULE_PAYMENT_LINKPOINT_API_AUTHORIZATION_MODE == 'Authorize Only' ? 'PREAUTH': 'SALE');
$this->payment_status = $myorder["ordertype"];
// send request to gateway
$result = $this->_sendRequest($myorder);
// alert to customer if communication failure
if (trim($result) == '<r_approved>FAILURE</r_approved><r_error>Could not connect.</r_error>' || !is_array($result)) {
$messageStack->add_session('checkout_payment', MODULE_PAYMENT_LINKPOINT_API_TEXT_FAILURE_MESSAGE, 'error');
zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL', true, false));
}
// PARSE Results
$all_response_info = '';
foreach($result as $key=>$value) {
$all_response_info .= ' ' .$key . '='.$value;
}
if ($this->code_debug) $messageStack->add_session('header', $all_response_info, 'caution');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -