'
. t('DPS Direct payment system - PXAccess');
$title2 = '
';
}
$methods[] = array(
'id' => 'uc_dps_pxaccess',
'name' => t('DPS PXAccess'),
'title' => $title1 . $title2,
'review' => t('Credit Card via PaymentExpress'),
'desc' => t('Redirect users to submit payments through dps.'),
'callback' => 'uc_payment_method_uc_dps_pxaccess',
'weight' => 1,
'checkout' => FALSE,
'no_gateway' => TRUE,
);
return $methods;
}
/*
* Implementation of Payment_method
*/
function uc_payment_method_uc_dps_pxaccess($op, &$arg1) {
switch ($op) {
case 'order-view':
return "A Transaction" ;
break;
case 'settings':
$form['uc_dps_pxaccess_checkout_button'] = array(
'#type' => 'textfield',
'#title' => t('Submit button text on the Order Review'),
'#description' => t('Provide DPS Pxaccess.'),
'#default_value' => variable_get('uc_dps_pxaccess_checkout_button', t('Submit')),
/* You can modify the name of button (e.g. Pay by dps )*/
);
return $form;
}
}
/**
* Capture the details when viewer is redirected back from DPS transaction site.
*/
function uc_dps_pxaccess_callback_process() {
// @TODO Run a reverse DNS lookup on the IP address the callback is coming
// from and verify it is from Payment Express
$ip = ip_address();
$fullhost = gethostbyaddr($ip);
$host = preg_replace("/^[^.]+./", "*.", $fullhost);
if (isset($_REQUEST["result"])) {
module_load_include('inc', 'uc_dps_pxaccess', 'pxaccess');
$pxaccess = new PxAccess(variable_get('uc_dps_pxaccess_server', ''), variable_get('uc_dps_pxaccess_userid', ''), variable_get('uc_dps_pxaccess_key', ''), variable_get('uc_dps_pxaccess_mac_key', ''));
$enc_hex = $_REQUEST["result"];
// getResponse method in PxAccess object returns PxPayResponse object
// which encapsulates all the response data
$rsp = $pxaccess->getResponse($enc_hex);
// the following are the fields available in the PxPayResponse object
$result->success = $rsp->getSuccess(); // =1 when request succeeds
$result->retry = $rsp->getRetry(); // =1 when a retry might help
$result->statusrequired = $rsp->getStatusRequired(); // =1 when transaction "lost"
$result->amountsettlement = $rsp->getAmountSettlement();
$result->authcode = $rsp->getAuthCode(); // from bank
$result->cardname = $rsp->getCardName(); // e.g. "Visa"
$result->dpstxnref = $rsp->getDpsTxnRef();
// the following values are returned, but are from the original request
$result->txntype = $rsp->getTxnType();
$result->txndata1 = $rsp->getTxnData1();
$result->txndata2 = $rsp->getTxnData2();
$result->txndata3 = $rsp->getTxnData3();
$result->currencyinput = $rsp->getCurrencyInput();
$result->emailaddress = $rsp->getEmailAddress();
$result->txnid = $rsp->getMerchantReference();
// load the store transaction
if ( $result->txnid ) {
$txn = uc_order_load($result->txnid);
if ( !$txn ) {
drupal_not_found();
exit();
}
}
else {
drupal_access_denied();
exit();
}
$login = variable_get('uc_new_customer_login', FALSE ) ;
if ($result->statusrequired == "1") { // pending
uc_order_save($txn);
uc_cart_complete_sale($txn, $login);
uc_order_comment_save($txn->order_id, 0, t('A payment is pending.'), 'admin');
watchdog('uc_dps_pxaccess', 'An error occured during the processing!', WATCHDOG_ERROR);
$output = theme("uc_dps_pxaccess_returnpage_output_error", $result, $txn);
}
elseif ($result->success == "1") {
$comment = t('Order ID: @txn_id', array('@txn_id' => $txn->order_id));
// check if payment already received.
$payments = uc_payment_load_payments($txn->order_id);
if($payments){
foreach($payments as &$value){
if($value->data == $result->dpstxnref){
// payment recoreded already don't add this payment just show success page
$output = theme("uc_dps_pxaccess_returnpage_output_success", $result, $txn);
drupal_set_message( 'Your transaction was completed' ) ;
return $output;
}
}
}
uc_payment_enter($txn->order_id, 'uc_dps_pxaccess', $txn->order_total, $order->uid, $result->dpstxnref, $comment);
//uc_payment_enter($txn->order_id, 'uc_dps_pxaccess', $txn->order_total, $order->uid, NULL, $comment);
uc_order_save($txn);
uc_cart_complete_sale($txn, $login);
uc_order_comment_save($txn->order_id, 0, t('A payment has been accepted.'), 'admin');
watchdog('uc_dps_pxaccess', 'Transaction was completed!', WATCHDOG_NOTICE );
$output = theme("uc_dps_pxaccess_returnpage_output_success", $result, $txn);
drupal_set_message( 'Your transaction was completed' ) ;
return $output ;
}
else{
uc_order_save($txn);
//uc_cart_complete_sale($txn);
uc_order_comment_save($txn->order_id, 0, t('A payment has been failed.'), 'admin');
watchdog('uc_dps_pxaccess', 'Transaction was failed!', WATCHDOG_ERROR);
drupal_set_message(t('Your DPS payment has failed. Please contact us for assistance.'));
$output = theme("uc_dps_pxaccess_returnpage_output_declined", $result, $txn);
}
}
return $output;
}
/*******************************************************************************
* Hook Functions (Ubercart)
******************************************************************************/
/**
* Implementation of hook_payment_gateway().
*/
function uc_dps_pxaccess_payment_gateway() {
$gateways[] = array(
'id' => 'uc_dps_pxaccess',
'title' => t('DPS PxAccess'),
'description' => t('Process credit card payments using DPS on your site.'),
'settings' => 'uc_dps_pxaccess_settings_form',
);
return $gateways;
}
/******************************************************************
* Theme functions
******************************************************************/
function theme_uc_dps_pxaccess_form_alter_buttonset_prefix() {
$output = '| '; return $output; } function theme_uc_dps_pxaccess_form_alter_buttonset_suffix() { $output = ' | '. drupal_get_form('uc_dps_pxaccess_form', $order) .' |
'. l(t('Continue Shopping'), variable_get('uc_continue_shopping_url', '')) .'
'; return $output; } // format the output when the transaction is pending function theme_uc_dps_pxaccess_returnpage_output_error($result, $txn) { drupal_set_title('Payment Output Error during the processing'); $output = ''. $result->txnid .'
'; $output .= '