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.
Related
This is my first time trying to integrate paypal into a wordpress site - so I might need a bit of hand holding. I'm building a custom plugin for a client where the admin creates booking forms for events and assigns them to users. The user can then log in and see their assigned booking forms and fill them out. Once filled out, the user can then pay the price of their booking.
Let say the user has filled out their booking form and is now ready to pay for their booking, they click on "pay" and are taken to a payment page (www.yoursite.com/deposit/?booking-id=xxx) which is essentially just a message and a pay button and hidden form fields for paypal. Here is the php for that page:
<?php
$paypal_url='https://www.sandbox.paypal.com/cgi-bin'; //
$paypal_id='malik#thedistractionsband.co.uk'; // Business email ID
$booking_form_id = get_query_var( 'booking-id' );
$current_user = wp_get_current_user();
?>
<?php
// The Query
$bookings_query = new WP_Query(
array(
'post_type' => 'bookings',
'p' => $booking_form_id
)
);
// The Loop
if ( $bookings_query->have_posts() ) {
while ( $bookings_query->have_posts() ) {
$bookings_query->the_post();
?>
<h2>Pay Deposit</h2>
<p>Hello <?php echo $current_user->display_name; ?> blah blah blah</p>
// Paypal form
<form action="<?php echo $paypal_url; ?>" method="post" name="frmPayPal1">
<?php
$total_amount = get_post_meta( $bookings_query->post->ID, 'wedding_price', true );
$deposit_amount = $total_amount*0.2;
?>
<input type="hidden" name="business" value="<?php echo $paypal_id; ?>">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="item_name" value="<?php echo get_post_meta( $bookings_query->post->ID, 'wedding_name', true ); ?> - 20% Deposit">
<input type="hidden" name="item_number" value="DISTR<?php echo $booking_form_id; ?>">
<input type="hidden" name="credits" value="510">
<input type="hidden" name="userid" value="<?php echo $current_user->ID; ?>">
<input type="hidden" name="amount" value="<?php echo $deposit_amount; ?>">
<input type="hidden" name="cpp_header_image" value="http://www.thedistractionsband.co.uk/files/2015/08/LOGO-1.1-1024x304.png">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="handling" value="0">
<input type="hidden" name="cancel_return" value="<?php echo get_site_url()."/payment-cancel/"; ?>">
<input type="hidden" name="return" value="<?php echo get_site_url()."/my-bookings/"; ?>">
<input name="notify_url" value="<?php echo DISTRACTIONS_LOGIN_PLUGIN_URL ?>includes/payments/paypal-ipn.php" type="hidden">
<input type="submit" border="0" name="submit" value="Pay Now" alt="PayPal - The safer, easier way to pay online!">
<div class="cards"><i class="fa fa-cc-amex"></i> <i class="fa fa-cc-mastercard"></i> <i class="fa fa-cc-visa"></i> <i class="fa fa-credit-card"></i> <i class="fa fa-cc-paypal"></i></div>
</form>
<?php
}
/* Restore original Post Data */
wp_reset_postdata();
} else {
echo '<p>No bookings found</p>';
}
?>
This all works fine, and actually payments go through fine. I'm now trying to work on the paypal-ipn.php file which is where I want to create communications with paypal and add an entry to the post_meta database table when payment is successful.
So far I don't have much, but here is my paypal-ipn.php
<?php
global $wpdb;
update_post_meta(52, 'deposit_paid', 1);
?>
I'm hoping that this would update deposit_paid to '1' (for post_id 52 - which I will dynamically change to the booking that has been paid for....once I've got this working).
Currently it does nothing, Am I doing something wrong here?
You have a few options here - the easiest (as its just a php page) is to add the following:
// Make wordpress functions available - so we can write to the db etc
require_once realpath('/wp-load.php');
With the correct relative path to the wp-load.php file (its in the root of WordPress).
You need this to enable the functions and get update_post_meta(); to work etc...
When developing you should have:
define('WP_DEBUG', true);
Set up in your wp-config.php as this will alert you to problems.
Option #2 is to make a function and hook the into a WordPress hook when the user submits the form. This is more complex and I feel not what you are after.
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
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.
hi there Iam creating a Paypal IPN and i have a pay now button in my cart page which is of type image. Im used to using type submit. i was just wondering how i would write to my database on the submition of this pay now button. what i mean is i want to write to the database as this button is clicked but im not sure exactly how to do it? here is my code for sending my data to paypal.
<?php
if(isset($_SESSION['username']) && isset($_SESSION['itemnames']))
{
$checkoutbutton .='<form action="https://www.sandbox.paypal.com/cgibin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="xxxxxx">
<input type="hidden" name="upload" value="1">';
?> <ul2>
<?php
for ($i = 0;$i <count($_SESSION['itemnames']);$i++)
{ ?>
<li>
<?php
$x = $i + 1;
echo "<h3>";
echo $_SESSION['itemnames'][$i];
echo "</h3>";
echo "<b>Cost per Item: €" .$_SESSION['price'][$i] ."</br> Number of Items: " . $_SESSION['quantity'][$i] ."</b>";
$checkoutbutton .='<input type="hidden" name="item_name_'.$x.'" value="'. $_SESSION['itemnames'][$i] .'">
<input type="hidden" name="amount_'.$x.'" value="' .$_SESSION['price'][$i] . '">
<input type="hidden" name="quantity_'.$x.'" value="' .$_SESSION['quantity'][$i] . '">';
?>
</li>
<?php } $checkoutbutton .='<input type="hidden" name="notify_url" value="http://ipnscript.php">
<input type="hidden" name="return" value="http://ranscomplete.php">
<input type="hidden" name="rm" value="2">
<input type="hidden" name="cbt" value="return to store">
<input type="hidden" name="cancel_return" value="http://www.theislandapp.com/transcancelled.php">
<input type="hidden" name="currency_code" value="EUR">
<input type="image" src="x-click-but5.gif" name="submit" alt="Make payments with PayPal - its fast, free and secure!">';
?>
</ul2>
<?php }
else {?>
<h2> No Items in cart </h2>
<?php } ?> </br></br>
You'll need to add a step before heading to PayPal. Basically your cart would POST to another script on your site, which would log whatever info you need, and then you can loop through your cart and send things over to PayPal via a GET string on the URL. I believe the variables are the same, plus you can even get their name and address info to store on your side beforehand.
You could always use ajax(jquery) to call a page in the background, it doesn't even have to display any data.
$.post("save.php", { name: "John", item: "143" } );
http://api.jquery.com/jQuery.post/
By giving your buy button an id, and using click function would make this possible.
<input id="yebeclicked" type="image" src="x-click-but5.gif" name="submit" alt="Make payments with PayPal - its fast, free and secure!">
<script type="text/javascript">
$("#yebeclicked").click(function() {
$.post("save.php", { name: "John", item: "143" } );
});
</script>
Cheers. ;)
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