how to use php dynamic Variables in paypal form - php

I want to use dynamic variabels in the form , I try to use like this
<input type="hidden" name="first_name" value=<?php echo $firstname ?> />
bu its not working, is there a anyway to use dynamic variable ?
my point with this a when user login on my site and click the paypal button all those values gona be writen on paypal form .
$sql = mysql_query("SELECT * FROM members WHERE id=' $userid' LIMIT 1");
while($row = mysql_fetch_array($sql)) {
$firstname = $row['firstname'];
$lastname = $row['lastname'];`
}
$pp_checkout_btn .= '<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post"><input type="hidden" name="cmd" value="_cart"><input type="hidden" name="upload" value="1"><input type="hidden" name="business" value="xxxxxxx#xxx.xx">
<input type="hidden" name="first_name"value=<?php echo $firstname ;?> />
<input type="hidden" name="last_name" value=<?php echo $lastname ;?> />
.........</form>';

the only "custom" variable I believe that you can send using the paypal form is a variable named "custom" which will store a string for you.
from your question it looks like you want to pre-fill information for the user on the paypal site. in that case, there are form elements you can set for that. see here: https://www.paypal.com/cgi-bin/webscr?cmd=_pdn_xclick_prepopulate_outside
if you want to confirm payment on your site, and do something after payment is confirmed, you need to set up an IPN ( https://www.paypal.com/ipn ) on your site, which paypal will notify once it's confirmed.

Related

Paypal return a variable issue

I'm have an issue with Paypal, i'm using a simple form :
<html>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="boukhersya#gmail.com">
<input type="hidden" name="item_name" value="DEMANDE D ETUDE PERSONNALISEE">
<input type='hidden' name='rm' value='2'>
<input type="hidden" name="amount" id=val value="79">
<input type="hidden" name="currency_code" value="EUR">
<input type="hidden" name="bn" value="PP-BuyNowBF">
<input type="hidden" name="notify_url" value= "http://<?php echo $_SERVER['SERVER_NAME'];?>/etude-gratuite.php" >
<input type="hidden" name="cancel_return" value="http://<?php echo $_SERVER['SERVER_NAME'];?>/etude-personalisee/test.php">
<input type="hidden" name="return" value="http://<?php echo $_SERVER['SERVER_NAME'];?>/etude-personalisee/paimentconfirme.php">
<input type="submit" value="Payer votre commande">
</form>
I want to return the email used in the payment, so i can know which user has paid
so i can get the email in the page test.php, can i do that with PDT ??
You can pass the field "custom" to pyapal and it will pass it back to you when the transaction is completed. You may want to use your user ID rather than an email address though.
<input type="hidden" name="custom" value="email#address.com">
https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables/
The way it works is: you use these hidden input values on for your paypal button. When the user is transferred to paypal all of these values are sent with it. One of the values you use is name="notify_url" when the user completes checkout paypal posts the checkout information to that url. In the case of php you do something like this:
$useremail = $_POST['custom']
Any custom information you want to have returned to you needs to go in the custom field. I use some kind of delimiter if I want more pieces of information returned, like this:
<input type="hidden" name="custom" value="user#email.com-firstname-userID">
Then you just explode the data:
$paypalvars = explode("-", $_POST['custom']);
$email = $paypalvars[0];
$firstName = $paypalvars[1];
$userID = $paypalvars[2];
Whatever value is in the custom filed will be posted back to your notify_url exactly the same way you give it to paypal.
You could use the Paypal IPN API to handle this.
Simply set up IPN within your Paypal account and then create a file which will manage the data that gets sent back upon payment.
This includes their email address too!
Note that the <input type="hidden" name="notify_url"> should be the input used to direct to test.php because at the moment, the information that will get passed back to you will be sent to the etude-gratuite.php

Generating paypal buttons for other users dynamically

I am planning on letting people list and sell their items on my site with payment/transaction processing done via paypal. To do this, i plan on letting my users dynamically generate a paypal button of their own when they are uploading their items(using my upload form).
I know that i can generate paypal buttons for my own account simply by logging into my paypal account. However, how would i go about doing this for other people ( if possible), whose accounts i will not have access to, and how would i make it secure?
Inputs would be appreciated!
P.S Im coding the site in php
If I understand the question correctly, you want to have your users customize a PayPal button to their own needs, right?
If so, what you should do is store the user's email address and the image button they want to use in a database (like MySQL) and then retrieve it and print the HTML.
Here's an example:
$query = mysql_query("SELECT * FROM `users`, `items` WHERE users.id = items.user_id") or die(mysql_error());
while($row = mysql_fetch_array($query)) {
?>
<form name="_xclick" action="https://www.paypal.com/us/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="<?php echo $row['email']; ?>">
<input type="hidden" name="currency_code" value="<?php echo $row['currency']; ?>">
<input type="hidden" name="item_name" value="<?php echo $row['item_name']; ?>">
<input type="hidden" name="amount" value="<?php echo $row['price']; ?>">
<input type="image" src="<?php echo $row['button_image']; ?>" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
<?php } ?>
Here is some very brief documentation from PayPal on it.

customizing paypal checkout, including php variable

I'm trying to add a "custom" value to the 3rd party checkout PayPal option. The problem I'm having is the PHP variable is being displayed on the screen. I'm passing the shopping cart values in a session variable.
if(isset($_SESSION['checkout'])){
$orderData = '<table border="1"><th style="width:80px">Item</th>
<th sytle="width:250px">Size</th>
<th style="width:60px">Quantity</th>';
for ($i=0; $i<count($_SESSION['checkout']); $i++){
$orderData .= '<tr><td style="text-align:center">'.$_SESSION['checkout'][$i][0].'</td><td style="text-align:center">'.$_SESSION['checkout'][$i][1].'</td><td style="text-align:center">'.$_SESSION['checkout'][$i][2].'</td></tr>';
}
}
I want that table to be passed along, and based on the PayPal documentation, all I need to do is include it. I'm echoing out the PayPal form like this:
echo '<form>
//other hidden values
<input type="hidden" name="custom" value="'.$orderData.'">
//input submit button here
</form>
And like I said, the input is supposed to be hidden, but it gets displayed before the PayPal button. How come?
UPDATE: Those code passes the amount perfectly:
<input type="hidden" name="amount" value="';?><?php if(isset($_SESSION['disc'])){print_r($_SESSION['disc']);}?><?php echo '">
It doesn't display on the page but the variable amount is correct in the page source.
UPDATE2: Here's my entire cart script:
echo '<div style="position:absolute; left:770px; top:50px">
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="myemail#example.com">
<input type="hidden" name="item_name" value="Merchandise">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="no_shipping" value="0">
<input type="hidden" name="custom" value="'.$orderData.'">
<input type="hidden" name="return" value="backtomywebsite.com">
<input type="hidden" name="cancel_return" value="backtomywebsite.com">
<input type="hidden" name="amount" value="';?><?php if(isset($_SESSION[$disc])){print_r($_SESSION[$disc]);}?><?php echo '">
<input type="image" src="http://www.mywebsite.com/images/BuyNow.png" name="submit" alt="Make payments with PayPal - it\'s fast, free and secure!" width="300" height="204">
</form>
</div>';
The script works when instead of $orderData I have a print_r session with the item information. That information gets sent to my paypal account but it is in an array form and looks ugly. If there was a way to make everything (member information, order information) into a php variable and pass it into the custom field, that would be great. Anyway...here's what is on the screen:
Hope you're still willing to help me out.
What do you mean it gets displayed before the PayPal button? If you are viewing the source code of the page, you will see the value in the page.
If you are saying you are passing amount over, but are not seeing it you may be using the wrong variable. The variable amount is a valid PayPal variable but depending what button you are specifically using the amount varialbe is slightly different. I could not tell from your code as I didn't see what you were passing over for "cmd", but if you are using a buy now button or an add to cart button that the variable "amount" would be the correct variable to use. If you are usnig the cart upload method, then you want to use the variable "amount_x". So if I passed two items over, and the first one was 0.99 and the second was 1.99 I would pass over the variable/value of "amount_1=0.99" and "amount_2=1.99".

How to get value back from Paypal?

I am facing this problem from last month. First i was able to get value back from paypal.
Now I am not able to get back value from paypal.
I am using following code.
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" style="padding: 0; margin: 0;">
<input type="hidden" name="cmd" value="_xclick/" />
<input type="hidden" name="business" value="my_bussiness_id" />
<input type="hidden" name="quantity" value="1" />
<input type="hidden" name="item_name" value="item" />
<input type="hidden" name="item_number" value="1" />
<input type="hidden" name="amount" value="item_price" />
<input type="hidden" name="shipping" value="0" />
<input type="hidden" name="no_note" value="1" />
<input type="hidden" name="notify_url" value="Your_notify_url">
<input type="hidden" name="currency_code" value="GBP" />
<input type="hidden" name="rm" value="2" >
<input type="hidden" name="return" value="your return url">
<input type="image" border="0" name="paypal" src="images/btn_paypal_nl.gif" onClick="" />
</form>
Thanks in advance..
Kanji
There's actually two methods of getting the data back--a return URL that posts upon completion with return values (I've not been terribly lucky making that work) then a separate function that sends you a post upon completion of a transaction to a separate page on your site, where you can collect back all the variables you posted to the site. I suggest the latter because on a buy it now page there's a possibility of the user not being returned to the site because the return button UI is pretty weak on PayPal's end.
To set it up you'd log in to your PayPal account, click on myaccount > profile > website payment preferences. Enabling the "payment data transfer" will do the trick. Once you've got it setup correctly, upon completion of a transaction it'll send to the page of your choice a post of everything you sent it....remember, you can send in variables such as Name, Address, etc just by defining them properly in the form. All the variables available are found here
Don't forget to build a sandbox site to test! Good Luck.
What I have normally done is this:
You see where you got notify_url as a hidden tag, use that for paypal to send you information about the transaction.
The url you put down should be a file on your server that will then do some logic, i.e. update your database that everything was ok, send out notification email of order, etc, etc
When paypal talks to this page, altho cant see the process, everything is sent via $_POST.
What I do as a test is i loop thru the $_POST array and send myself an email so I know what values have been posted back to me.
//paypal variables
$message = "<h1>Paypal variables</h1>";
foreach($_POST as $key => $value)
{
$message.= $key . " - " . $value . "<br />";
}
Link below gives you more info.
https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_admin_IPNIntro

paypal and Php?

I have two ways to check from user:
1.if user input (Amount field < 5(user credit):
do update database the remain amount in my database table.
2.if user input(Amount field) > 5(user credit):
Do paypal transaction with the submit form.
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" id="payPalForm">
<input type="hidden" name="item_number" value="01 - General Payment to FreelanceSwitch.com">
<input name="item_name" type="hidden" id="item_name" size="45" value="Posting job">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="business" value="seller_1265789181_biz#xxx.xxx.xx">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="return" value="http://freelanceswitch.com/payment-complete/">
Paying Page:<input name="amount" type="text" id="amount" size="5">
<input type="submit" name="Submit" value="Pay">
</form>
Anybody could tell me how to do with the paypal submit form with the conditions.?
thanks.
Thanks #Donny Kurnia ,now I have tried:
EDIT::
function compare_user_credit($paying_price, $user_credit){
$db = &JFactory::getDBO();
$user =& JFactory::getUser();
$user_id = $user->get('id');
if ($paying_price <= $user_credit) {
$remain_credit = $user_credit - $paying_price;
//DO UPDATE:enough credit
update_user_credit_after_paying($remain_credit,$user_id);
$action_after_paying = header("Location: index.php?xxxx=5");
}
# Case2 direct to paypal with the submit form.
else if ($paying_price > $user_credit){
//Need submit form to paypal.
$action_after_paying = header("Location: index.php=xxxx&paypal=".$_POST["amount"]);
}
return $action_after_paying;
}
$output = '<form method="POST" > ';
$output .='<h1>Credit:'.get_credit().'</h1>';
$output .= ' Paying Page <input type="text" name="amount" size=3 max_length=5 />';
$output .='<input type="submit" name="pay" value="pay" />' ;
echo $output;
if(isset($_POST["pay"])){
compare_user_credit($_POST["amount"], $user_credit);
}
HOw Could I do with Paypal in Case 02.(direct to paypal with submit form.)
Maybe you can receive the form submit to your own code and then check it's value. If it satisfy the first condition, do the database update. If it satisfy the second condition, redirect the user to a page that have hidden form that will submit to paypal. You can populate the data in this hidden form using data from database or previous form input, and put a javascript code so the form will automatically submitted when the page is loaded.
In my code, I use Micah Carrick's Paypal IPN class to send data to paypal. The class have a sample code on how to display the hidden form, with a submit button in case the javascript is disabled.

Categories