Home arrow PHP arrow Page 2 - Creating a PHP PayPal Instant Payment Notification Script

Adding a Bank and Credit Card - PHP

This is an important tutorial on the use of PHP in the implementation of PayPal IPN (Instant Payment notification) system on your website. There are many advantages to using this system on your site. If you're ready to put the power of PayPal to work for you, keep reading.

TABLE OF CONTENTS:
  1. Creating a PHP PayPal Instant Payment Notification Script
  2. Adding a Bank and Credit Card
By: Codex-M
Rating: starstarstarstarstar / 7
January 10, 2011

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

You will notice that the account was created successfully, although it failed to add a bank and credit card. To correct this issue, click "Enter Sandbox Test site." Use the login email and password generated earlier.

1. Go to "Profile" -> "Add or Edit Bank account" -> Select "Checking." PayPal Sandbox will auto-populate the routing and account number fields, except for the "Bank name."

2. Enter a fictitious bank name, for example "Codex Bank." Then click "Continue."

3. You will be asked to confirm deposits. Just enter a small amount, like 0.55 and 0.75, and then click "Submit."

4. If you see the message "Bank account confirmed," click "Continue."

5. Now to add a fictitious credit card. Click "Back to Profile Summary," and then go to "Profile" -> "Add or Edit Credit Card."

6. Some fields are populated automatically (like the credit card number and the billing address). Others, such as the expiration date, aren't. For the "Expiration Date" field, you need to set a valid date which will expire in the future -- December 2016, for example. Also, with the "card verification number" field, you might need to change the default 000 to something else, such as 123.

7. Finally, click "Add Card."

8. Log out of your Test buyer account in Sandbox. When you go back to "Test Account," you will notice that the personal account is now "Verified" because you have added a bank account and a credit card number.

9. To add a "seller" account type (which you will use to represent yourself as the merchant), click "Preconfigured," and then, under "Create a Sandbox Test account," make sure you have selected "Seller" under "Account Type."

10. Follow the rest of the instructions, which will be very similar to creating a "Buyer" account type. Take note of the generated passwords and email address, because you will be using this to log in to the seller PayPal Sandbox test site.

Finally, you should have at least one test seller (business) and one test buyer (personal) account in your PayPal Sandbox.

To use these accounts when testing an IPN PHP web application in Sandbox mode:

  1. Generate "Buy Now" buttons by logging in to the PayPal Sandbox seller account (by selecting seller account under "Test accounts" and then clicking "Enter Sandbox Test site").

  2. You can test purchase products in your website using the generated "Buy Now" button using the sandbox buyer account. After you click the "Buy Now" button, you will be diverted to the PayPal Sandbox checkout process (http://www.sandbox.paypal.com/), and then you'll use the buyer sandbox account to pay for your product purchase.

  3. You can configure your selling preferences (such as IPN settings, etc) in Sandbox by using the test seller account.
     

Integrating PayPal IPN into Your Website Checkout Flow

Suppose you have a website that sells ebooks. You decided to let customers use PayPal to pay you. You can use IPN to validate downloading of ebooks by customers that have completed their payments to you in PayPal.

Details on the PayPal IPN standard can be read here: https://cms.paypal.com/cgi-bin/marketingweb?cmd=_render-content&content_ID=developer/e_howto_admin_IPNIntro

Below is the typical implementation flowchart showing the integration of PayPal IPN into a website:

As you can see, it all starts when a visitor to your website is shopping for items you are offering for sale. When the visitor wants to buy a certain item, they click on the PayPal Buy Now buttons, which will take the visitor to PayPal for payment.

As usual, using website payments standard allows customers to pay you using a credit card or their remaining PayPal balance.

Running in the transaction's background simultaneously (indicated by yellow arrows), the PayPal transaction triggers PayPal's servers to send an IPN message targeted to the IPN PHP script you have added to your PayPal account.

Once your script receives the message from PayPal, it is required to reply, to confirm receipt of IPN communication.

Once your PHP script can provide a reply to PayPal, it will reply with the status of the IPN transaction, which is either VERIFIED or INVALID.

The information posted to your PHP script from PayPal contains a lot of data pertaining to your customer and the transaction. That includes your email address, the payment amount, payment currency, payment status, item number, etc.

Your script should validate all of this information to make sure none of it is spoofed. Once validated, the PHP script will save all of the information to a MySQL database on your website.
 
On the other side of the transaction (from the customer's end, shown in green arrows), the customer will receive a payment receipt by email from PayPal.

This payment receipt email contains the transaction ID as well as other important details, such as the invoice number. The customer will be diverted to a download page on your website after successful payment, and click the "Click here to download your ebook" button in PayPal.

To make sure only verified and paid customers can download the ebook, the customer will enter the invoice number of the transaction, which will be used by the PHP script to fetch the corresponding IPN information saved in the MySQL database.

If the invoice number, as well as other information, is valid, PHP will stream the ebook to the customer for downloading. The PHP script should then update the customer information in the database, indicating that the transaction is complete and the customer has already downloaded the material. This will prevent duplicate transactions.



 
 
>>> More PHP Articles          >>> More By Codex-M
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: