Coldfusion - Paypal

Posted on 2010-11-16
Medium Priority
Last Modified: 2012-08-14
Hello experts.
I'm looking for a tutorial to use coldfusion with paypal and the ipn.cfm from paypal :https://www.paypal.com/us/cgi-bin/webscr?cmd=p/pdn/ipn-codesamples-pop-outside(code below).
i include the form i submit to paypal (from another tutorial that returns to a checkout_controller.cfm)
and the ipn.cfm that i want to use.
Any help to make this full working?

<CFSET variables.total_cost = 0.30>

<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="mycode">

<!--- 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">

<!--- 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="EUR">

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

<input type="hidden" name="amount" value="#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://mydomain/paypal/checkout_controller.cfm">

<input type="hidden" name="cancel_return" value="http://mydomain/paypal/checkout_failure.cfm">

<!--- <input  type="submit"  border="0" src="paypal_logo.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"> --->
<input type="hidden" name="lc" value="GR">
<input type="hidden" name="button_subtype" value="services">
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted">
<input type="image"  src="https://www.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">


<!-- 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(Form[TheField])#">
<CFIF IsDefined("FORM.payment_date")>
<CFSET str = str & "&payment_date=#URLEncodedFormat(Form.payment_date)#">
<CFIF IsDefined("FORM.subscr_date")>
<CFSET str = str & "&subscr_date=#URLEncodedFormat(Form.subscr_date)#">
<CFIF IsDefined("FORM.auction_closing_date")>
<CFSET str = str & "&subscr_date=#URLEncodedFormat(Form.auction_closing_date)#">
<!-- post back to PayPal system to validate -->
<CFHTTP URL="https://www.paypal.com/cgi-bin/webscr?#str#" METHOD="GET" RESOLVEURL="false">
<!-- assign posted variables to local variables -->
<CFSET item_name=FORM.item_name>
<CFSET payment_status=FORM.payment_status>
<CFSET payment_amount=FORM.mc_gross>
<CFSET payment_currency=FORM.mc_currency>
<CFSET txn_id=FORM.txn_id>
<CFSET receiver_email=FORM.receiver_email>
<CFSET payer_email=FORM.payer_email>
<CFIF IsDefined("FORM.item_number")>
<CFSET item_number=FORM.item_number>
<!-- check notification validation -->
<CFIF #CFHTTP.FileContent# is "VERIFIED">
<!-- check that payment_status=Completed -->
<!-- check that txn_id has not been previously processed -->
<!-- check that receiver_email is your Primary PayPal email -->
<!-- check that payment_amount/payment_currency are correct -->
<!-- process payment -->
<!-- log for investigation -->
<!-- error -->

<!--- 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#'


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


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


Open in new window

Question by:Panos
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
LVL 16

Accepted Solution

Gurpreet Singh Randhawa earned 1000 total points
ID: 34152391
Have you tested your code, is it working or not!

If make sure if you are using paypal for the very first time go for the sandbox account or developer account of paypal. Then do the same code for that testing and see if your transaction works.

A very tutorial for IPN can be found @ the following CFm Site!


Author Comment

ID: 34153042
Hi myselfrandhawa
I have to configure my dyndns account to check this.
I will come back as soon as i can.

Author Comment

ID: 34166243
Hi,here i'mback
I solved my dyndns problems,created a test buyer and test seller account in paypal sandbox.
I created a table orders with the fields in the link you posted.
I have now ipn succssfull sended.
but i don't get the values in my database.Any help?
<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))#" />


    <cfif IsDefined("FORM.payment_date")>

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


    <cfif IsDefined("FORM.subscr_date")>

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


    <!--- 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 "seller_1290102322_biz@gmail.com">

              <cfquery name="qInsertOrder" datasource="#request.dsn#">
                INSERT INTO Orders(

          <cfcatch type="any"><!--- /home/fsb/logs/paypal_error.log --->

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







   <cflocation  url="../../index.cfm" addtoken="no"/>


Open in new window

How To Reduce Deployment Times With Pre-Baked AMIs

Even if we can't include all the files in the base image, we can sometimes include some of the larger files that we would otherwise have to download, and we can also sometimes remove the most time-consuming steps. This can help a lot with reducing deployment times.

LVL 52

Expert Comment

ID: 34170065
but i don't get the values in my database.Any help?

Is the CFIF block running at all?

tutorial to use coldfusion with paypal and the ipn.cfm from paypal

Side note - I'd be careful following that example.. It looks like whoever wrote it doesn't know much about CF.

Author Comment

ID: 34170270
Hi agx.
Can you a better tutorial using ipn?
LVL 52

Assisted Solution

_agx_ earned 1000 total points
ID: 34170645
If you're comfortable with cfc's - this one looks MUST better. Disclaimer, I haven't used it myself.
LVL 52

Expert Comment

ID: 34170650
>> MUST better

Haha... I fat fingered that one.  I meant, it: looks MUCH better   ;-)

Author Comment

ID: 34179978
Hi again.I did not forget you.I was testing and testing........
Agx i did not get it work with the cfc's.
there are two ways to handle this.
1)Storing a transaction values in a table with a column f.e payment_status 0 (for not completed).
After that submit a form to paypal with information to the transaction.There will be a ipn check and If transaction is completed than update the payment_status column to 1.
2)The second way is to store the transaction after submiting the form to paypal and catching all the values during the ipn.cfm call from paypal,like the example from myselfrandhawa.

I don't know wich is the best way but i think the first one gives more possibilities.
Thank you for your help.


Author Closing Comment

ID: 34179979
Thank you

Featured Post

Not sure which OpenStack Certification to get?

So you’ve realized you might want to get certified in OpenStack, but you’re not sure what the benefits might be or even which one you should take. You know there are several certification courses you can choose from, but how do you know which one is right for you?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question