i am administration of parsjoomla! team that translated joomla 1.5 to persian.
we are going to release an E-commerse Edition of joomla for free!
we translate virtumart 1.1 (http://virtumart.net) but we have very big problem.i am beginner on php .
in our country we have special e-payment ,it is sb24.
it is a simple code of sb 24 payment :
Code: Select all
<form action="https://acquirer.sb24.com/CardServices/controller" method="post">
<input id="Amount" name="Amount" value="1">
<input type="hidden" id="MID" name="MID" value="00025004-02">
<input type="hidden" id="ResNum" name="ResNum" value="603">
<input id="RedirectURL" name="RedirectURL" value="http://www.yahoo.com/">
<input name="B1" value="Send" type="submit">
</form>"Amount" (Toatal price) ( we post to sb24)
"MID" (Marchent Id) (we pos
"ResNum" (reserve number)
"RedirectURL" (the address that user go there after a successful transaction)
we want to set it with virtumart.i found in administrator\components\com_virtuemart\classes\payment (joomla!) for pay pal two files :
ps_paypal.php and ps_paypal.cfg.php
i create two files with :
ps_sb24.php ? ps_sb24.cfg.php
and copy paypal files into it .
this is ps_paypal.php code :
Code: Select all
<?php
if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
/**
*
* @version $Id: ps_paypal.php 1095 2007-12-19 20:19:16Z soeren_nb $
* @package VirtueMart
* @subpackage payment
* @copyright Copyright (C) 2004-2007 soeren - All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* VirtueMart is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See /administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details.
*
* http://virtuemart.net
*/
/**
* This class implements the configuration panel for paypal
* If you want to change something "internal", you must modify the 'payment extra info'
* in the payment method form of the PayPal payment method
*/
class ps_paypal {
var $classname = "ps_paypal";
var $payment_code = "PAYPAL";
/**
* Show all configuration parameters for this payment method
* @returns boolean False when the Payment method has no configration
*/
function show_configuration() {
global $VM_LANG;
$db = new ps_DB();
/** Read current Configuration ***/
include_once(CLASSPATH ."payment/".$this->classname.".cfg.php");
?>
<table class="adminform">
<tr class="row0">
<td><strong><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_ENABLE_AUTORIZENET_TESTMODE') ?></strong></td>
<td>
<select name="PAYPAL_DEBUG" class="inputbox" >
<option <?php if (@PAYPAL_DEBUG == '1') echo "selected=\"selected\""; ?> value="1"><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_YES') ?></option>
<option <?php if (@PAYPAL_DEBUG != '1') echo "selected=\"selected\""; ?> value="0"><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_NO') ?></option>
</select>
</td>
<td>
<?php
printf( $VM_LANG->_('VM_ADMIN_CFG_PAYPAL_NOTIFYSCRIPT_TIP'), '<pre>'. COMPONENTURL."notify.php</pre>" );
?>
</td>
</tr>
<tr class="row1">
<td><strong><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_PAYPAL_EMAIL') ?></strong></td>
<td>
<input type="text" name="PAYPAL_EMAIL" class="inputbox" value="<?php echo PAYPAL_EMAIL ?>" />
</td>
<td><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_PAYPAL_EMAIL_EXPLAIN') ?>
</td>
</tr>
<tr class="row0">
<td><strong><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_PAYPAL_STATUS_SUCCESS') ?></strong></td>
<td>
<select name="PAYPAL_VERIFIED_STATUS" class="inputbox" >
<?php
$q = "SELECT order_status_name,order_status_code FROM #__{vm}_order_status ORDER BY list_order";
$db->query($q);
$order_status_code = Array();
$order_status_name = Array();
while ($db->next_record()) {
$order_status_code[] = $db->f("order_status_code");
$order_status_name[] = $db->f("order_status_name");
}
for ($i = 0; $i < sizeof($order_status_code); $i++) {
echo "<option value=\"" . $order_status_code[$i];
if (PAYPAL_VERIFIED_STATUS == $order_status_code[$i])
echo "\" selected=\"selected\">";
else
echo "\">";
echo $order_status_name[$i] . "</option>\n";
}?>
</select>
</td>
<td><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_PAYPAL_STATUS_SUCCESS_EXPLAIN') ?>
</td>
</tr>
<tr class="row1">
<td><strong><?php echo $VM_LANG->_('VM_ADMIN_CFG_PAYPAL_STATUS_PENDING') ?></strong></td>
<td>
<select name="PAYPAL_PENDING_STATUS" class="inputbox" >
<?php
for ($i = 0; $i < sizeof($order_status_code); $i++) {
echo "<option value=\"" . $order_status_code[$i];
if (PAYPAL_PENDING_STATUS == $order_status_code[$i])
echo "\" selected=\"selected\">";
else
echo "\">";
echo $order_status_name[$i] . "</option>\n";
} ?>
</select>
</td>
<td><?php echo $VM_LANG->_('VM_ADMIN_CFG_PAYPAL_STATUS_PENDING_EXPLAIN') ?></td>
</tr>
<tr class="row0">
<td><strong><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_PAYPAL_ONLYVERIFIED') ?></strong></td>
<td>
<select name="PAYPAL_VERIFIED_ONLY" class="inputbox" >
<option <?php if (@PAYPAL_VERIFIED_ONLY != '1') echo "selected=\"selected\""; ?> value="0"><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_NO') ?></option>
<option <?php if (@PAYPAL_VERIFIED_ONLY == '1') echo "selected=\"selected\""; ?> value="1"><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_YES') ?></option>
</select>
</td>
<td><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_PAYPAL_ONLYVERIFIED_EXPLAIN') ?></td>
</tr>
<tr class="row1">
<td><strong><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_PAYPAL_STATUS_FAILED') ?></strong></td>
<td>
<select name="PAYPAL_INVALID_STATUS" class="inputbox" >
<?php
for ($i = 0; $i < sizeof($order_status_code); $i++) {
echo "<option value=\"" . $order_status_code[$i];
if (PAYPAL_INVALID_STATUS == $order_status_code[$i])
echo "\" selected=\"selected\">";
else
echo "\">";
echo $order_status_name[$i] . "</option>\n";
} ?>
</select>
</td>
<td><?php echo $VM_LANG->_('PHPSHOP_ADMIN_CFG_PAYPAL_STATUS_FAILED_EXPLAIN') ?>
</td>
</tr>
</table>
<?php
}
function has_configuration() {
// return false if there's no configuration
return true;
}
/**
* Returns the "is_writeable" status of the configuration file
* @param void
* @returns boolean True when the configuration file is writeable, false when not
*/
function configfile_writeable() {
return is_writeable( CLASSPATH."payment/".$this->classname.".cfg.php" );
}
/**
* Returns the "is_readable" status of the configuration file
* @param void
* @returns boolean True when the configuration file is writeable, false when not
*/
function configfile_readable() {
return is_readable( CLASSPATH."payment/".$this->classname.".cfg.php" );
}
/**
* Writes the configuration file for this payment method
* @param array An array of objects
* @returns boolean True when writing was successful
*/
function write_configuration( &$d ) {
$my_config_array = array(
"PAYPAL_DEBUG" => $d['PAYPAL_DEBUG'],
"PAYPAL_EMAIL" => $d['PAYPAL_EMAIL'],
"PAYPAL_VERIFIED_ONLY" => $d['PAYPAL_VERIFIED_ONLY'],
"PAYPAL_VERIFIED_STATUS" => $d['PAYPAL_VERIFIED_STATUS'],
"PAYPAL_PENDING_STATUS" => $d['PAYPAL_PENDING_STATUS'],
"PAYPAL_INVALID_STATUS" => $d['PAYPAL_INVALID_STATUS']
);
$config = "<?php\n";
$config .= "if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' ); \n\n";
foreach( $my_config_array as $key => $value ) {
$config .= "define ('$key', '$value');\n";
}
$config .= "?>";
if ($fp = fopen(CLASSPATH ."payment/".$this->classname.".cfg.php", "w")) {
fputs($fp, $config, strlen($config));
fclose ($fp);
return true;
}
else
return false;
}
/**************************************************************************
** name: process_payment()
** returns:
***************************************************************************/
function process_payment($order_number, $order_total, &$d) {
return true;
}
}Code: Select all
class ps_paypal {
var $classname = "ps_paypal";
var $payment_code = "PAYPAL";Code: Select all
class ps_sb24 {
var $classname = "ps_sb24";
var $payment_code = "SB24";
}one of the my frinds wrote php class for sb24 :
Code: Select all
<?php
/*******************************************************************************
* *
* @version sbpayment.php version 0.1 *
* @copyright Copyright (c) 2008. *
* @license http://opensource.org/licenses/gpl-license.php GNU Public License. *
* @author said shamspour saidshp@yahoo.com. *
* *
*******************************************************************************/
/*
CREATE TABLE SBPayment (id INT(10) NOT NULL AUTO_INCREMENT,
res_num CHAR(20) NOT NULL,
ref_num CHAR(20) NOT NULL,
total_amont INT NOT NULL,
payment INT NOT NULL DEFAULT 0,
date_start INT(12) NOT NULL,
primary key(id),
unique(res_num),
index(ref_num));
*/
class SBPayment
{
public $action = 'https://acquirer.sb24.com/CardServices/controller';
public $webMethodURL = 'https://Acquirer.sb24.com/ref-payment/ws/ReferencePayment?WSDL';
public $redirectURL = 'http//www.yourdomain.com/sbpayment.php';
public $totalAmont;
public $refNum;
public $resNum;
protected $payment;
protected $merchantID;
protected $password;
protected $msg = array();
protected $errorState = array(
'Canceled By User' => '?????? ?????? ?????? ???? ???',
'Invalid Amount' => '???? ??? ?????? ?? ???? ?????? ???? ????? ???',
'Invalid Transaction' => '??????? ????? ?????? ????? ??? ?? ???? ?? ?????? ???? ???? ??? ???',
'Invalid Card Number' => '????? ???? ?????? ???',
'No Such Issuer' => '???? ???? ????? ????? ???? ?????',
'Expired Card Pick Up' => '?? ????? ?????? ???? ????? ???',
'Incorrect PIN' => '??? ???? ?????? ??? pin',
'No Sufficient Funds' => '?????? ?? ?????? ???? ?? ???? ??? ????',
'Issuer Down Slm' => '????? ???? ??? ???? ????? ???? ????',
'TME Error' => '??? ?? ???? ?????',
'Exceeds Withdrawal Amount Limit' => '???? ??? ?? ??? ?????? ???',
'Transaction Cannot Be Completed' => '????? ??? ????? ???? ?????',
'Allowable PIN Tries Exceeded Pick Up' => '??? ???? 3 ????? ?????? ???? ??? ???? ??? ??? ???? ?????? ??',
'Response Received Too Late' => '?????? ?? ???? ????? ???? ??? ?????',
'Suspected Fraud Pick Up' => '?????? ???? ??? cvv2 ??? ExpDate ???????'
);
protected $errorVerify = array(
'-1' => '???? ????? ????',
'-2' => '????? ?? ????? ??????',
'-3' => '????? ?? ???? ?????????? ??? ???? ??????',
'-4' => '???? ???? ?? ?? ??????? ?????? ???',
'-5' => '???? ???? ????????',
'-6' => '??? ???? ????? ???? ?????',
'-7' => '???? ???????? ??? ???',
'-8' => '??? ????? ?? ????? ?? ?? ???? ???',
'-9' => '???? ????????? ??? ???? ?? ???? ??????',
'-10' => '???? ???????? ???? ????????? ??? ???? ???',
'-11' => '??? ????? ?? ???? ?? ?? ???? ???',
'-12' => '???? ?????? ???? ???',
'-13' => '???? ?????? ???? ????? ???? ??? ?? ???? ????? ?????? ???? ???????? ???',
'-14' => '???? ??????? ????? ???? ???',
'-15' => '???? ?????? ?? ???? ?????? ???? ???',
'-16' => '???? ????? ?????',
'-17' => '????? ??? ??????? ?? ?? ???? ????? ??? ?? ???? ????? ????? ???',
'-18' => '??????? ??????? ??? ip address'
);
public $style = array('TableBorderColor' => '',
'TableBGColor' => '',
'PageBGColor' => '',
'PageBorderColor' => '',
'TitleFont' => '',
'TitleColor' => '',
'TitleSize' => '',
'TextFont' => '',
'TextColor' => '',
'TextSize' => '',
'TypeTextColor' => '',
'TypeTextColor' => '',
'TypeTextSize' => '',
'LogoURI' => ''
);
function __construct($mID = '',$pass = '')
{
$this->merchantID = $mID;
$this->password = $pass;
}
protected function createResNum()
{
do{
$m = md5(microtime());
$resNum = substr($m,0,20);
$search = mysql_query("SELECT res_num FROM sbpayment WHERE res_num = '$resNum'");
if( mysql_num_rows($search) < 1 ) {
break;
}
}while( true );
$this->resNum = $resNum;
}
protected function searchResNum( $resNum )
{
$search = mysql_query( "select * FROM SBPayment WHERE res_num='$resNum'");
if ( mysql_num_rows( $search ) < 1 ) {
return false;
}
return mysql_fetch_assoc( $search );
}
protected function searchRefNum( $refNum )
{
$search = mysql_query( "select * FROM SBPayment WHERE ref_num = '$refNum'" );
if ( mysql_num_rows( $search ) < 1 ) {
return false;
}
return mysql_fetch_assoc( $search );
}
protected function saveBankInfo( $payment )
{
$this->payment = $payment;
return mysql_query( "UPDATE sbpayment SET ref_num = '$this->refNum' ,payment = '$payment' WHERE res_num = '$this->resNum'" ) or $this->setMsg(mysql_error());
}
public function saveStoreInfo( $totalAmont )
{
if( $totalAmont == '' ) {
$this->setMsg( "Error: TotalAmont" );
return false;
}
$time = time();
$this->totalAmont = $totalAmont;
$this->createResNum();
return mysql_query( "INSERT INTO sbpayment SET res_num = '$this->resNum', total_amont = '$this->totalAmont', date_start = $time" ) or $this->setMsg(mysql_error());
}
public function receiverParams( $resNum = '' , $refNum = '' ,$state = '' )
{
if( ( empty($state) or empty($resNum) or strlen($refNum) != 20 ) or $state != 'OK' ) {
if(isset($this->errorState[$state])) {
$this->setMsg( 'state',$state );
} else {
$this->setMsg("error state");
}
return false;
}
$searchResNum = $this->searchResNum( $resNum );
if( is_array( $searchResNum ) ) {
if( $searchResNum['payment'] > 0) {
$this->setMsg( "???? ?? ???? ?????? ????? ?????? ????" );
return false;
}
} else {
$this->setMsg("????? ??????? ?? ??? ??????? ????? ????");
return false;
}
$this->refNum = $refNum;
$this->resNum = $resNum;
$this->totalAmont = $searchResNum['total_amont'];
return $this->lastCheck();
}
protected function lastCheck()
{
if( empty($this->resNum) or strlen($this->refNum) != 20 ) {
$this->setMsg( "Error: resNum or refNum is empty" );
return false;
}
//web method verify transaction
$verify = $this->verifyTrans();
if( $verify > 0 ) {
if( $verify == $this->totalAmont ) {
$this->saveBankInfo( $verify );
$this->setMsg("?????? ?? ?????? ????? ?? ???? ?? ?????? ?? ??????? ????");
$this->setMsg( "$this->resNum"." : ?? ?????? " );
return true;
} elseif( $verify > $this->totalAmont ) {
//web method partial reverse transaction
$revAmont = $verify - $this->totalAmont;
$reverse = $this->reverseTrans( $revAmont );
$this->setMsg("????? ????? ???? ??????? ??? ?? ???? ???????? ???");
if( $reverse == 1 ) {
$this->setMsg("????? ???? ?????? ??? ?? ???? ??? ????? ?????");
$this->saveBankInfo( $this->totalAmont );
} else {
$this->setMsg( 'verify',$reverse );
$this->setMsg( "?? ??? ???? ??????? ??? ?? ????? ?? ????? ?? ???? ??? ????? ????? ???? " );
$this->saveBankInfo( $verify );
}
$this->setMsg("?????? ?? ?????? ????? ?? ???? ?? ?????? ?? ??????? ????");
$this->setMsg( "$this->resNum"." : ?? ?????? " );
return true;
} elseif( $verify < $this->totalAmont ) {
//web method full reverse transaction
$rev = $this->reverseTrans( $verify );
$this->setMsg("???? ??????? ??? ???? ?? ???? ????? ??? ");
if( $rev == 1 ) {
$this->setMsg("?? ???? ??????? ?? ???? ??? ????? ?????");
$this->saveBankInfo( 0 );
} else {
$this->setMsg("?? ????? ?? ????? ?? ???? ??????? ?? ???? ??? ????? ????? ???? ???? ???? ?? ???? ?? ?????? ?? ??????? ????");
$this->setMsg( "$this->resNum"." : ?? ?????? " );
$this->setMsg( 'verify',$rev );
$this->saveBankInfo( $verify );
}
return false;
}
//Error transaction
} elseif ( $verify < 0 or $verify == false ) {
$this->setMsg( "????? ????? ????? ?? ????? ?????? ??? ????" );
$this->setMsg( 'verify',$verify );
$this->saveBankInfo( 0 );
return false;
}
}
protected function verifyTrans()
{
if(empty($this->refNum) or empty($this->merchantID) ) {
return false;
}
$soapClient = new soapclient( $this->webMethodURL,'wsdl' );
$soapProxy = $soapClient->getProxy();
$result = false;
for( $a=1;$a<6;++$a ) {
$result = $soapProxy->verifyTransaction( $this->refNum,$this->merchantID );
if( $result != false ) {
break;
}
}
return $result;
}
protected function reverseTrans( $revNumber )
{
if( $revNumber <= 0 or empty($this->refNum) or empty($this->merchantID) or empty($this->password) ) {
return false;
}
$soapClient = new soapclient( $this->webMethodURL,'wsdl' );
$soapProxy = $soapClient->getProxy();
$result = false;
for( $a=1;$a<6;++$a ) {
$result = $soapProxy->reverseTransaction( $this->refNum,$this->merchantID,$this->password,$revNumber );
if( $result != false )
break;
}
return $result;
}
public function sendParams()
{
if ( $this->totalAmont <= 0 or empty($this->action) or empty($this->redirectURL) or empty($this->resNum) or empty($this->merchantID) ) {
$this->setMsg( "Error: function sendParams()" );
return false;
}
$form = "<html>";
$form .= "<body onLoad=\"document.forms['sendparams'].submit();\" >";
$form .= "<form name=\"sendparams\" method=\"POST\" action=\"$this->action\" enctype=\"application/x-www-form-urlencoded\" >\n";
foreach ( $this->style as $key=>$val ) {
if( $val != '' ) {
$form .= "<input type=\"hidden\" name=\"$key\" value=\"$val\" />\n";
}
}
$form .= "<input type=\"hidden\" name=\"Amont\" value=\"$this->totalAmont\" />\n";
$form .= "<input type=\"hidden\" name=\"ResNum\" value=\"$this->resNum\" />\n";
$form .= "<input type=\"hidden\" name=\"MID\" value=\"$this->merchantID\" />\n";
$form .= "<input type=\"hidden\" name=\"RedirectURL\" value=\"$this->redirectURL\" />\n";
$form .= "</form>";
$form .= "</body>";
$form .= "</html>";
print $form;
}
protected function setMsg($type='',$index='')
{
if ( $type == 'state' and isset( $this->errorState[$index] ) ) {
$this->msg[] = $this->errorState[$index];
} elseif( $type == 'verify' and isset($this->errorVerify[$index]) ) {
$this->msg[] = $this->errorVerify[$index];
} elseif( $type != 'verify' and $type != 'state') {
$this->msg[] = "$type";
}
}
public function getMsg($dis='')
{
if( count($this->msg) == 0 ) return array();
if( $dis == 'display' ) {
$msg = "<ul>\n";
foreach ( $this->msg as $v ) { $msg .= "<li> $v </li>\n"; }
$msg .= "</ul>\n";
return print $msg;
}
return $this->msg;
}
}
?>Code: Select all
<?php
ob_start();
header("content-type: text/html; charset=utf-8");
include './nusoap/lib/nusoap.php';
include './sbpayment.php';
$conn = mysql_connect('localhost','root','');
mysql_select_db('store',$conn);
$sb = new SBPayment("merchantID","password");
if( isset($_POST['State']) ){
$State = $_POST['State'];
$RefNum = $_POST['RefNum'];
$ResNum = $_POST['ResNum'];
$sb->receiverParams($ResNum,$RefNum,$State);
$sb->getMsg('display');
} elseif( isset( $_POST['submit'] ) ) {
if( $sb->saveStoreInfo( $_POST['totalAmont'] ) ) {
$sb->sendParams();
} else {
$sb->getMsg('display');
}
} else { ?>
<form action="<?php print $_SERVER['PHP_SELF']; ?>" method="post" />
???? ?????<input type="text" name="totalAmont" />
<input type="submit" name="submit" value="payment" />
</form>
<?php } ?>Thanks alot!
Hossein