Paypal is an online platform that allows one to send and receive money, pay and receive payments. It is the most popular online payment platform accepting most of the debit and credit cards.
When you want to create a website, app or software that would allow people to make payment to you, paypal becomes the most favorable option. However, for you to be able to accomplish this, you need to know a bit of programming and working with paypal objects.
Every paypal activity involves sending requests to paypal and receiving responses which determine the next course of action. This can be accomplished in any programming language that allows communication with a web server. Also, paypal has integration apis for most popular platforms and there are also many open source APIs as well.
What is a request? probably you already know that by now. You may also be aware that there are two types of requests either POST or GET request. Within a request, you set the variables and assign them some data value. I'll assume you already know web programming and if you don't, be sure to check out various tutorials for your favorite language coming soon on this site and also millions of other tutorial sites such as W3CSchools, php.net, msdn, tutorials point among others. Don't forget to seek assistance at stackoverlow and codeproject. Good luck. For now, I'd like you introduce you to several variables that need to be set within a paypal request.
To start off, you need a paypal account which you can create here: Create a free Paypal Account
Next you need to create a form to post data to paypal. We are going to post the data using POST method. The location of the server where we need to post data is https://www.paypal.com/cgi-bin/webscr.
So let us start and create a form to post data to paypal. I will use PHP but you can use any language of your choice. I could use ASP.NET with C# or VB.NET but I think PHP will allow many developers to be able to adapt the code to alot of platforms including codeigniter, joomla, Yii, CakePHP,symfomy etc although I intend to also do an example for each. With time i will add an example in ASP.NET. Let's create a form in html.
<form action="https://www.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="yourpaypalemail@yourhost.com">
<input type="hidden" name="item_name_1" value=""your item name>
<input type="hidden" name="amount_1" value="' 200">
<input type="hidden" name="quantity_1" value="10">
<input type="hidden" name="custom" value="'array_of_your_products">
<input type="hidden" name="notify_url" value="https://www.yoursite.com/notify_url.php">
<input type="hidden" name="return" value="https://www.yoursite.com/paymentcompleted.php">
<input type="hidden" name="rm" value="2">
<input type="hidden" name="cbt" value="Return to The Store">
<input type="hidden" name="cancel_return" value="https://www.yoursite.com/cancel_transaction.php">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="currency_code" value="USD">
<input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but01.gif" name="submit" alt="Make payments with PayPal - its fast, free and secure!">
</form>
having created the form, our task now is to populate it with data from our store. This will obviously be fetched from a database. all the variables that need to be set are in bold in the form above.
Now the fun part starts. Making a query from your database: Of course, in an actual application, you would get this data from a session in a shopping cart ( see PHP Shopping Cart Tutorial). But for demostration purposes, lets fetch our items directly for the database.
Connecting to database
<?php
$database_host = "localhost"; //most servers can allow you to use localhost while others require the //actual server eg mysql.host.com
$database_user = "root"; // default user. can be any user you create and give permissions
$database_password = ""; // default is blank but some servers and for security you should use one
$database_name = "name_of_database_here";
mysql_connect($database_host ,$database_user,$database_password ) or die ("error connecting to database server");
mysql_select_db($database_name ) or die ("database not found");
?>
Fetch data from database
<?php
$query = mysql_query("SELECT * FROM products") ; // assuming your products are in a table called products;
$products =array();
while($row = mysql_fetch_array($query)){
$product['name']= $row["name"];
$product["quantity"] = $row["quantity"];
$product['"price'] = $row["price"];
array_push($products,$product);
}
?>
Populate our form
<form action="https://www.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="yourpaypalemail@yourhost.com">
<?php
$x=0;
foreach($products as $p){
'<input type="hidden" name="item_name_'.$x.'" value="'.$p["name"].'">
<input type="hidden" name="amount_'.$x.'" value="'.$p["price"].'">
<input type="hidden" name="quantity_'.$x.'" value="'.$p["quantity"].'">';
$x+=1;
}
?>
<input type="hidden" name="custom" value="'array_of_your_products">
<input type="hidden" name="notify_url" value="https://www.yoursite.com/notify_url.php">
<input type="hidden" name="return" value="https://www.yoursite.com/paymentcompleted.php">
<input type="hidden" name="rm" value="2">
<input type="hidden" name="cbt" value="Return to The Store">
<input type="hidden" name="cancel_return" value="https://www.yoursite.com/cancel_transaction.php">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="currency_code" value="USD">
<input type="image"
src="http://www.paypal.com/en_US/i/btn/x-click-but01.gif" name="submit"
alt="Make payments with PayPal - its fast, free and secure!">
</form>
0 comments :
Post a Comment