[SOLVED] Payment plugin for EB not working

  • eliteideas
  • Topic Author
  • Offline
  • New Member
  • New Member
More
13 years 1 month ago - 13 years 1 month ago #8446 by eliteideas
[SOLVED] Payment plugin for EB not working was created by eliteideas
I am quite new to PHP development and am currently trying to develop a Netcash payment plugin for EB. I am definitely doing something wrong, though.

When the booking is confirmed, the system seems to pass the information along to Netcash (removing the type="hidden" displays the correct gateway login information as determined in the plugin parameters on the "Waiting for Netcash" page) but the gateway responds with "Merchant not authorised."

Looking at the URL displayed, there are critical parameters that go missing in the transfer from our site to Netcash.

This is the URL displayed in the browser:
Code:
https://gateway.netcash.co.za/merchant/declined.asp?p1=9876&p2=30&p3=%7EMerchant+not+authorised+to+use+this+service.&p4=&p5=&p6=50.00&p7=&p8=&p9=&p10=&p11=&p12=&pam=&m_1=&m_2=&m_3=&m_4=&m_5=&m_6=&m_7=&m_8=&m_9=rv@elite-ideas.net&m_10=&CardHolderIpAddr=&MaskedCardNumber=&TransactionType=Authorisation
I've included the code for plugin below - could anyone help me figure out what I'm doing wrong?

The mandatory parameters are the following:
  • m1 (Alphanumeric)
  • m2 (AN)
  • m3 (AN)
  • p1 (AN)
  • p2 (AN)
  • p3 (AN)
  • p4 (Numeric)
  • Budget (1/0)
