Skip to content

Coldfusion based paypal IPN Integration

November 6, 2007

Paypal IPN integration :-

Please follow the steps below

  1. Get a Paypal business account after signing up with paypal
  2. Login to your paypal account
  3. click on profile tab
  4. click on Instant Payment Notification Preferences under Selling Preferences
  5. Enter the Instant Payment Notification (IPN) URL . ie, http://www.yourwebsitedomain.com/ipn.cfm. Dont worry about IPN.CFM now , we can work out that script later. So now you gave the Instant Payment Notification (IPN) URL and turn ON the Instant Payment Notification (IPN). Back to profile summary
  6. Now click on Website Payment Preferences again under Selling Preferences

Turn on Auto Return

Give the same URL http://www.yourwebsitedomain.com/ipn.cfm for Return URL.

Turn on Payment Data Transfer -> On

Also turn on PayPal Account Optional:

Click Save and that’s it.

7. (optional step) this step is for people who are conscious about beauty.

Click on Custom Payment Pages under Selling Preferences and customize

your PayPal’s payment page by adding header URL, background color and border color of the header.

8. Lets move on to real code- CheckOut form

This will be the checkout form of your shopping cart.

Please replace with your information which are marked in bold

<cfoutput>

<form action=” https://www.paypal.com/cgi-bin/webscr&#8221; method=”post”>

<input type=”hidden” name=”cmd” value=”_xclick”>

<!— put your paypal business account here—>

<input type=”hidden” name=”business” value=”shimjudavid@gmail.com“>

<!— put the list of products in the cart between value. You can dynamically populate your values here —>

<input type=”hidden” name=”item_name” value=”product1, product2, product3“>

<!— put the order_id here. You can dynamically populate your order id here —>

<input type=”hidden” name=”item_number” value=”1000“>

<!— put the currency code here —>

<input type=”hidden” name=”currency_code” value=”USD“>

<!— put the total amount of your cart which includes tax and shipping here —>

<input type=”hidden” name=”amount” value=”#DollarFormat(val(variables.total_cost))#“>

<!— this is the controller page which does the logic if payment is success or failure —>

<input type=”hidden” name=”return” value=”http://www.yourwebsite.com/checkout_controller.cfm“>

<input type=”hidden” name=”cancel_return”

value=”http:// http://www.yourwebsite.com /checkout_failure.cfm“>

<input type=”image” border=”0″ src=”paypal_logo.gif” name=”submit”

alt=”Make payments with PayPal – it’s fast, free and secure!”>

</form>

</cfoutput>

9) ipn.cfm

Copy paste this code and save it to directory which you mentioned on paypal IPN URL.

<cfif IsDefined(“FieldNames”)>

<!– read post from PayPal system and add ‘cmd’ –>

<cfset str = “cmd=_notify-validate” />

<cfloop index=”TheField” list=”#FORM.FieldNames#”>

<cfset str = str & “&#LCase(TheField)#=#URLEncodedFormat(Evaluate(TheField))#” />

</cfloop>

<cfif IsDefined(“FORM.payment_date”)>

<cfset str = str & “&payment_date=#URLEncodedFormat(FORM.payment_date)#” />

</cfif>

<cfif IsDefined(“FORM.subscr_date”)>

<cfset str = str & “&subscr_date=#URLEncodedFormat(FORM.subscr_date)#” />

</CFIF>

<!– post back to PayPal system to validate –>

<CFHTTP URL=”https://www.sandbox.paypal.com/cgi-bin/webscr?#str#&#8221; METHOD=”GET” RESOLVEURL=”FALSE” />

<!– check notification validation –>

<cfif CFHTTP.FileContent IS “VERIFIED”>

<!– check that payment_status=Completed –>

<cfif FORM.payment_status IS “Completed”>

<!– check that receiver_email is your email address –>

<cfif FORM.receiver_email IS “<!—enter email —>”>

<cftry>

<cfcatch type=”any”><!— /home/fsb/logs/paypal_error.log —>

