Pages

Tuesday, 10 December 2013

How to integrate paypal by php

Paypal is the most used online payment gateway in the world. It is secured for both buyer and seller. So, for online transaction both buyers and sellers like to use it. But how PayPal gateway is integrated in web? A lot of tutorials are available in online. I will discuss here about the easiest way to integrate.

I will use PHP language for integrate it.

First Step: Create a Form

Keep the information of product items that you want to sell in a form. It is just a html form tag (<form>). Below is an example of a form:

<form action="https://www.paypal.com/cgi-bin/webscr" method="POST">

<input type="hidden" name="cmd" value="_xclick" />
<input type="hidden" name="business" value="nurulsnit@gmail.com">
<input type="hidden" name="item_name" id="item_name" value="My Product" />           
<input type="hidden" name="currency_code" value="USD" />
<input type="hidden" name="amount" value="10" />

<input type="submit" value="Buy Now"  />

</form>

Explanation of the above code:
Form action = https://www.paypal.com/cgi-bin/webscr. It is live paypal link. If you want to test the payment you can use sandbox paypal link. ( Sandbox is a test mode of paypal, in next post i will discuss about sandbox ).

Sandbox form action will be = https://www.sandbox.paypal.com/cgi-bin/webscr

<input type="hidden" name="cmd" value="_xclick" />, it is an essential variable for paypal transaction. This is a hidden type variable which name is cmd and value = _xclick.

business variable contains your paypal business account mail address. In this paypal account the payment will send. It is the seller paypal id.
item_name is the product name which is selling or purchasing.
currency_code is the currency name of transaction.
amount is the product price amount.
        

No comments:

Post a Comment