Web site Integration
Now that you are familiar the CyberCash API the next stage is to
integrate CyberCash into your web site. When you receive an authorization request there are
several tasks that need to be done.
integrate CyberCash into your web site. When you receive an authorization request there are
several tasks that need to be done.
- Verify the input variables
- Send an authorization request to CyberCash
- Log to a database the order request and the CyberCash authorization status
- If the authorization status is successful proceed to fulfill the goods or services requested
- Else display an error and exit
- Present the customer with an order receipt
Below is an example of an authorization wrapper function. This takes care of CyberClass interfacing,
database logging (done with MySQL) and error handling.
database logging (done with MySQL) and error handling.
<?php
/*
CyberClass authorization wrapper function
// SQL table definition used in insert order logs into
CREATE TABLE cc_order_log (
order_id CHAR(16),
amount CHAR(12),
order_desc tinytext,
trans_time datetime,
card_name CHAR(100),
card_address CHAR(100),
card_city CHAR(30),
card_state CHAR(30),
card_zip CHAR(15),
card_country CHAR(30),
part_card_num CHAR(6),
mstatus CHAR(20),
merr_code CHAR(10),
merr_msg tinytext,
merch_txn CHAR(12),
ref_code CHAR(14)
)
*/
include("class.cyberclass.php");
function
cyberauth($order){
/* Make the cyberclass instance */
$transaction = new cyberclass('/etc/merchant_conf');
/* Make the credit card authorization request */
$cybercash_result = $transaction->SendCC2_1Server('mauthonly',$order);
$part_card_num = substr($order['card-number'], 0, 2) .
substr($order['card-number'],
strlen($order['card-number']) - 4, 4);
/* Make copy of order */
$db = $order;
/* Run addslashes() on data */
reset($db);
while($key = key($db)){
$db[$key] = addslashes($db[$key]);
next($db);
}
$dbMErrCode = addslashes($cybercash_result[MErrCode]);
$dbMErrMsg = addslashes($cybercash_result[MErrMsg]);
/* Log the transaction results */
$insert = "INSERT INTO cc_order_log VALUES ('{$order['order-id']}',
'{$db['amount']}',
'{$db['order_desc']}',
NOW(),
'{$db['card-name']}',
'{$db['card-address']}',
'{$db['card-city']}',
'{$db['card-state']}',
'{$db['card-zip']}',
'{$db['card-country']}',
'$part_card_number',
'{$cybercash_result['MStatus']}',
'$dbMErrCode',
'$dbMErrMsg',
'{$cybercash_result['merchtxn']}',
'{$cybercash_result['refcode']}'
)";
if(
mysql("your_db", $insert) == false){
mail('[email protected]',
'Cyberauth Database Log Error','', $insert);
}
if(
$cybercash_result['MStatus'] == "success"){
/* Success */
$return_result['success'] = true;
}elseif(eregi("failure", $cybercash_result[MStatus])){
/* Failure */
$return_result['success'] = false;
$return_result['message'] =
"There was an error processing your credit card
transaction. {$cybercash_result['MErrCode']} -
{$cybercash_result['MErrMsg']}.";
}elseif(
$cybercash_result['MStatus'] == "success-duplicate"){
/* Repeat */
$return_result['success'] = false;
$return_result['message'] =
"There was an error processing your credit card
transaction. The transaction you created is a
duplication of a previous transaction.";
}else{
/* Unknown Error */
$return_result['success'] = false;
$return_result['message'] =
"There was an unknown error while processing the
credit card transaction.";
}
/* Return results */
$return_result['order-id'] = $order_id;
$return_result['part-card-number'] = $part_card_num;
$return_result['card-type'] = $cybercash_result['card-type'];
$return_result['merchtxn'] = $cybercash_result['merchtxn'];
$return_result['refcode'] = $cybercash_result['refcode'];
return
$return_result;
}
?>
To setup and use the cyberauth function create the cc_order_log table in your database by
running the given SQL create table command. The cyberauth script is an example and can be
adjusted to work with any database. Adjust other various items in the script such as the path
to the merchant_conf file, the database and email notification.
running the given SQL create table command. The cyberauth script is an example and can be
adjusted to work with any database. Adjust other various items in the script such as the path
to the merchant_conf file, the database and email notification.