Process of Making a Payment With Paypal
Now we have completed how to create and configure test accounts and configure the website payment settings. So lets move onto integrating paypal sandbox with our site. In this tutorial I am going to show you how the flow of a paypal payment using “Paypal Buy Now” buttons. This tutorial is used to learn the process of a payment. I’ll be covering several types of payment process like express checkout, recurring payments, subscriptions in future tutorials once we cover all the basics needed to handle paypal payments. So let’s start creating a Buy Now button.
You can find sample paypal button codes at Paypal Buttons. Copy the code for Buy Now button and change it as following.
<form name="_xclick" action="https://www.sandbox.paypal.com/webscr" method="post"> <input type="hidden" name="cmd" value="_xclick"> <input type="hidden" name="business" value="firstname.lastname@example.org"> <input type="hidden" name="currency_code" value="USD"> <input type="hidden" name="item_name" value="Teddy Bear"> <input type="hidden" name="return" value="http://www.innovativephp.com/demo/payapl-process/success.php"> <input type="hidden" name="amount" value="12.99"> <input type="image" src="http://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"> </form>
Form action – the code you copied contains paypal live site url as the action. Since we are still using the sandbox for testing, we need to change it as https://www.sandbox.paypal.com/webscr.
Return URL – we can set the url to return after finishing the paymet, by using the return hidden parameter. If this is not specified payment will redirect to the URL you have configured on Website Payment Preferences. In order to return url to work you need to set the status of auto return to on.
Business Email – Change the email address of business hidden parameter to your business email address.
Now we are ready to start the payment process. Following section contains the steps for making a paypal sandbox payment.
Insert the above code to your web page and load the web page. You will see a paypal button. Following code is a sample screen of how it will be displayed. In the sample i have added a html table to display the data for purchased item. If you insert the code only, you will get only the paypal button.
Now click the buy now button and you will be directed to the paypal payment screen as shown in the following screen.
After login you will be asked to Review your payment information as shown in the following screen. Click the Pay Now button once the review is complete.
Then you will be directed to Paypal Payment success page and in few seconds you will be redirected automatically to return url you have specified as shown in the following screen.
Now the payment is completed and you should take a look at the URL of the above screen. After the success.php it contains set of parameters and values returned from paypal. In order to validate the payment and save in our database we need to process these data. Next tutorial I will show you how to process paypal payment data using php curl library.