How to add multiple paypal accounts

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
bigfoot_3000
Forum Newbie
Posts: 6
Joined: Tue Jan 26, 2010 6:44 am

How to add multiple paypal accounts

Post by bigfoot_3000 »

Hi,

I am a novice to php and MySQL, I know html and css and learning php and mysql and it's making me scratch my head a little bit too hard <will need to invest in a hard hat>.

I have a php script that is attached to mysql, it is a restaurant script. But is only has facility to add PayPal as a payment option on one restaurant, so when they check out and pay via paypal it uses one paypal account email. So, if I want to add a second restaurant - that second one will also be using the first one's paypal email address/account.

Below is the paypal code i found in the settings.php.

define('PAYPAL_EMAIL', 'info@youremailaddress.com');
define('PAYPAL_BUTTON', '<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="'.PAYPAL_EMAIL.'">
<input type="hidden" name="item_name" value="#{order_id} Food Order">
<input type="hidden" name="amount" value="{total_price}">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="button_subtype" value="products">
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted">
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
<input type="hidden" name="return" value="'.$GLOBALS['mainurl'].'paypal.php">
<input type="hidden" name="cancel_return" value="'.$GLOBALS['mainurl'].'">
</form>');

Now, if I add another restaurant, what do I need to do in order each restaurant can use it's own individual paypal email address?

Kind regards,

Bigfoot_3000
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: How to add multiple paypal accounts

Post by AbraCadaver »

There are many ways to do it, and it partially depends upon how you define your restaurant (how do you know which restaurant the user is ordering from). Assuming you have the restaurant name or id in a variable $restaurant, then something like this:

Code: Select all

switch($restaurant) {
    case 'restaurant1':
        define('PAYPAL_EMAIL', 'info@restaurant1.com');
        break;
 
    case 'restaurant2':
        define('PAYPAL_EMAIL', 'info@restaurant2.com');
        break;
 
    //etc...
}
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
bigfoot_3000
Forum Newbie
Posts: 6
Joined: Tue Jan 26, 2010 6:44 am

Re: How to add multiple paypal accounts

Post by bigfoot_3000 »

Hi AbraCadaver,

It chooses the restaurant by selecting the City, then the Street then the restaurant and it has a restaurant id.

Ok, your example above is good, but what if I have 100's of restaurants (wow am I dreaming, but what if)? Can't go on doing that DEFINE on each one right.

I can place their PayPal email address somewhere in MySQL, in their restaurant details, but then will need to get the PayPal email address called up on each restaurant or maybe set up a new database on mysql just for PayPal email address for the restaurant id's (which sounds better) but then will need to call it up, any ideas on this.

Actually, I found this for when choosing the restaurant:

if ($_REQUEST['rid']) {
$rsr=getSqlRow("SELECT id,cityid,streetid FROM rests WHERE id=".remSpecialChars($_REQUEST['rid'])."");
$_SESSION['cityid']=$rsr['cityid'];
$_SESSION['streetid']=$rsr['streetid'];
$_SESSION['restid']=$rsr['id'];
}

- - - - - - - - - -

Below is what is within the Payment Type within the admin, where the restaurant owner can choose to set his the various payment methods via Credit Card, PayPal, Cash etc, but the PayPal at the moment only allows one restaurant to have it's PayPal email address, meaning that when I add a new restaurant - if they select PayPal payment method, it will go to the first restaurant's PayPal. Need to be able to allow Restaurant 2 (3, 4 etc, etc) to have their own PayPal email.

<?
include "check_login.php";
include "../config/conf.php";
include "../config/ajax_res.php";
require_once ("../js/xajax_core/xajax.inc.php");

$xajax = new xajax();
$xajax->registerFunction("Save_payment_types");
$xajax->configure('statusMessages',false);
$xajax->configure('waitCursor', false);
$xajax->processRequest();
>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Restaurant Admin</title>
<? include "styles.php";
$xajax->printJavascript($GLOBALS['mainpath']."js/"); ?>
</head>

<body>

<div class="wrapper">

<? include "header.php";
include "sub_home.php"; ?>

<div id="content">
<div id="container">
<br />
<h1 class="h1">Payment Types</h1>
<form id="myform" name="myform" method="post" action="javascript:void(null);">
<table width="400">
<tr>
<td width="90%" class="tdheader">Type</td>
<td width="10%" class="tdheader"></td>
</tr>
<?
$secenekler = getSqlField("SELECT paymenttypes FROM rests WHERE id=".$_SESSION['restaid']."","paymenttypes");
$getRs = mysql_query("SELECT * FROM paymenttypes order by paymenttype asc");
while ($rs = mysql_fetch_array($getRs)) {
$class=(($count++)%2==0)?"tda":"tdb";
?>
<tr>
<td class="<?=$class?>"><?=$rs['paymenttype'];?></td>
<td class="<?=$class?>"><input type="checkbox" name="ptype[]" id="ptype[]" value="<?=$rs['paymenttype'];?>" <? if (substr_count($secenekler,$rs['paymenttype']."|")>0) echo "checked"; ?>></td>
</tr>
<? } ?>
<tr>
<td><input type="submit" name="sbt" id="sbt" value="Save" style="font-size:16px;" onclick='this.disabled=true; xajax_Save_payment_types(xajax.getFormValues("myform")); return false;'></td>
<td></td>
</tr>
</table>

</form>
</div>
</div>

<div class="push"></div>
</div>
<div class="bottomfooter">

<? include "footer.php"; ?>
</div>

</body>
</html>

- - - - - - - - - -

Regards,

bigfoot_3000
Post Reply