ColdFusion Community

The online ColdFusion / CFML community website

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, 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 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” 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:// 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#” 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 = <cfqueryparam cfsqltype="cf_sql_integer" value="#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>

Add a Comment

You need to be a member of ColdFusion Community to add comments!

Join ColdFusion Community

Nick Tong Comment by Nick Tong on December 11, 2007 at 10:46pm
Very useful David, thanks
Specialists in ColdFusion Development

> Place your advert here <


Latest Activity

Justin Mclean and Emma Morris are now friends
1 hour ago
pk added 5 discussions
20 hours ago
pk updated their profile
20 hours ago
M. Taake updated their profile
yesterday
on Sunday
I think it is because Coldfusion isn't viewed as a good development language. The people making decisions hear .NET, Java, or PHP... so coldfusion isn't really looked from a management point of view. What they don't seem to understand is that it is…
on Thursday
M. Taake added a discussion
The company I currently work for are wanting to convert from Coldfusion / Oracle to Sharepoint / MSSQL.  I was wondering if anyone had any thoughts on this?   Also, how hard will it be for me to get use to .Net?
on Thursday
John Gagliarid updated their profile photo
on Thursday
John Gagliarid is now a member of ColdFusion Community
on Thursday
Jim Priest added an event
NCDevCon at College of Textiles - NC State University
May 22, 2010 to May 23, 2010
The Triangle Area ColdFusion User's Group (TACFUG), associates, and sponsors are organizing the NCDevCon 2010 Conference (NCDevCon) to be held May 22-23, 2010 on the Centennial Campus of NC State University in Raleigh, North Carolina. The conferenc…
March 2
This group is a place to see some of the latest CF open source projects.
March 2
Nikhil Saxena added a discussion to the group CFTwitter
Dear All,   Hope all of you are doing good. I am working as a soft. eng. in a Organigation. we purchase a Imagecroping tool It is working with 32 bit OS perfectly but after some time we move on 64 bit OS with CF 9.0 we are not able to register it. S…
March 2

Members

  • Justin Mclean
  • Rick Turner
  • pk
  • Vishnuprasad
  • M. Taake
  • Richard Reece
  • Kjeld
  • Erik-Jan Jaquet
  • Matt Gifford AKA coldfumonkeh
  • Will Wilson
  • Gary Blinth
  • dickbob

Translate this page

© 2010   Created by Nick Tong

Badges  |  Report an Issue  |  Privacy  |  Terms of Service

Sign in to chat!