Please help me with my eCommerce Website

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
studio23salons
Forum Newbie
Posts: 6
Joined: Sat May 31, 2014 8:22 am

Please help me with my eCommerce Website

Post by studio23salons »

Here's the problem:

PayPal Payout Problem

1. My problem is on the page where Members Activation is being paid using the website custom currency which is Peso, where 45 Pesos equals to $1.

2. The membership fee is 50 Pesos or $1.06 USD. The page "fees.php" shows correct Peso amount (50 Pesos) with $1.06 USD as equivalent in dollars.

3. When clicked the checkout, it proceeds to the page "process_payment.php", then proceeds to PayPal page

4. The problem is that it does not convert to the correct $1.06 amount, but shows $50 on the PayPal page which is wrong.

*** The Product page, where customers makes a purchase, there's no problem because PayPal converts the money correctly to USD amount. I believe there's something wrong with the "process_payment.php" page but I cannot figure it out.

Code: Select all

The website is:  www.studio23salons.com

Code: Select all

Please download the php files www.studio23salons.com/issuewithcurrencyonpaypal.zip
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Please help me with my eCommerce Website

Post by Celauran »

Not much we'll be able to tell you without seeing the code. Nobody's going to download some random zip file.
studio23salons
Forum Newbie
Posts: 6
Joined: Sat May 31, 2014 8:22 am

Re: Please help me with my eCommerce Website

Post by studio23salons »

thanks for your eply celauran... im so sorry about that.. i was trying to post all 3 php files at once and is not accepted by the system...

here's the fee.php code:

Code: Select all

<?php
require 'includes/master.inc.php';
require_once 'includes/vlib/vlibTemplate.php';
$Auth->requireUser('fee.php');
          $tmpl = new vlibTemplate('tmpl/pay_user.htm');
          $db = Database::getDatabase(); // DB conenction
          $tmpl->setvar('siteurl', $Config->siteurl);
          $tmpl->setvar('page_title', $Config->sitename .' : '.$tmpl->get_lstring('PAY FEE'));
          $username = $_SESSION['m_user']['username'];
$frm = $_POST;
$to = adminemailid();
$page_content = "";
$sitecurrency = $Config->currencysymbol;
$bank_enabled = $db->getValue("SELECT if(enabled>0,1,0) FROM `module` where name='bank' and type='payment'");
if(isset($frm) && isset($frm["send_msg"]) && $frm["send_msg"] == 1){
  $msgtext = "<b>Date: </b>".$frm['paid_date']."/".$frm['paid_month']."/".$frm['paid_year']."<br />
  <b>".$tmpl->get_lstring('AMOUNT').": </b>".$frm['paid_amount']."<br />
  <b>".$tmpl->get_lstring('TRANSFERRED TO').": </b>".$frm['paid_bank']."<br />
  <b>".$tmpl->get_lstring('TRANSFERRED FROM BANK').": </b>".$frm['branchname']."<br />
  <b>".$tmpl->get_lstring('BRANCH').": </b>".$frm['branchdistrict']."<br />
  <b>".$tmpl->get_lstring('STATE').": </b>".$frm['branchstate']."<br />
  <b>".$tmpl->get_lstring('NOTES').": </b>".nl2br($frm["message"])."<br />";
  $db->query("insert into message(`sent_time`,`text`,`sender`,`receiver`,`subject`) values('".time()."','$msgtext','".$_SESSION['m_user']['id']."','1','(Paid Fees)')");
  $page_content.="<span class=\"success\">".$tmpl->get_lstring('THANK YOU FOR THE PAYMENT DETAILS')."!</span><br /><br /><br />";
}
$mem_fees = get_plan_fee($_SESSION['m_user']['plan']);
$page_content.="<span style=\"font-size:140%;\">".$tmpl->get_lstring('FEE AMOUNT').": <strong>$sitecurrency$mem_fees</strong><br /></span><br />
<fieldset><legend>".$tmpl->get_lstring('PAYMENT OPTIONS')."</legend>";
$amount = round($mem_fees / $Config->currencyrate , 2);
$amount_orig = $amount;
$_SESSION['fee_amt']=$mem_fees;
//$page_content.="<b><span class='hlite'>".$tmpl->get_lstring('PAY BY CREDIT OR DEBIT CARD')."</span>";
/*$page_content .= "<img src=\"".$Config->siteurl."/images/account_balance.jpg\" alt=\"eWallet\" style=\"width:130px; padding:10px;\" />";*/
$res=$db->getRows("select * from module where type='payment' and enabled ='1' order by `order` asc");
foreach($res as $row)
{
	if($row['name']=='bank')
		{
			if(file_exists(DOC_ROOT."/images/logo/".$row['name'].".jpg"))
			{
			 $page_content.="<img src='images/logo/".$row['name'].".jpg'  style='width:130px; padding:10px;'/>&nbsp";
			}
			else
			{
			 $page_content="";
			}
		}
		else
		{
				$file=get_module_config($row['name'],$row['name'].'_logo');
				if($file)
				{
					if(file_exists(DOC_ROOT."/images/logo/".$file))
					{
					$page_content.="<img src='images/logo/".$file."' alt='".$row['name']."' style='width:130px; padding:10px;'/>&nbsp";
					}
					else
					{
					$page_content.="&nbsp;&nbsp;&nbsp;".$row['name']."&nbsp;&nbsp;&nbsp;";
					}
				}
				else
				{
				 $page_content.="";
				}
		}
}
		$page_content.="<br />
    <div style='text-align:center'>
		<input class='subbutton button' type=\"button\" name=\"submit\" value=\"".$tmpl->get_lstring('CONTINUE')." >>\" onclick=\"document.location.href='process_payment.php?type=".$g_payment_member_join."'\">
    </div>
		<br />";