<cffile action=”append” file=”paypal_error.log” output=”Error #Now()#: #cfcatch.Detail#” /><!— ,#str# —>

</cfcatch>

</cftry>

</cfif>

</cfif>

</cfif>

<cfelse>

<cflocation url=”<!— Enter URL —>” addtoken=”no”/>

</cfif>

10)checkout_controller.cfm

<!— comes from paypal as success —>

Url scope : <cfdump var=”#url#”><br>

<cfif isdefined(“URL.ST”) AND URL.ST EQ “Completed” AND isdefined(“URL.item_number”) >

<cfquery name=”updateOrder” datasource=”#REQUEST.dsn#”>

UPDATE testorder

SET order_status = 1

WHERE orderNumber = ‘#URL.item_number#’

</cfquery>

<cflocation addtoken=”yes” url=”checkout_success.cfm?order_id=#URL.item_number#”>

<cfelse>

<cflocation addtoken=”no” url=”checkout_failure.cfm”>

</cfif>

11) checkout_failure.cfm

Display page, if payment is unsuccessful

<p align=”center” class=”error”>Your payment is not successfully processed.</p>

<p align=”center” class=”error”>We sincerely apologize for the inconveniences caused hereby.</p>

12)Checkout_success.cfm

Display page, if payment is successful

<cfoutput>

<p align=”center” class=”error”>Your payment is successfully processed.</p>

<p align=”center” class=”error”>Your Order Number is #url.order_id#</p>

</cfoutput>

 

About these ads
11 Comments leave one →
  1. Jared permalink
    November 6, 2007 3:17 pm

    Cool!! this is what I am looking for last 2 days!!

  2. alhaimy permalink
    November 6, 2007 5:08 pm

    HI FREIND

    YOU HAVE DONE A NICE WORK

    COME AND VISIT MY OWN SITE
    http://CHARMINGWOMEN.GOOGLEPAGES.COM

  3. July 14, 2008 6:11 pm

    Can this technique be used for PayPal Flowpro?

    Thanks.

  4. wazzy permalink
    April 3, 2009 3:20 pm

    hi
    The content above is Excellent and it has sloved all my problem, thanks for the good content.

    thanks………

  5. Robert Daniel permalink
    April 4, 2009 8:15 am

    Very Helpful. Thanks’

  6. ROCK permalink
    August 19, 2009 1:13 am

    OMG!!! You’re a life saver.
    Thanks sooo much for makin’ this tutorial.
    Seconds to install. Instant Success!!

  7. Gaby permalink
    March 7, 2010 5:36 am

    YES !
    Exactly copied, instantly runned !
    Thanks so much for your nice tutorial.
    Already surfed like crazy before …
    Merci, merci et merci encore…

  8. May 13, 2010 1:04 am

    Do you know if this code is still valid in 2010? I’ve been trying for the longest time to get this same exact logic to PayPal using their IPN and webpayments standard plan but I always get a http 500 response error on paypal side, as if I did not complete this ipn handshaking process. I have a feeling they require now cfhttp to post instead of a ‘get’.

  9. Tom permalink
    May 25, 2010 9:04 pm

    I ‘m trying to use the return URL i.e “checkout_controller.cfm” but there are no variables coming from Paypal when Paypal calls the return page after payment…

    In this example it says that variables “URL.ST” and “URL.item_number” are coming from Paypal. Can somebody confirm that this is still the case?
    Thanks

  10. September 15, 2012 8:56 pm

    My brother recommended I might like this website.

    He was entirely right. This post truly made
    my day. You can not imagine just how much time I had spent
    for this info! Thanks!

  11. July 18, 2013 5:34 am

    Do not look at investing in the stock market as a hobby.
    It is something that has a lot of risk involved and
    it should be taken very seriously. If you do not have enough time,
    effort and patience to take it seriously, then you should
    not get yourself involved with it.
    __________________________________________________________________________

    I really Love google stock picks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: