Skip to content

Instantly share code, notes, and snippets.

@ombagrao22
Created March 11, 2013 05:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ombagrao22/5132114 to your computer and use it in GitHub Desktop.
Save ombagrao22/5132114 to your computer and use it in GitHub Desktop.
<?php
/*
* This is custom gateway for "Citrus Payement Sloution"
* @created: 5 MARCH 2013
* @author: Omprakash
*/
$nzshpcrt_gateways[$num]['name'] = 'Citrus Pay Gateway';
$nzshpcrt_gateways[$num]['internalname'] = 'citrus_pay_gateway';
$nzshpcrt_gateways[$num]['function'] = 'gateway_citrus_pay_gateway';
$nzshpcrt_gateways[$num]['form'] = "form_citrus_pay_gateway";
$nzshpcrt_gateways[$num]['submit_function'] = "submit_citrus_pay_gateway";
/*
* Including Citrus gateway Liberies
*/
set_include_path(ABSPATH . '/lib'. PATH_SEPARATOR.get_include_path());
require_once( ABSPATH . '/lib/CitrusPay.php');
require_once 'Zend/Crypt/Hmac.php';
/*
* @description: function of gateway for computing hash
*/
function generateHmacKey($data, $apiKey=null){
$hmackey = Zend_Crypt_Hmac::compute($apiKey, "sha1", $data);
return $hmackey;
}
CitrusPay::setApiKey(get_option( "citrus_pay_gateway_secret_key" ),'production');
function gateway_citrus_pay_gateway($seperator, $sessionid){
//$wpdb is the database handle,
//$wpsc_cart is the shopping cart object
global $wpdb, $wpsc_cart;
//This grabs the purchase log id from the database
//that refers to the $sessionid
$response_url = 'http://localhost/ecommerce/response/';
$vanityUrl = get_option( "citrus_pay_gateway_vanity_url" );
$currency = "INR";
$merchantTxnId = $sessionid;
$orderAmount = $wpsc_cart->total_price;
$data = "$vanityUrl$orderAmount$merchantTxnId$currency";
$secSignature = generateHmacKey($data,CitrusPay::getApiKey());
$action = CitrusPay::getCPBase()."$vanityUrl";
$time = time()*1000;
$time = number_format($time,0,'.','');
$purchase_log = $wpdb->get_row(
"SELECT * FROM `".WPSC_TABLE_PURCHASE_LOGS.
"` WHERE `sessionid`= ".$sessionid." LIMIT 1"
,ARRAY_A) ;
//This grabs the users info using the $purchase_log
// from the previous SQL query
$usersql = "SELECT `".WPSC_TABLE_SUBMITED_FORM_DATA."`.value,
`".WPSC_TABLE_CHECKOUT_FORMS."`.`name`,
`".WPSC_TABLE_CHECKOUT_FORMS."`.`unique_name` FROM
`".WPSC_TABLE_CHECKOUT_FORMS."` LEFT JOIN
`".WPSC_TABLE_SUBMITED_FORM_DATA."` ON
`".WPSC_TABLE_CHECKOUT_FORMS."`.id =
`".WPSC_TABLE_SUBMITED_FORM_DATA."`.`form_id` WHERE
`".WPSC_TABLE_SUBMITED_FORM_DATA."`.`log_id`=".$purchase_log['id']."
";
$userinfo = $wpdb->get_results($usersql, ARRAY_A);
//Now we will store all the information into an associative array
//called $data to prepare it for sending via cURL
//please note that the key in the array may need to be changed
//to work with your gateway (refer to your gateways documentation).
$data = array();
//USer information will goe here...
$userinfo = $wpdb->get_results($usersql, ARRAY_A);
foreach((array)$userinfo as $key => $value){
if(($value['unique_name'] == 'billingfirstname') && $value['value'] != ''){
$data['BILLFIRSTNAME'] = $value['value'];
}
if(($value['unique_name'] == 'billinglastname') && $value['value'] != ''){
$data['BILLLASTNAME'] = $value['value'];
}
if(($value['unique_name'] == 'billingaddress') && $value['value'] != ''){
$data['BILLADDRESS'] = $value['value'];
}
if (($value['unique_name'] == 'billingcity') && $value['value'] != '') {
$data['BILLCITY'] = $value['value'];
}
if (($value['unique_name'] == 'billingstate') && $value['value'] != '') {
$data['BILLSTATE'] = $value['value'];
}
if (($value['unique_name'] == 'billingcountry') && $value['value'] != '') {
$data['BILLCOUNTRY'] = $value['value'];
}
if(($value['unique_name'] == 'billingemail') && $value['value'] != ''){
$data['BILLEMAIL'] = $value['value'];
}
if(($value['unique_name'] == 'billingphone') && $value['value'] != ''){
$data['BILLPHONE'] = $value['value'];
}
if(($value['unique_name'] == 'billingpostcode') && $value['value'] != ''){
$data['BILLPIN'] = $value['value'];
}
}
//Transaction form starts here ...
$transactionform = '<form action="'. $action .'" method="POST" name="TransactionForm" id="transactionForm">';
$transactionform .= '<p>
<label> Transaction ID:</label><input name="merchantTxnId"
type="text" value="'. $merchantTxnId .'" />
</p>
<p>
<label> addressState:</label><input name="addressState" type="text"
value="'. $data['BILLSTATE'] .'" />
</p>
<p>
<label> addressCity:</label><input name="addressCity" type="text"
value="'. $data['BILLCITY'] .'" />
</p>
<p>
<label> addressStreet1:</label><input name="addressStreet1"
type="text" value="'. $data['BILLADDRESS'] .'" />
</p>
<p>
<label> addressCountry:</label><input name="addressCountry"
type="text" value="'. $data['BILLCOUNTRY'] .'" />
</p>
<p>
<label> addressZip:</label><input name="addressZip" type="text"
value="'. $data['BILLPIN'] .'" />
</p>
<p>
<label> firstName:</label><input name="firstName" type="text"
value="'. $data['BILLFIRSTNAME'] .'" />
</p>
<p>
<label> lastName:</label><input name="lastName" type="text"
value="'. $data['BILLLASTNAME'] .'" />
</p>
<p>
<label> Mobile Number:</label><input name="phoneNumber" type="text"
value="'. $data['BILLPHONE'] .'" />
</p>
<p>
<label> email:</label><input name="email" type="text"
value="'. $data['BILLEMAIL'] .'" />
</p>
<p>
<label> user session:</label><input name="sessionid" type="hidden" value="'. $sessionid .'" />
</p>
<p>
<label> paymentMode:</label><input name="paymentMode" type="text"
value="NET_BANKING" />
</p>
<p>
<label> issuerCode:</label><input name="issuerCode" type="text"
value="" />
</p>
<p>
<label> cardHolderName:</label><input name="cardHolderName"
type="text" value="" />
</p>
<p>
<label> cardNumber:</label><input name="cardNumber" type="text"
value="" />
</p>
<p>
<label> expiryMonth:</label><input name="expiryMonth" type="text"
value="" />
</p>
<p>
<label> cardType:</label><input name="cardType" type="text"
value="" />
</p>
<p>
<label> cvvNumber:</label><input name="cvvNumber" type="text"
value="" />
</p>
<p>
<label> expiryYear:</label><input name="expiryYear" type="text"
value="" />
</p>
<p>
<label> returnUrl:</label><input name="returnUrl" type="text"
value="'. $response_url .'" />
</p>
<p>
<label> amount:</label><input name="orderAmount" type="text"
value="'. $orderAmount . '" />
</p>
<p>
Time: <input type="text" name="reqtime" value="' . $time . '" /> <input
type="hidden" name="secSignature"
value="' . $secSignature. ' " /> <input type="hidden"
name="currency" value="' . $currency . '" />
</p>';
$transactionform .= '</form>';
echo $transactionform;
echo '<script type="text/javascript">
document.getElementById("transactionForm").submit();
</script>';
//Transaction form Ends here ...
exit();
$transact_url = get_option('transact_url');
$response = 'Successs';
if($response == 'Success' || $response == 'SuccessWithWarning'){
//redirect to transaction page and store in DB as a order with
//accepted payment
$sql = "UPDATE `".WPSC_TABLE_PURCHASE_LOGS.
"` SET `processed`= '2' WHERE `sessionid`=".$sessionid;
$wpdb->query($sql);
$transact_url = get_option('transact_url');
unset($_SESSION['WpscGatewayErrorMessage']);
header("Location: ".$transact_url.$seperator."sessionid=".$sessionid);
exit();
}else{
//redirect back to checkout page with errors
$sql = "UPDATE `".WPSC_TABLE_PURCHASE_LOGS.
"` SET `processed`= '5' WHERE `sessionid`=".$sessionid;
$wpdb->query($sql);
$transact_url = get_option('checkout_url');
$_SESSION['WpscGatewayErrorMessage'] =
__('Sorry your transaction did not go through successfully, please try again.');
header("Location: ".$transact_url);
exit();
}
}
/*
*
*/
function form_citrus_pay_gateway(){
global $wpsc_gateways, $wpdb;
$output = '<tr><td>';
$output.='<input name="citrus_pay_access_key" type="text" value="' . get_option( "citrus_pay_access_key" ) . '" />';
$output.='Citrus Pay Access Key';
$output.='<input name="citrus_pay_gateway_secret_key" type="text" value="' . get_option( "citrus_pay_gateway_secret_key" ) . '" />';
$output.='Citrus Pay Secret Key';
$output.='<input name="citrus_pay_gateway_vanity_url" type="text" value="' . get_option( "citrus_pay_gateway_vanity_url" ) . '" />';
$output.='Citrus Pay Vanity url';
$output .= '</tr></td>';
return $output;
}
/*
* Custom Form appending At Checkout page..
*/
if ( in_array( 'citrus_pay_gateway', (array)get_option( 'custom_gateway_options' ) ) ) {
$output = '<tr><td>
<label for="paymentmode">Payment mode</label>
<select class="text" name="paymentMode" id="paymentmode">
<option value="">Select Payment Mode</option>
<option value="NET_BANKING">NetBanking</option>
<option value="CREDIT_CARD">Credit Card</option>
<option value="DEBIT_CARD">Debit Card</option>
</select>
</td></tr>';
$gateway_checkout_form_fields[$nzshpcrt_gateways[$num]['internalname']] = $output;
}
function submit_citrus_pay_gateway(){
if($_POST['citrus_pay_access_key'] != null) {
update_option('citrus_pay_access_key',
$_POST['citrus_pay_access_key']);
}
if($_POST['citrus_pay_gateway_secret_key'] != null) {
update_option('citrus_pay_gateway_secret_key',
$_POST['citrus_pay_gateway_secret_key']);
}
if($_POST['citrus_pay_gateway_vanity_url'] != null) {
update_option('citrus_pay_gateway_vanity_url',
$_POST['citrus_pay_gateway_vanity_url']);
}
return true;
}
@ombagrao22
Copy link
Author

Hi This is my main gateway file where my code working fine for storing and displaying configuration options for my new custom gateway. Here i am also able to post values using new custom gateway, but here i want response of the gateway on another page having template Responce.php. On this template for storing transaction of each user i want $session id but i am unable to get that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment