If you've ever wanted to have a shopping cart solution that works in REAL time, but didn't want to (or couldn't) get a merchant account, your alternative is PayPal. PayPal is the leading money processing site on the web, with millions of transactions each day! A short time ago, PayPal introduced Instant Payment Notification ("IPN") which allowed vendors the ability to sell products from their web sites and then update their databases in real time when customers checked out. Let me warn you that using PayPal's IPN system is a tough thing to do, it's not as easy as they make it appear. In order to make this task less difficult I decided to write a tutorial on how to implement it for your website. This is probably the only tutorial online showing you how to implement the PayPal IPN, as most people would rather have you pay them to implement it for you! So let's begin with the tutorial.

The first thing you will need to do is to get a FREE PayPal account. Now keep in mind that to accept payments you will have to put a credit card and a bank account on record. This is good for you (if you're like me, you will want to get the Paypal MasterCard Debit Card which allows you to access your Paypal funds instantly through MasterCard). Once you have those steps in place, the next thing is to begin your IPN modifications. That will be the first part of this tutorial.

Go to www.paypal.com

Log into your account and then click on the "Sell" tab on the upper right hand corner:

Next click on the Instant Payment Notification link:

Then click on the Technical Overview section:

Next you will click on the link titled "Start Using IPN".

Then click on the "EDIT" button:

Now you will need to enter two values:
1) Make sure this is "checked".
2) Enter the URL to the file that you will create in this tutorial, it's usually recommended you place it in the CART folder under the name ipn.cfm.
3) Click the Save Button.

Note: Click the "read the instructions" link above the "SAVE" button for further information.

That's it, you have now enabled PayPal's IPN and are ready to use it! Now I'll show you the back-end code you'll need to begin accessing real time payments.

The first thing you need to understand is that PayPal will send you information to the link you place above (The file you will now create) as POST form submission. That data will be available for you to do as you wish.... this tutorial will demonstrate how you use that data to finalize an order and allow the customer to download the software they've purchased.

The first thing you need to do is to create a string with values you will pass back to PayPal for verification.

<!-- read post from PayPal system and add 'cmd' -->
<CFSET str="cmd=_notify-validate">
<CFLOOP INDEX="TheField" list="#Form.FieldNames#">
    <CFSET str = str &
<CFIF IsDefined(
    <CFSET str = str &
<CFIF IsDefined(
    <CFSET str = str &

Next we will post that information back to PayPal to verify that this is a VALID order and that the values we have are correct.
<!-- post back to PayPal system to validate -->
<CFHTTP URL="https://www.paypal.com/cgi-bin/webscr?#str#" METHOD="GET" RESOLVEURL="false">

<!-- check notification validation -->
<CFIF #CFHTTP.FileContent# is
    <!-- check that payment_status=Completed -->
    <cfif FORM.payment_status eq "Completed">
    <!-- check that receiver_email is your email address -->
    <cfif #FORM.RECEIVER_EMAIL# eq "mypaypalemail@mysite.com">
        <!-- process payment -->

            <cfquery name="qInsertOrder" datasource="MyDSN">
                INSERT INTO Orders(

        <!--- let's log all errors --->
        <cffile action="append"
"Error order info">

Now let's generate a password for this customer, this will be used to allow them to download their software, you can also (as shown) generate serial numbers for their software at this step, to make sure that they get a serial number when registering their software!

    <cfset password = #Evaluate("#RandRange(1,10000)# * #RandRange(1,10000)#")#>
    <cfset serial_number =
        <cfquery name=
"qInsertCustomer" datasource="YourDSN">
                    INSERT INTO Customers(

              <!--- log any errors when inserting this customer --->
            <cffile action="append"
"Error inserting customer">

Now send the customer an email, thanking them for their order and with further information about their purchase:
    <!--- send user an email --->
        <cfmail from=
"you@yoursite.com" to="#FORM.payer_email#" subject="MySite.Com Software Purchase!">
            Thank you for purchasing software from MySite.Com

            You may download your software by going to:

            Your username is: #payer_email#
            Your password is: #password#

            If you have questions or need help, please go to:

            Thanks again for your purchase!
            MySite.Com, Inc.
     <!--- Now send yourself an email alerting that there was a sale done --->
     <cfmail from="me@mysite.com" to="me@mysite.com" subject="Someone Purchased From The Website!">
      An order was placed by: #FORM.first_name#' #FORM.last_name#

        Item Purchased:
        Item Number: #FORM.ITEM_NUMBER#
        PayPal Fee: #DollarFORMAT(FORM.PAYMENT_FEE)#
        Profit Fee: #DollarFormat(Evaluate("#FORM.PAYMENT_GROSS# - #FORM.PAYMENT_FEE#"))#

        A Reminder Email:

        <!--- Log Any Errors Sending Emails --->
        <cffile action="append"
"Error sending email">

    <!-- log for investigation -->

     Something that was purchased was invalid, either the order or the information provided. This is usually good to log in case someone is trying to purchase with stolen card numbers, etc. Here simply place a QUERY tag that insert the data above into a database.

   <!-- error -->

    This usually means that something went wrong along the way, you can use this area to log it and keep for your records.


That's pretty much it, with this tutorial you can now begin taking instant credit card payments via PayPal securely and process the orders on the fly! Something that was purchased was invalid, either the order or the information provided. This is usually good to log in case someone is trying to purchase with stolen card numbers, etc. Here simply place a QUERY tag that insert the data above into a database. What's the exact procedure of placing the QUERY tag from Paypal IPN message so that it inserts the data into a database? Great many thanks Radek

  • For all those who suffer Try this it worked for me!!! I tried to make it as simple as possible Paypal says the funds went into your account
    Invalid Info

  • Advertisement

    Sponsored By...
    Mobile App Development (IOS, Android, Cordova, Phonegap, Objective-C, Java) - Austin, Texas Mobile Apps - Touch512, LLC.