if($bank_enabled == 1)
 {
	/*$page_content.=$tmpl->get_lstring('BANK TRANS OR DEPOSIT')."<img src=\"".$Config->imageurl."/bank_transf.jpg\"><br />
	".$tmpl->get_lstring('TRANS OR DEPOSIT FEES AMT TO BANK ACNT').".<br />
	<br /><br />";*/
	$bankoptions = "";
	$res = $db->getRows("select * from settings_bank");
	//while($row = db_fetch_array($res)){
	foreach($res as $row){
	  $bankoptions .= "<option value=\"".$row['bank']."\">". $row['bank']."</option>";
	  /*$page_content .= "<br /><strong>". $row['bank']."</strong><br />";
	  if($row['bankimage']) $page_content .= "<img src=\"".$Config->siteurl."/images/".$row['bankimage']."\" style='float:left;margin-right:10px;'>";
	  $page_content .= "A/c No: <strong>".$row['accountnumber']."</strong><br />". htmlspecialchars_decode(stripslashes($row['payee'])) . "<br /><br /><br />";*/
	}
	$page_content.="</fieldset>";
$page_content.="
<br /><span class=\"hlite\">
".$tmpl->get_lstring('ALREADY MADE PAYMENT SEND DETAILS').":</span>
<form method=\"post\" action=\"\" onSubmit=\"return checkform(this);\">
<input type=\"hidden\" name=\"send_msg\" value=\"1\">
<table border=\"0\">
  <tr><td><font style='color:red;'>*</font> ".$tmpl->get_lstring('PAYMENT DATE').":</td><td align='left'><select name=\"paid_date\">".get_day_options(date('d')) ."</select><select name=\"paid_month\">" . get_month_options(date('m')) . "</select><select name=\"paid_year\">" . get_year_options3() . "</select></td></tr>
  <tr><td><font style='color:red;'>*</font> ".$tmpl->get_lstring('AMOUNT').":</td><td><input type=\"text\" class=\"input\" name=\"paid_amount\"></td></tr>
  <tr><td><font style='color:red;'>*</font> ".$tmpl->get_lstring('TRANSFERRED TO').":</td><td><select class=\"input\" name=\"paid_bank\">
  $bankoptions
  <option value=\"other\">Other</option>
  </select></td></tr>
  <tr><td><b>".$tmpl->get_lstring('TRANSFERRED FROM BANK').":</b></td></tr>
  <tr><td>".$tmpl->get_lstring('BANK NAME').":</td><td><input type=\"text\" class=\"input\" name=\"branchname\"></td></tr>
  <tr><td>".$tmpl->get_lstring('CITY').":</td><td><input type=\"text\" class=\"input\" name=\"branchdistrict\"></td></tr>
  <tr><td>".$tmpl->get_lstring('STATE REGION').":</td><td><input type=\"text\" class=\"input\" name=\"branchstate\"></td></tr>
  <tr><td colspan=\"2\">".$tmpl->get_lstring('MESSAGE').": <br /><textarea style=\"width:350px;height:90px;\" name=\"message\" id=\"message\" rows=\"5\" cols=\"30\"></textarea></td></tr>
  </table>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  <input class='subbutton button' type=\"submit\" name=\"Submit\" value=\"Send\">
</form>
";
}
$tmpl->setvar('pagecontent',$page_content);
$tmpl->pparse();
?>
studio23salons
Forum Newbie
Posts: 6
Joined: Sat May 31, 2014 8:22 am

Re: Please help me with my eCommerce Website

Post by studio23salons »

here's the process_payment.php file:

Code: Select all

<?php
$PAGE = 'store';
require 'includes/master.inc.php';
require_once 'includes/vlib/vlibTemplate.php';
require_once 'includes/vlib/vlibDate.php';
if($_GET['type']==4)
{}
else{
 $Auth->requireUser('process_payment.php');}
