Det er denne her som skal laves om så jeg kan bruge den med Epay.dk
Er der nogen der kan hjælpe?
-------------------------------------------------------
<?php
/**
* @version 1.0.0
* @package RSEvents!Pro 1.0.0
* @copyright (C) 2007-2012
www.rsjoomla.com* @license GPL,
http://www.gnu.org/copyleft/gpl.html*/
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.plugin.plugin' );
class plgSystemRseprovmerchant extends JPlugin
{
//set the value of the payment option
protected $rsprooption = 'vmerchant';
public function __construct( &$subject, $config ) {
parent::__construct( $subject, $config );
}
/*
* Is RSEvents!Pro installed
*/
protected function canRun() {
$helper = JPATH_SITE.'/components/com_rseventspro/helpers/rseventspro.php';
if (file_exists($helper)) {
require_once $helper;
JFactory::getLanguage()->load('plg_system_rseprovmerchant',JPATH_ADMINISTRATOR);
return true;
}
return false;
}
/*
* Add the current payment option to the Payments List
*/
public function rsepro_addOptions() {
if ($this->canRun())
return JHTML::_('select.option', $this->rsprooption, JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_NAME'));
else return JHTML::_('select.option', '', '');
}
/*
* Add optional fields for the payment plugin. Example: Credit Card Number, etc.
* Please use the syntax <form method="post" action="index.php?option=com_rseventspro&task=process" name="paymentForm">
* The action provided in the form will actually run the rsepro_processForm() of your payment plugin.
*/
public function rsepro_showForm($vars) {
$app = JFactory::getApplication();
if($app->getName() != 'site') return;
//check to see if we can show something
if (!$this->canRun()) return;
if (isset($vars['method']) && $vars['method'] == $this->rsprooption)
{
JFactory::getLanguage()->load('com_rseventspro',JPATH_SITE);
jimport('joomla.mail.helper');
$db = JFactory::getDBO();
$doc = JFactory::getDocument();
//is the plugin enabled ?
$enable = JPluginHelper::isEnabled('system', 'rseprovmerchant');
if (!$enable) return;
$details = $vars['details'];
$tickets = $vars['tickets'];
//check to see if its a payment request
if (empty($details->verification) && empty($details->ide) && empty($details->email) && empty($tickets)) return;
//get the currency
$currency = $vars['currency'];
//get merchant code
$merchant = $this->params->get('merchant_id','');
$userid = $this->params->get('user_id','');
$pin = $this->params->get('user_pin','');
// Break if no gateway details
if (empty($merchant) || empty($userid) || empty($pin)) {
echo '<h1>'.JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_NO_DETAILS').'</h1>';
return;
}
// Items purchased
$items = '';
// Total price
$total = 0;
if (!empty($tickets)) {
foreach ($tickets as $ticket) {
if (empty($ticket->price))
$items .= $ticket->quantity. ' x '.$ticket->name.' ('.JText::_('COM_RSEVENTSPRO_GLOBAL_FREE'). ')<br />';
else
$items .= $ticket->quantity. ' x '.$ticket->name.' ('.rseventsproHelper::currency($ticket->price).')<br />';
if ($ticket->price > 0)
$total += ($ticket->quantity * $ticket->price);
}
}
if (!empty($details->discount))
$total = $total - $details->discount;
if (empty($total)) return;
if ($details->early_fee)
$total = $total - $details->early_fee;
if ($details->late_fee)
$total = $total + $details->late_fee;
//tax
if (!empty($details->tax))
$total = $total + $details->tax;
//get the months and years dropdowns
$months[] = JHTML::_('select.option', '01', JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_JANUARY'));
$months[] = JHTML::_('select.option', '02', JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_FEBRUARY'));
$months[] = JHTML::_('select.option', '03', JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_MARCH'));
$months[] = JHTML::_('select.option', '04', JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_APRIL'));
$months[] = JHTML::_('select.option', '05', JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_MAY'));
$months[] = JHTML::_('select.option', '06', JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_JUNE'));
$months[] = JHTML::_('select.option', '07', JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_JULY'));
$months[] = JHTML::_('select.option', '08', JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_AUGUST'));
$months[] = JHTML::_('select.option', '09', JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_SEPTEMBER'));
$months[] = JHTML::_('select.option', '10', JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_OCTOBER'));
$months[] = JHTML::_('select.option', '11', JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_NOVEMBER'));
$months[] = JHTML::_('select.option', '12', JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_DECEMBER'));
$exp_month = JHTML::_('select.genericlist', $months, 'cc_exp_m', 'class="rs_select" size="1"','value','text',date('m'));
$years = array();
for ($i=2010;$i<=2020;$i++)
$years[] = JHTML::_('select.option', $i, $i);
$exp_year = JHTML::_('select.genericlist', $years, 'cc_exp_y', 'class="rs_select" size="1"','value','text',date('Y'));
//get the event name
$db->setQuery("SELECT name FROM #__rseventspro_events WHERE id = ".(int) $details->ide." ");
$eventname = $db->loadResult();
$item = count($tickets) == 1 ? htmlentities($eventname.' - '.$tickets[0]->name,ENT_QUOTES,'UTF-8') : htmlentities($eventname.' - '.JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_MULTIPLE'),ENT_QUOTES,'UTF-8');
$doc->addScript(JURI::root().'plugins/system/rseprovmerchant/rseprovmerchant.js');
$html = '';
$html .= '<fieldset class="rs_fieldset">'."\n";
$html .= '<legend>'.JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_TICKETS_INFO').'</legend>'."\n";
$html .= '<table cellspacing="10" cellpadding="0" class="table table-bordered rs_table">'."\n";
$html .= '<tr>'."\n";
$html .= '<td><b>'.JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_TICKETS').'</b></td>'."\n";
$html .= '<td>'."\n";
$html .= $items;
$html .= '</td>'."\n";
$html .= '</tr>'."\n";
if (!empty($details->discount)) {
$html .= '<tr>'."\n";
$html .= '<td><b>'.JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_TICKETS_DISCOUNT').'</b></td>'."\n";
$html .= '<td>'.rseventsproHelper::currency($details->discount).'</td>'."\n";
$html .= '</tr>'."\n";
}
if ($details->early_fee)
{
$html .= '<tr>'."\n";
$html .= '<td><b>'.JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_EARLY_FEE').'</b></td>'."\n";
$html .= '<td>'."\n";
$html .= rseventsproHelper::currency($details->early_fee);
$html .= '</td>'."\n";
$html .= '</tr>'."\n";
}
if ($details->late_fee)
{
$html .= '<tr>'."\n";
$html .= '<td><b>'.JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_LATE_FEE').'</b></td>'."\n";
$html .= '<td>'."\n";
$html .= rseventsproHelper::currency($details->late_fee);
$html .= '</td>'."\n";
$html .= '</tr>'."\n";
}
if (!empty($details->tax))
{
$html .= '<tr>'."\n";
$html .= '<td><b>'.JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_TICKETS_TAX').'</b></td>'."\n";
$html .= '<td>'.rseventsproHelper::currency($details->tax).'</td>'."\n";
$html .= '</tr>'."\n";
}
$html .= '<tr>'."\n";
$html .= '<td><b>'.JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_TICKETS_TOTAL').'</b></td>'."\n";
$html .= '<td>'.rseventsproHelper::currency($total).'</td>'."\n";
$html .= '</tr>'."\n";
$html .= '</table>'."\n";
$html .= '</fieldset>'."\n";
$html .= '<form method="post" action="'.JRoute::_('index.php?option=com_rseventspro&task=process',false).'" id="vmerchant" autocomplete="off">'."\n";
$html .= '<table cellspacing="20" cellpading="0" class="rs_table">'."\n";
$html .= '<tr><td valign="top" width="200">'."\n";
$html .= '<label for="cc_number">'.JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_CARD_NUMBER').'</label>'."\n";
$html .= '</td><td>'."\n";
$html .= '<input type="text" class="rs_textbox" id="cc_number" name="cc_number" onkeyup="java script:this.value=this.value.replace(/[^0-9]/g, \'\');" maxlength="16" size="25" value=""/>'."\n";
$html .= '<br/><br/><img src="'.JURI::root().'components/com_rseventspro/assets/images/cc_logo.gif" alt="CC" />'."\n";
$html .= '</td></tr>'."\n";
$html .= '<tr><td>'."\n";
$html .= '<label for="cc_exp_date">'.JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_CARD_EXP_DATE').'</label>'."\n";
$html .= '</td><td>'."\n";
$html .= $exp_month.' / '.$exp_year."\n";
$html .= '</td></tr>'."\n";
$html .= '<tr><td>'."\n";
$html .= '<label for="cc_ccv">'.JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_CARD_CCV').'</label>'."\n";
$html .= '</td><td>'."\n";
$html .= '<input type="text" class="rs_textbox" name="cc_ccv" id="cc_ccv" size="5" onkeyup="java script:this.value=this.value.replace(/[^0-9]/g, \'\');" maxlength="4" value="" />';
$html .= ' <span onmouseout="rs_tooltip.hide();" onmouseover="rs_tooltip.show(\'rs_tooltip\');" id="rs_whats_csc">'.JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_CARD_CCV_WHATS_THIS').'</span>';
$html .= '</td></tr>'."\n";
$html .= '<tr><td>'."\n";
$html .= '<label for="cc_fname">'.JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_CARD_FNAME').'</label>'."\n";
$html .= '</td><td>'."\n";
$html .= '<input type="text" class="rs_textbox" id="cc_fname" name="cc_fname" size="25" value=""/>'."\n";
$html .= '</td></tr>'."\n";
$html .= '<tr><td>'."\n";
$html .= '<label for="cc_lname">'.JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_CARD_LNAME').'</label>'."\n";
$html .= '</td><td>'."\n";
$html .= '<input type="text" class="rs_textbox" id="cc_lname" name="cc_lname" size="25" value=""/>'."\n";
$html .= '</td></tr>'."\n";
$html .= '<tr><td colspan="2"><button type="submit" onclick="return vmerchant_validate(\''.JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_VALIDATE_CC_NUMBER',true).'\',\''.JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_VALIDATE_CC_CCV',true).'\');" class="rs_button">'.JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_PAY').'</button></td></tr>'."\n";
$html .= '</table>'."\n";
$html .= '<input type="hidden" name="email" value="'.$details->email.'" />'."\n";
$html .= '<input type="hidden" name="amount" value="'.rseventsproHelper::convertprice($total).'" />'."\n";
$html .= '<input type="hidden" name="hash" value="'.$details->verification.'" />'."\n";
$html .= '<input type="hidden" name="description" value="'.$item.'" />'."\n";
$html .= '<input type="hidden" name="ide" value="'.$details->ide.'" />'."\n";
$html .= '</form>'."\n";
$html .= '<div id="rs_tooltip" style="display: none;">'."\n";
$html .= '<div>'.JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_CARD_CCV_DESC').'</div>'."\n";
$html .= '<div align="center"><img src="'.JURI::root().'components/com_rseventspro/assets/images/cc_csc.gif" alt="CSC" /></div>';
$html .= '</div>'."\n";
echo $html;
}
}
/*
* Process the form
*/
public function rsepro_processForm($vars) {
//check to see if we can show something
if (!$this->canRun()) return;
$app = JFactory::getApplication();
$db = JFactory::getDBO();
$log = array();
$params = array();
$data = $vars['data'];
$hash = $data->getString('hash');
$db->setQuery("SELECT gateway FROM #__rseventspro_users WHERE verification = ".$db->q($hash)." ");
$gateway = $db->loadResult();
if ($gateway != $this->rsprooption) return;
//get merchant code
$merchant = $this->params->get('merchant_id','');
$userid = $this->params->get('user_id','');
$pin = $this->params->get('user_pin','');
// Break if no gateway details
if (empty($merchant) || empty($userid) || empty($pin)) {
echo '<h1>'.JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_NO_DETAILS').'</h1>';
return;
}
$post_url = "
https://www.myvirtualmerchant.com/VirtualMerchant/process.do"; $post_values = array(
"ssl_merchant_id" => $merchant,
"ssl_user_id" => $userid,
"ssl_pin" => $pin,
"ssl_test_mode" => $this->params->get('mode',0) ? "false" : "true",
"ssl_show_form" => "false",
"ssl_transaction_type" => "CCSALE",
"ssl_result_format" => "ASCII", //html,ASCII
"ssl_cvv2cvc2_indicator" => '1',
"ssl_card_number" => $data->getString('cc_number'),
"ssl_exp_date" => $data->getString('cc_exp_m').substr($data->getString('cc_exp_y'),2,4),
"ssl_cvv2cvc2" => $data->getString('cc_ccv'),
"ssl_amount" => $data->getString('amount'),
"ssl_description" => substr($data->getString('description'),0,255),
"ssl_invoice_number" => $hash,
"ssl_first_name" => $data->getString('cc_fname'),
"ssl_last_name" => $data->getString('cc_lname')
);
$log[] = JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_LOG1');
$string = '';
foreach( $post_values as $key => $value )
$string .= "$key=" . urlencode( $value ) . "&";
$string = rtrim($string, "& ");
unset($post_values);
if (!function_exists('curl_init')) {
$log[] = JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_LOG2');
} else {
$log[] = JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_LOG3');
$request = curl_init($post_url);
curl_setopt($request, CURLOPT_HEADER, 0);
curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($request, CURLOPT_POSTFIELDS, $string);
curl_setopt($request, CURLOPT_SSL_VERIFYPEER, FALSE);
$return = curl_exec($request);
curl_close ($request); // close curl object
$response = $this->_parseResponse($return);
// Get the subscriber id
$db->setQuery("SELECT id FROM #__rseventspro_users WHERE verification = ".$db->q($hash)." ");
$subscriber = $db->loadResult();
if ($response !== false)
{
if (isset($response['errorCode']) && $response['errorCode'] > 0)
{
if (isset($response['errorMessage']) && !empty($response['errorMessage']))
$message = $response['errorMessage'];
else if (isset($response['errorName']) && !empty($response['errorName']))
$message = $response['errorName'];
else $message = JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_ERR');
$msg = $message;
$log[] = JText::sprintf('RSEPRO_PLG_PLUGIN_VMERCHANT_LOG4',$message);
} else
{
if (isset($response['ssl_result']) && $response['ssl_result'] == 0)
{
if(!empty($subscriber))
{
if (!empty($response))
foreach($response as $key=>$value)
$params[] = $db->escape($key.'='.$value);
$params = is_array($params) ? implode("\n",$params) : '';
$db->setQuery("UPDATE #__rseventspro_users SET `state` = 1, `params` = ".$db->q($params)." WHERE id = ".(int) $subscriber." LIMIT 1");
$db->query();
//send the activation email
require_once JPATH_SITE.'/components/com_rseventspro/helpers/emails.php';
rseventsproHelper::confirm($subscriber);
$log[] = JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_LOG5');
$log[] = JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_LOG6');
$msg = JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_PAYMENT_OK');
}
} else
{
$message = isset($response['ssl_result_message']) ? $response['ssl_result_message'] : JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_ERR');
$log[] = JText::sprintf('RSEPRO_PLG_PLUGIN_VMERCHANT_LOG4',$message);
$msg = $message;
}
}
}
else
{
$log[] = JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_LOG7');
$msg = JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_ERR');
}
}
rseventsproHelper::savelog($log,$subscriber);
$db->setQuery("SELECT name FROM #__rseventspro_events WHERE id = ".(int) $data->getString('ide')." ");
$eventname = $db->loadResult();
$redirect = rseventsproHelper::route('index.php?option=com_rseventspro&layout=show&id='.rseventsproHelper::sef($data->getString('ide'),$eventname),false);
$app->redirect($redirect,$msg);
}
protected function _parseResponse($response) {
$return = array();
if (!empty($response))
{
$response = str_replace("\r",'',$response);
$response = explode("\n",$response);
if (!empty($response))
{
foreach ($response as $line)
{
if (empty($line)) continue;
$line = explode('=',$line);
if (isset($line[0]))
$return[$line[0]] = $line[1];
}
return $return;
}
return false;
}
return false;
}
public function rsepro_tax($vars) {
if (!$this->canRun()) return;
if (isset($vars['method']) && $vars['method'] == $this->rsprooption) {
$total = isset($vars['total']) ? $vars['total'] : 0;
$tax_value = $this->params->get('tax_value',0);
$tax_type = $this->params->get('tax_type',0);
return rseventsproHelper::setTax($total,$tax_type,$tax_value);
}
}
public function rsepro_info($vars) {
if (!$this->canRun()) return;
if (isset($vars['method']) && $vars['method'] == $this->rsprooption) {
$app = JFactory::getApplication();
$params = array();
$data = $vars['data'];
if (!empty($data)) {
if (!is_array($data)) {
$data = explode("\n",$data);
if (!empty($data)) {
foreach ($data as $line) {
$linearray = explode('=',$line);
if (!empty($linearray))
$params[trim($linearray[0])] = trim($linearray[1]);
}
}
} else {
$params = $data;
}
echo $app->isAdmin() ? '<fieldset>' : '<fieldset class="rs_fieldset">';
echo '<legend>'.JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_PAYMENT_DETAILS').'</legend>';
echo '<table width="100%" border="0" class="adminform rs_table table table-striped">';
echo '<tr>';
echo '<td width="25%" align="right">'.JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_TRANSACTION_ID').' :</td>';
echo '<td>'.@$params['ssl_txn_id'].'</td>';
echo '</tr>';
echo '<tr>';
echo '<td width="25%" align="right">'.JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_CODE').' :</td>';
echo '<td>'.@$params['ssl_approval_code'].'</td>';
echo '</tr>';
echo '</table>';
echo '</fieldset>';
}
}
}
public function rsepro_name($vars) {
if (!$this->canRun()) return;
if (isset($vars['gateway']) && $vars['gateway'] == $this->rsprooption) {
return JText::_('RSEPRO_PLG_PLUGIN_VMERCHANT_NAME');
}
}
}