Sample form from Netcash technical guide:
Code:
<form method="POST" action="https://gateway.netcash.co.za/vvonline/ccnetcash.asp "> <input type="hidden" name="m_1" value="testuser"> <input type="hidden" name="m_2" value="testpass"> <input type="hidden" name="m_3" value="654321"> <input type="hidden" name="p1" value="0291"> <input type="hidden" name="p2" value="Uniquekkap"> <input type="hidden" name="p3" value="Example Goods"> <input type="hidden" name="p4" value="39.99"> <input type="hidden" name="p10" value=""> <input type="hidden" name="Budget" value="Y"> <input type="hidden" name="m_4" value="Extra 1"> <input type="hidden" name="m_5" value=" Extra 2"> <input type="hidden" name="m_6" value=" Extra 3"> <input type="hidden" name="m_9" value="jack@test.com"> <input type="hidden" name="m_10" value="page=returnpage.asp&CommId=123"> <input type="submit" value="Pay by Credit Card"> </form>
My current plugin code:
Code:
class os_netcash extends os_payment { /** * netcash mode * * @var boolean live mode : true, test mode : false */ var $_mode = 0 ; /** * netcash url * * @var string */ var $_url = null ; /** * Array of params will be posted to server * * @var string */ var $_params = array(); /** * Array containing data posted from netcash to our server * * @var array */ var $_data = array(); /** * Constructor functions, init some parameter * * @param object $config */ function os_netcash($params) { parent::setName('os_netcash'); parent::os_payment(); parent::setCreditCard(false); parent::setCardType(false); parent::setCardCvv(false); parent::setCardHolderName(false); $this->ipn_log = true ; $this->ipn_log_file = JPATH_COMPONENT.DS.'ipn_logs.txt'; // Not sure what this does - form seems to work if commented out // $this->setParam('m1', $params->get('nc_id')); // $this->setParam('m2', $params->get('nc_pwd')); // $this->setParam('m3', $params->get('nc_pin')); // $this->setParam('p1', $params->get('nc_term_id')); $this->nc_budget = N; // $this->setParam('currency', 'ZAR'); if (!$params->get('netcash_mode')) { $this->setParam('testMode', '100'); $this->_url = 'https://gateway.netcash.co.za/vvonline/ccnetcash.asp'; } else { $this->_url = 'https://gateway.netcash.co.za/vvonline/ccnetcash.asp'; } } /** * Set param value * * @param string $name * @param string $val */ function setParam($name, $val) { $this->_params[$name] = $val; } /** * Setup payment parameter * * @param array $params */ function setParams($params) { foreach ($params as $key => $value) { $this->_params[$key] = $value ; } } /** * Process payment * * @param object $row The registration record * @param array $data */ function processPayment($row, $data) { $db = & JFactory::getDBO() ; $itemName = JText::_('EB_EVENT_REGISTRATION'); $itemName = str_replace('[EVENT_TITLE]', $data['event_title'], $itemName); // Temporary change to hardcode Netcash params // $this->setParam('m1', $params->get('nc_id')); // $this->setParam('m2', $params->get('nc_pwd')); // $this->setParam('m3', $params->get('nc_pin')); // $this->setParam('p1', $params->get('nc_term_id')); $this->setParam('m1', netcashuser); $this->setParam('m2', somepassword); $this->setParam('m3', 123456); $this->setParam('p1', 9876); $this->setParam('p2', $row->id); $this->setParam('p3', $itemName); $this->setParam('p4', number_format($row->amount, 2)); $this->setParam('Budget', N); $this->setParam('m_9', $row->email); $this->submitPost(); } /** * Submit post to netcash server * */ function submitPost() { ?> <div class="contentheading"><?php echo JText::_('EB_WAIT_netcash'); ?></div> <form method="post" action="<?php echo $this->_url; ?>" name="os_form" id="os_form"> <?php foreach ($this->_params as $key=>$val) { echo '<input type="hidden" name="'.$key.'" value="'.$val.'" />'; echo "\n"; } ?> <script type="text/javascript"> function redirect() { document.os_form.submit(); } setTimeout('redirect()',3000); </script> </form> <?php } /** * Validate the post data from netcash to our server * * @return string */ function _validate() { foreach ($_POST as $key=>$value) { $this->_data[$key] = $value ; } $cartId = JRequest::getVar('p3', '') ; $amount = JRequest::getVar('p4', '') ; $transId = JRequest::getVar('p2') ; $transStatus = JRequest::getVar('TransactionAccepted', '') ; $this->log_ipn_results(true); if ($transStatus == 'true') { $this->_data['p3'] = $cartId ; $this->_data['p4'] = $amount ; $this->_data['p2'] = $transId ; return true ; } else { return false ; } } /** * Log IPN result * * @param string $success */ function log_ipn_results($success) { if (!$this->ipn_log) return; $text = '['.date('m/d/Y g:i A').'] - '; if ($success) $text .= "SUCCESS!\n"; else $text .= 'FAIL: '.$this->last_error."\n"; $text .= "IPN POST Vars from Netcash:\n"; foreach ($this->_data as $key=>$value) { $text .= "$key=$value, "; } $text .= "\nIPN Response from Netcash Server:\n ".$this->ipn_response; $fp=fopen($this->ipn_log_file,'a'); fwrite($fp, $text . "\n\n"); fclose($fp); // close file } /** * Process payment * */ function verifyPayment() { $ret = $this->_validate(); if ($ret) { $config = EventBookingHelper::getConfig() ; $id = $this->_data['p3']; $transactionId = $this->_data['p2']; $amount = $this->_data['p4']; if ($amount < 0) return false ; $row = JTable::getInstance('EventBooking', 'Registrant'); $row->load($id); $row->transaction_id = $transactionId ; $row->payment_date = date('Y-m-d H:i:s'); $row->published = true; $row->store(); EventBookingHelper::sendEmails($row, $config); JPluginHelper::importPlugin( 'eventbooking' ); $dispatcher =& JDispatcher::getInstance(); $dispatcher->trigger( 'onAfterPaymentSuccess', array($row)); return true ; } else { return false; } } }
Last edit: 13 years 1 month ago by eliteideas. Reason: Issue resolved

Please Log in or Create an account to join the conversation.

More
13 years 1 month ago #8453 by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic Re: Payment plugin for Events Booking not working
Hi

Since this is a custom payment plugin you developed yourself, I am not sure what parameter you need to pass to the payment gateway . Looks at your code, I see the below line of code :
Code:
$this->setParam('m1', netcashuser); $this->setParam('m2', somepassword); $this->setParam('m3', 123456); $this->setParam('p1', 9876);

Maybe you will need to set it to :
Code:
$this->setParam('m1', "netcashuser"); $this->setParam('m2', "somepassword"); $this->setParam('m3', 123456); $this->setParam('p1', 9876);

Please note that netcashuser is now surrounded by "" character because it is a string . Can you check?

Please Log in or Create an account to join the conversation.

  • eliteideas
  • Topic Author
  • Offline
  • New Member
  • New Member
More
13 years 1 month ago #8462 by eliteideas
Replied by eliteideas on topic Re: Payment plugin for Events Booking not working
Thanks, it seems to have helped!

Still getting other errors from the gateway but will take it up with their support desk and keep you posted here.

Thanks again!

Please Log in or Create an account to join the conversation.

  • eliteideas
  • Topic Author
  • Offline
  • New Member
  • New Member
More
13 years 1 month ago #8474 by eliteideas
Replied by eliteideas on topic Re: Payment plugin for Events Booking not working
Gateway errors sorted - it was due to fat fingers on my side and an incomplete registration process on theirs.

Please Log in or Create an account to join the conversation.

Moderators: Tuan Pham Ngoc