$tmpl = new vlibTemplate('tmpl/process_payment.htm');
$tmpl->setvar('siteurl', $Config->siteurl);
$tmpl->setvar('page_title', $Config->title . " :".$tmpl->get_lstring('CHECKOUT'));
$db = Database::getDatabase();
$tmpl->setvar('debug','');
$tmpl->setvar('disable','');
$err=0;
$tmpl->setvar('hide_account',0);
if(!isset($_GET['type']))
{
	redirect('home.php');
}
else
{
	if(($_GET['type']==1) || ($_GET['type']==4) || ($_GET['type']==6))
	{
		$tmpl->setvar('hide_account',1);
	}
}
$this_script = $Config->siteurl."/call_back.php";
$payza_recurring_script = $Config->siteurl."/payzacall_back.php";
if(($_GET['type']==1) || ($_GET['type']==2)  || ($_GET['type']==3) || ($_GET['type']==6))
{
$username= $_SESSION['un'];
}
else
{
	$username= "";
}
$timestamp = date('Y-m-d H:i:s');
$balance=get_member_balance($username);
$amount = get_usd_amount($_SESSION['carttotal']+get_config('shipping_charge'));
$frm = $_POST;
$to = adminemailid();
$page_content = "";
if(isset($_SESSION['carttotal']))
{
	$amount = get_usd_amount($_SESSION['carttotal']+get_config('shipping_charge'));
	$cart_amount=$_SESSION['carttotal']+get_config('shipping_charge');
	$tmpl->setvar('total_in_local',$_SESSION['carttotal']+get_config('shipping_charge'));
	$tmpl->setvar('usd_total',$amount);
}
elseif(isset($_SESSION['fee_amt']))
{
	$amount = get_usd_amount($_SESSION['fee_amt']);
	$fee=$_SESSION['fee_amt'];	
	$tmpl->setvar('total_in_local',$_SESSION['fee_amt']);
	$tmpl->setvar('usd_total',$amount);
}
$tmpl->setvar('hide_content',0);
if($frm['submit'] )
{
  $payment=$frm['payment'];
	if(isset($payment))
	{
		//Throught E-wallent Balance
		if($payment=='account')
		{
			if($balance < $cart_amount)
			{
				$err=1;
				$msg=$tmpl->get_lstring('YOU HAVE INSUFFICIENT ACCOUNT BALANCE');
				$tmpl->setvar('msg_err',$msg);
			}
			else
			{
				$comment='Debited for product purchase';
				$orderid = add_new_order($username,'account');
				debit_member($username, $cart_amount, $comment, $timestamp);
				change_order_status($orderid, 'paid', "auto-debited from eWallet balance", 1);
				unset($_SESSION['cart']);
				unset($_SESSION['carttotal']);
				$tmpl->setvar('debug',"<h2>".$tmpl->get_lstring('ORDER COMPLETE')."!</h2><br /><b>".$tmpl->get_lstring('YOU ACCOUNT IS DEBITED')." ".$Config->currencysymbol.$cart_amount." <br /><a href='myorders.php'>".$tmpl->get_lstring('VIEW ORDER DETAILS')."</a>");
				$tmpl->setvar('ordercomplete',1);
			}
		}
		else if($payment=='bank')
		{
			$payment_type = $_GET['type'];
			if($payment_type==1 || $payment_type==2)
			{
				$res=$db->getRows("select * from settings_bank");
				$debug ="";
				$debug .="<h2>Thank You!</h2>You can transfer or deposit the amount to any of the accounts mentioned below. After making the payment send transaction details with Order ID to support team. <br />
				<br />";
				foreach($res as $row){
				$debug .="<b>".$tmpl->get_lstring('BANK').":</b> ".$row['bank']." <br />";
				$debug .="<b>".$tmpl->get_lstring('ACCOUNT NO').":</b> ".$row['accountnumber']." <br />";
				$debug .="<b>".$tmpl->get_lstring('PAYEE').":</b> ".$row['payee']." <br />----------------<br />";
				}
				$tmpl->setvar('debug',$debug);
				$tmpl->setvar('ordercomplete',1);
			}
			if($payment_type==3)
			{
				add_new_order($username,'offline');
				unset($_SESSION['cart']);
				$res=$db->getRows("select * from settings_bank");
				$debug ="";
				$debug .="<h2>".$tmpl->get_lstring('ORDER COMPLETE')."!</h2>You can transfer or deposit the amount to any of the accounts mentioned below. After making the payment send transaction details with Order ID to support team. <br />
				<br />";
				foreach($res as $row){
				$debug .="<b>".$tmpl->get_lstring('BANK').":</b> ".$row['bank']." <br />";
				$debug .="<b>".$tmpl->get_lstring('ACCOUNT NO').":</b> ".$row['accountnumber']." <br />";
				$debug .="<b>".$tmpl->get_lstring('PAYEE').":</b> ".$row['payee']." <br />----------------<br />";
				}
				$tmpl->setvar('debug',$debug);
				$tmpl->setvar('ordercomplete',1);
			}
			if($payment_type==4)
			{
				add_new_order(0,'offline');
				unset($_SESSION['cart']);
				$res=$db->getRows("select * from settings_bank");
				$debug ="";
				$debug .="<h2>".$tmpl->get_lstring('ORDER COMPLETE')."!</h2>You can transfer or deposit the amount to any of the accounts mentioned below. After making the payment send transaction details with Order ID to support team. <br />
				<br />";
				foreach($res as $row){
				$debug .="<b>".$tmpl->get_lstring('BANK').":</b> ".$row['bank']." <br />";
				$debug .="<b>".$tmpl->get_lstring('ACCOUNT NO').":</b> ".$row['accountnumber']." <br />";
				$debug .="<b>".$tmpl->get_lstring('PAYEE').":</b> ".$row['payee']." <br />----------------<br />";
				}
				$tmpl->setvar('debug',$debug);
				$tmpl->setvar('ordercomplete',1);
			}
		}
		elseif($payment=='cashsense')
		{
			$cashsense_form="";
			$payment_type = $_GET['type'];
			if($payment_type==1)
			{
				$fee_amt=round(($fee + get_module_config('cashsense','cashsense_fee_fixed'))/(100/(100 + get_module_config('cashsense','cashsense_fee') )) , 2);
				$cashsense_form .="<fieldset><legend>Cashsense Payment</legend><form action='https://merchantapi.cashsense.com/MerchantFormPost.aspx' method='post'>
				<input id='fxMerchantID' type='hidden' name='fxMerchantID' value='".get_module_config('cashsense','cashsense_id')."' />
				<input id='fcusername' type='hidden' name='fcusername' value='".get_module_config('cashsense','cashsense_username')."'/>
				<input id='fcpassword' type='hidden' name='fcpassword' value='".get_module_config('cashsense','cashsense_pwd')."'/>		
				<table border='0' cellpadding='3' cellspacing='3'>
				<tr><td><b><span style='color:red;'>*</span> Username: </b></td><td><input id='fcCustomerName' type='text' name='fcCustomerName' value='".$_SESSION['m_user']['username']."' readonly='readonly'/><td></tr>
				<tr><td><b><span style='color:red;'>*</span> Email:</b> </td><td><input id='Text1' type='text' name='fcEmailAddress' value='".$_SESSION['m_user']['email']."' readonly='readonly'/></td></tr>
				<tr><td><b><span style='color:red;'>*</span> Amount: </b></td><td><input id='fnAmount' type='text' name='fnAmount' value='".$fee_amt."' readonly='readonly'/></td></tr>
				<input id='fcMerchantTxnID' type='hidden' name='fcMerchantTxnID' value='".generate_txnid()."'/>
				<input id='fxProdID' type='hidden' name='fxProdID' value='0'/>
				<input id='fcProductCode' type='hidden' name='fcProductCode' value='' />
				<input id='fnProdQty' type='hidden' name='fnProdQty' value='0' />
				<input id='fcDescription' type='hidden' name='fcDescription' value='Membership Fee'/>
				<tr><td colspan='2' align='center'><input type='submit' value='submit'  class='subbutton button'/></td></tr></table>
				</form></fieldset>";				
				$tmpl->setvar('debug',$cashsense_form);
				$tmpl->setvar('ordercomplete',1);
				
			}
			if($payment_type==2)
			{
				$fee_amt=round(($fee + get_module_config('cashsense','cashsense_fee_fixed'))/(100/(100 + get_module_config('cashsense','cashsense_fee') )) , 2);
				$cashsense_form .="<fieldset><legend>Cashsense Payment</legend><form action='https://merchantapi.cashsense.com/MerchantFormPost.aspx' method='post'>
				<input id='fxMerchantID' type='hidden' name='fxMerchantID' value='".get_module_config('cashsense','cashsense_id')."' />
				<input id='fcusername' type='hidden' name='fcusername' value='".get_module_config('cashsense','cashsense_username')."'/>
				<input id='fcpassword' type='hidden' name='fcpassword' value='".get_module_config('cashsense','cashsense_pwd')."'/>		
				<table border='0' cellpadding='3' cellspacing='3'>
				<tr><td><b><span style='color:red;'>*</span> Username: </b></td><td><input id='fcCustomerName' type='text' name='fcCustomerName' value='".$_SESSION['m_user']['username']."' readonly='readonly'/><td></tr>
				<tr><td><b><span style='color:red;'>*</span> Email:</b> </td><td><input id='Text1' type='text' name='fcEmailAddress' value='".$_SESSION['m_user']['email']."' readonly='readonly'/></td></tr>
				<tr><td><b><span style='color:red;'>*</span> Amount: </b></td><td><input id='fnAmount' type='text' name='fnAmount' value='".$fee_amt."' readonly='readonly'/></td></tr>
				<input id='fcMerchantTxnID' type='hidden' name='fcMerchantTxnID' value='".generate_txnid()."'/>
				<input id='fxProdID' type='hidden' name='fxProdID' value='0'/>
				<input id='fcProductCode' type='hidden' name='fcProductCode' value='' />
				<input id='fnProdQty' type='hidden' name='fnProdQty' value='0' />
				<input id='fcDescription' type='hidden' name='fcDescription' value='Membership Renewal Fee'/>
				<tr><td colspan='2' align='center'><input type='submit' value='submit'  class='subbutton button'/></td></tr></table>
				</form></fieldset>";				
				$tmpl->setvar('debug',$cashsense_form);
				$tmpl->setvar('ordercomplete',1);
			}
			if($payment_type==3)
			{
				$orderid = add_new_order($username,'cashsense');
				unset($_SESSION['cart']);
				$cartamt=round(($cart_amount + get_module_config('cashsense','cashsense_fee_fixed'))/(100/(100 + get_module_config('cashsense','cashsense_fee') )) , 2);
				$cashsense_form .="<fieldset><legend>Cashsense Payment</legend><form action='https://merchantapi.cashsense.com/MerchantFormPost.aspx' method='post'>
				<input id='fxMerchantID' type='hidden' name='fxMerchantID' value='".get_module_config('cashsense','cashsense_id')."' />
				<input id='fcusername' type='hidden' name='fcusername' value='".get_module_config('cashsense','cashsense_username')."'/>
				<input id='fcpassword' type='hidden' name='fcpassword' value='".get_module_config('cashsense','cashsense_pwd')."'/>		
				<table border='0' cellpadding='3' cellspacing='3'>
				<tr><td><b><span style='color:red;'>*</span> Username: </b></td><td><input id='fcCustomerName' type='text' name='fcCustomerName' value='".$_SESSION['m_user']['username']."' readonly='readonly'/><td></tr>
				<tr><td><b><span style='color:red;'>*</span> Email:</b> </td><td><input id='Text1' type='text' name='fcEmailAddress' value='".$_SESSION['m_user']['email']."' readonly='readonly'/></td></tr>
				<tr><td><b><span style='color:red;'>*</span> Amount: </b></td><td><input id='fnAmount' type='text' name='fnAmount' value='".$cartamt."' readonly='readonly'/></td></tr>
				<input id='fcMerchantTxnID' type='hidden' name='fcMerchantTxnID' value='".generate_txnid()."'/>
				<input id='fxProdID' type='hidden' name='fxProdID' value='0'/>
				<input id='fcProductCode' type='hidden' name='fcProductCode' value='' />
				<input id='fnProdQty' type='hidden' name='fnProdQty' value='0' />
				<input id='fcDescription' type='hidden' name='fcDescription' value='Membership Product Purchase'/>
				<tr><td colspan='2' align='center'><input type='submit' value='submit'  class='subbutton button'/></td></tr></table>
				</form></fieldset>";				
				$tmpl->setvar('debug',$cashsense_form);
				$tmpl->setvar('ordercomplete',1);
			}
			if($payment_type==4)
			{
				$orderid = add_new_order(0,'cashsense');
				unset($_SESSION['cart']);
				$cartamt=round(($cart_amount + get_module_config('cashsense','cashsense_fee_fixed'))/(100/(100 + get_module_config('cashsense','cashsense_fee') )) , 2);
				$cashsense_form .="<fieldset><legend>Cashsense Payment</legend><form action='https://merchantapi.cashsense.com/MerchantFormPost.aspx' method='post'>
				<input id='fxMerchantID' type='hidden' name='fxMerchantID' value='".get_module_config('cashsense','cashsense_id')."' />
				<input id='fcusername' type='hidden' name='fcusername' value='".get_module_config('cashsense','cashsense_username')."'/>
				<input id='fcpassword' type='hidden' name='fcpassword' value='".get_module_config('cashsense','cashsense_pwd')."'/>		
				<table border='0' cellpadding='3' cellspacing='3'>
				<tr><td><b><span style='color:red;'>*</span> Username: </b></td><td><input id='fcCustomerName' type='text' name='fcCustomerName' value='' /><td></tr>
				<tr><td><b><span style='color:red;'>*</span> Email:</b> </td><td><input id='Text1' type='text' name='fcEmailAddress' value='' /></td></tr>
				<tr><td><b><span style='color:red;'>*</span> Amount: </b></td><td><input id='fnAmount' type='text' name='fnAmount' value='".$cartamt."' readonly='readonly'/></td></tr>
				<input id='fcMerchantTxnID' type='hidden' name='fcMerchantTxnID' value='".generate_txnid()."'/>
				<input id='fxProdID' type='hidden' name='fxProdID' value='0'/>
				<input id='fcProductCode' type='hidden' name='fcProductCode' value='' />
				<input id='fnProdQty' type='hidden' name='fnProdQty' value='0' />
				<input id='fcDescription' type='hidden' name='fcDescription' value='Guest Product Purchase'/>
				<tr><td colspan='2' align='center'><input type='submit' value='submit'  class='subbutton button'/></td></tr></table>
				</form></fieldset>";				
				$tmpl->setvar('debug',$cashsense_form);
				$tmpl->setvar('ordercomplete',1);
			}
			
		}
		else
		{
			require "includes/payment/".$payment.".php";
			require "includes/order.php";
			require "includes/user.php";
			$classname=$payment;
			$obj=new $payment();
			$ord=new order();
			$usr=new userinfo();
			$userid = $_SESSION['m_user']['id'];
			$username = $_SESSION['m_user']['username'];
			$payment_type = $_GET['type'];
			if($payment_type==1)
			{
				if($payment=='paypal_recurring')
				{
					$item_name="Membership paypal monthly recurring fee";
					$custom="userid-".$_SESSION['m_user']['id']."|type-5|mode-paypal_recurring";
					$obj->process($item_name,$fee,$custom,$this_script);
					$tmpl->setvar('hide_content',1);
				}
				elseif($payment=='payza_recurring')
				{
						$item_name="Membership payza monthly recurring fee";
						$custom="userid-".$_SESSION['m_user']['id']."|type-5|mode-payza_recurring";
						$obj->process($item_name,$fee,$custom,$payza_recurring_script);
						$tmpl->setvar('hide_content',1);
				}
				else
				{
				 $item_name="Membership Fee";
				 $custom="userid-".$_SESSION['m_user']['id']."|type-".$payment_type."|mode-".$payment;
				 $obj->process($item_name,$fee,$custom,$this_script);
				 $tmpl->setvar('hide_content',1);
				}
			}
			if($payment_type==2)
			{
				if($payment=='paypal_recurring')
				{
					$item_name="Membership paypal monthly recurring renewal fee";
					$custom="userid-".$_SESSION['m_user']['id']."|type-5|mode-paypal_recurring";
					$obj->process($item_name,$fee,$custom,$this_script);
					$tmpl->setvar('hide_content',1);
				}
				elseif($payment=='payza_recurring')
				{
						$item_name="Membership payza monthly recurring renewal fee";
						$custom="userid-".$_SESSION['m_user']['id']."|type-5|mode-payza_recurring";
						$obj->process($item_name,$fee,$custom,$payza_recurring_script);
						$tmpl->setvar('hide_content',1);
				}
				else
				{
				 $item_name="Membership Renewal Fee";
				 $custom="userid-".$_SESSION['m_user']['id']."|type-".$payment_type."|mode-".$payment;
				 $obj->process($item_name,$fee,$custom,$this_script);
				 $tmpl->setvar('hide_content',1);
				}
			}
			if($payment_type==3)
			{
				if($payment=='payza'){	$payment_method='alertpay';}
				elseif($payment=='liberty_reserve'){$payment_method='lr'; }
				elseif($payment=='money_booker'){$payment_method='skrill'; }
				else{$payment_method=$payment;}
				$item_name="Product Purchase";
				$order_id = $ord->add_new_order($_SESSION['m_user']['username'],$payment_method);
				$custom="userid-".$_SESSION['m_user']['id']."|type-".$payment_type."|orderid-".$order_id."|mode-".$payment;
				$obj->process($item_name,$amount,$custom,$this_script);
				unset($_SESSION['cart']);
				unset($_SESSION['carttotal']);
				$tmpl->setvar('hide_content',1);
			}
			if($payment_type==4)
			{
				if($payment=='payza'){	$payment_method='alertpay';}
				elseif($payment=='liberty_reserve'){$payment_method='lr'; }
				elseif($payment=='money_booker'){$payment_method='skrill'; }
				else{$payment_method=$payment;}
				$item_name="Guest Product Purchase";
				$order_id = $ord->add_new_order(0,$payment_method);
				$custom="userid-0|type-".$payment_type."|orderid-".$order_id."|mode-".$payment;
				$obj->process($item_name,$amount,$custom,$this_script);
				unset($_SESSION['cart']);
				unset($_SESSION['carttotal']);
				$tmpl->setvar('hide_content',1);
			}
			if($payment_type==6)
			{
				$item_name="Membership Plan upgrade";
				$custom="userid-".$_SESSION['m_user']['id']."|type-".$payment_type."||mode-".$payment;
				$obj->process($item_name,$fee,$custom,$this_script);
				$tmpl->setvar('hide_content',1);
			}
		}
	}
	else
	{
		$err=1;
		$msg="<b style='color:#F00'>".$tmpl->get_lstring('SELECT ANY PAYMENT OPTION')."</b>";
        $tmpl->setvar('debug',$msg);
	}
}
if($_GET['type']==6)
{
//Get all Installed payment gateways
$res=$db->getRows("select * from module 
				  where 
				  type='payment' 
				  and enabled ='1' 
				  and name!='paypal_recurring' 
				  and  name!='payza_recurring'
				   and  name!='bank'
				  order by `order` asc");
}
else
{
//Get all Installed payment gateways
$res=$db->getRows("select * from module where `enabled`='1' and `type`='payment' order by `order` asc");
}
$payment_list ="";
if(count($res) >0)
{
	$payment_list .='<tr>';
	$i=1;
	foreach($res as $row)
	{
		if($row['name']=='bank')
		{
			$hide='onclick="return show_details_bank()"';
			if(file_exists(DOC_ROOT."/images/logo/".$row['name'].".jpg"))
			{
			 $payment_logo="<img src='images/logo/".$row['name'].".jpg'  width='140px' />";
			}
			else
			{
			 $payment_logo="";
			}
		}
		else
		{
			$hide='onclick="return hide_details();"';
			$file=get_module_config($row['name'],$row['name'].'_logo');
			if($file)
			{
				if(file_exists(DOC_ROOT."/images/logo/".$file))
				{
				$payment_logo="<img src='images/logo/".$file."' width='140px'  />";
				}
				else
				{
				$payment_logo="";
				}
			}
			else
			{
			 $payment_logo="";
			}
		}
		$payment_list .='<td width="50px;" align="right">
		<input type="radio" name="payment" value='.$row['name'].' '.$hide.'>
		</td>
		<td width="220px;" style="padding-left:10px;"><b>'.ucwords(str_replace('_',' ',$row['name'])).'</b>
		<br />'.$payment_logo;
		
		if($row['name']=='cashsense')
		{
			$payment_list .='<br />(Charges :P'.sprintf("%1\$.2f",get_module_config($row['name'],$row['name'].'_fee_fixed')).'+'.sprintf("%1\$.2f",get_module_config($row['name'],$row['name'].'_fee')).'%)';
		}
		elseif($row['name']!=='bank')
		{
			$payment_list .='<br />(Charges :$'.sprintf("%1\$.2f",get_module_config($row['name'],$row['name'].'_fee_fixed')).'+'.sprintf("%1\$.2f",get_module_config($row['name'],$row['name'].'_fee')).'%)';
		}
		
		$payment_list .='</td>';
		if (($i % 2) == 0)
		{
		$payment_list .='</tr><tr>';
		}
		else
		{
		$payment_list .='';
		}
		$i++;
	}
	$payment_list .='<tr>';
}
$tmpl->setvar('payment_list',$payment_list);
$account_msg="<fieldset><legend>".$tmpl->get_lstring('ACCOUNT DETAILS')."</legend><table><tr><td><b>".$tmpl->get_lstring('YOUR ACCOUNT BALANCE').": </td><td>".str_replace('Â','',$Config->currencysymbol)."".$balance."</b></td></tr></table></fieldset>";
$tmpl->setvar('account_msg',$account_msg);
$bank_details=$db->getRow("select * from settings_bank");
$page_content.=$tmpl->get_lstring('CHECKOUT_A')."
<!--				 <b>".$tmpl->get_lstring('BANK').":</b> ".$bank_details['bank']." <br />
				 <b>".$tmpl->get_lstring('ACCOUNT NO').":</b> ".$bank_details['accountnumber']." <br />
				 <b>".$tmpl->get_lstring('PAYEE').":</b> ".$bank_details['payee']."--><table>";
$bankoptions = "";
$res = $db->getRows("select * from settings_bank");
foreach($res as $row)
{
  $page_content .="<tr>";
  $bankoptions .= "<option value=\"".$row['bank']."\">". $row['bank']."</option>";
  $page_content .= "<td style='padding-right:20px;'><br /><strong>". $row['bank']."</strong><br /></td>";
  if($row['bankimage']) $page_content .= "<td style='padding-right:20px;'><img src=\"".$Config->siteurl."/images/".$row['bankimage']."\" style='float:left;margin-right:10px;'></td>";
  $page_content .= "<td>A/c No: <strong>".$row['accountnumber']."</strong><br />". htmlspecialchars_decode(stripslashes($row['payee'])) . "<br /><br /><br /></td>";
  $page_content .="</tr>";
}
$page_content.="</table></fieldset>";
$tmpl->setvar('page_content',$page_content);
$tmpl->pparse();
?>
studio23salons
Forum Newbie
Posts: 6
Joined: Sat May 31, 2014 8:22 am

Re: Please help me with my eCommerce Website

Post by studio23salons »

lastly, here's the paypal.php

Code: Select all

<?php
include_once  '../includes/master.inc.php';
class paypal
{
	var $last_error;                 // holds the last error encountered
	var $ipn_log;                    // bool: log IPN results to text file?
	var $ipn_log_file;               // filename of the IPN log
	var $ipn_response;               // holds the IPN response from paypal
	var $ipn_custom;               // holds the IPN response from paypal
	var $ipn_data = array();         // array contains the POST values for IPN
	var $fields = array();           // array holds the fields to submit to paypal
	var $paypal_url;
	var $paypal_postback;
	function paypal()
	{
		$db = Database::getDatabase();
		if(get_module_config('paypal','paypal_live'))
		{
		 $this->paypal_url = 'https://www.paypal.com/cgi-bin/webscr';
		 $this->paypal_postback = 'ssl://www.paypal.com';
		}
		else
		{
		 $this->paypal_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
		 $this->paypal_postback = 'ssl://www.sandbox.paypal.com';
		}
		$this->last_error = '';
		$this->ipn_log_file = '.paypal_payment.log';
		$this->ipn_log = true;
		$this->ipn_response = '';
	}
	function process($itemname,$cart_amt,$custom,$this_script)
	{
		$db = Database::getDatabase();
		$amt=round(($cart_amt + get_module_config('paypal','paypal_fee_fixed'))/(100/(100 + get_module_config('paypal','paypal_fee') )) , 2);
		echo "<html>\n";
		echo "<head><title>Processing Payment...</title></head>\n";
		echo "<body onLoad=\"document.forms['paypal_form'].submit();\">\n";
		echo "<center><h2>Please wait, your order is being processed and you";
		echo " will be redirected to the paypal website.</h2></center>\n";
		echo "<form method=\"post\" name=\"paypal_form\" ";
		echo "action=\"".$this->paypal_url."\">\n";
		echo "<input type=\"hidden\" name=\"business\" value=\"".get_module_config('paypal','paypal_id')."\"/>\n";
		echo "<input type=\"hidden\" name=\"return\" value=\"".$this_script."?action=success\"/>\n";
		echo "<input type=\"hidden\" name=\"cancel_return\" value=\"".$this_script."?action=cancel\"/>\n";
		echo "<input type=\"hidden\" name=\"notify_url\" value=\"".$this_script."?mode=paypal\"/>\n";
		echo "<input type=\"hidden\" name=\"currency_code\" value=\"USD\"/>\n";
		echo "<input type=\"hidden\" name=\"rm\" value=\"2\"/>\n";
		echo "<input type=\"hidden\" name=\"cmd\" value=\"_xclick\"/>\n";
		echo "<input type=\"hidden\" name=\"item_name\" value=\"".$itemname."\"/>\n";
		echo "<input type=\"hidden\" name=\"amount\" value=\"".$amt."\"/>\n";
		echo "<input type=\"hidden\" name=\"custom\" value=\"".$custom."\"/>\n";
		echo "<center><br/><br/>If you are not automatically redirected to ";
		echo "paypal within 5 seconds...<br/><br/>\n";
		echo "<input type=\"submit\" value=\"Click Here\"></center>\n";
		echo "</form>\n";
		echo "</body></html>\n";
	}
	function validate($response)
	{
	  $db = Database::getDatabase();
	  $fp=fopen($this->ipn_log_file,'a');
      fwrite($fp, "---------------------Start\n\n");
      fclose($fp);
      // parse the paypal URL
      $url_parsed=parse_url($this->paypal_url);
      // generate the post string from the _POST vars aswell as load the
      // _POST vars into an arry so we can play with them from the calling
      // script.
      $post_string = '';
      foreach ($response as $field=>$value) {
         $this->ipn_data["$field"] = $value;
         $post_string .= $field.'='.urlencode(stripslashes($value)).'&';
      }
      $post_string.="cmd=_notify-validate"; // append ipn command
   		if( $this->ipn_data['mc_gross'] <= 0 )
   		{
        $this->last_error = "Incorrect Amount Paid : ". $this->ipn_data['mc_gross'];
        $this->log_ipn_results(false);
        return false;
   		}
		if($this->ipn_data['payment_status'] !='Completed')
   		{
        $this->last_error = "Invalid Payment Status: ". $this->ipn_data['payment_status'];
        $this->log_ipn_results(false);
        return false;
   		}
		if($this->ipn_data['txn_type'] !='web_accept')
   		{
        $this->last_error = "Invalid Transaction type: ". $this->ipn_data['txn_type'];
        $this->log_ipn_results(false);
        return false;
   		}
      // open the connection to paypal
      $fp = fsockopen($this->paypal_postback,"443",$err_num,$err_str,30);
      if(!$fp)
	  {
         $this->last_error = "fsockopen error no. $errnum: $errstr";
         $this->log_ipn_results(false);
         return false;
      }
	  else
	  {
         // Post the data back to paypal
         fputs($fp, "POST $url_parsed[path] HTTP/1.1\r\n");
         fputs($fp, "Host: $url_parsed[host]\r\n");
         fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
         fputs($fp, "Content-length: ".strlen($post_string)."\r\n");
         fputs($fp, "Connection: close\r\n\r\n");
         fputs($fp, $post_string . "\r\n\r\n");
         // loop through the response from the server and append to variable
         while(!feof($fp)) {
            $this->ipn_response .= fgets($fp, 1024);
         }
         fclose($fp); // close connection
      }
      if (eregi("VERIFIED",$this->ipn_response)) 
	  {
         // Valid IPN transaction.
		$this->log_ipn_results(true);
		
		$txn_id = $this->ipn_data['txn_id'];
		$rowcount = $db->getValue("select count(id) from paypal_transactions where txnid='" . $txn_id . "'");
		if ($rowcount == 0)
		{
			$db->query("insert into paypal_transactions set txnid='" . $txn_id . "',
			date='" . date('Y-m-d H:i:s') . "',
			payment_type='" . $this->ipn_data['payment_type'] . "',
			payer_email='" . $this->ipn_data['payer_email'] . "',
			mc_gross='" . $this->ipn_data['mc_gross'] . "',
			mc_currency='" . $this->ipn_data['mc_currency'] . "',
			txn_type='" . $this->ipn_data['txn_type'] . "'");
		}
		return true;
      } else {
         // Invalid IPN transaction.  Check the log for details.
         $this->last_error = 'IPN Validation Failed.';
         $this->log_ipn_results(false);
         return false;
      }
	}
	
	function log_ipn_results($success) 
	{
      if (!$this->ipn_log) return;  // is logging turned off?
      // Timestamp
      $text = '['.date('m/d/Y g:i A').'] - ';
      // Success or failure being logged?
      if ($success) $text .= "SUCCESS!\n";
      else $text .= 'FAIL: '.$this->last_error."\n";
      // Log the POST variables
      $text .= "IPN POST Vars from Paypal:\n";
      foreach ($this->ipn_data as $key=>$value) {
         $text .= "$key=$value, ";
      }
      // Log the response from the paypal server
      $text .= "\nIPN Response from Paypal Server:\n ".$this->ipn_response;
      // Write to log
      $fp=fopen($this->ipn_log_file,'a');
      fwrite($fp, $text . "\n\n");
      fclose($fp);  // close file
   }
}
?>
studio23salons
Forum Newbie
Posts: 6
Joined: Sat May 31, 2014 8:22 am

Re: Please help me with my eCommerce Website

Post by studio23salons »

please help me Celauran... thanks
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Please help me with my eCommerce Website

Post by Celauran »

Code: Select all

echo "<input type=\"hidden\" name=\"currency_code\" value=\"USD\"/>\n";
Shouldn't that be in pesos, not US dollars?
Post Reply