?
Solved

Coldfusion - Paypal

Posted on 2010-11-16
9
Medium Priority
?
1,078 Views
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?


checkform.cfm:
<CFSET variables.total_cost = 0.30>
<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="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">
</form>

</cfoutput>

ipn.cfm
<!-- 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])#">
</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>
<CFIF IsDefined("FORM.auction_closing_date")>
<CFSET str = str & "&subscr_date=#URLEncodedFormat(Form.auction_closing_date)#">
</CFIF>
<!-- post back to PayPal system to validate -->
<CFHTTP URL="https://www.paypal.com/cgi-bin/webscr?#str#" METHOD="GET" RESOLVEURL="false">
</CFHTTP>
<!-- 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>
</CFIF>
<!-- 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 -->
<CFELSEIF #CFHTTP.FileContent# is "INVALID">
<!-- log for investigation -->
<CFELSE>
<!-- error -->
</CFIF>

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>

Open in new window

0
Comment
Question by:Panos
[X]
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
9 Comments
 
LVL 16

Accepted Solution

by:
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!

http://tutorial23.easycfm.com/
0
 
LVL 2

Author Comment

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

Author Comment

by:Panos
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))#" />

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

          <cftry>
              <cfquery name="qInsertOrder" datasource="#request.dsn#">
                INSERT INTO Orders(
                                        receiver_email,
                                        item_number,
                                        quantity,
                                        payment_status,
                                        payment_date,
                                        payment_gross,
                                        payment_fee,
                                        txn_id,
                                        txn_type,
                                        payment_type,
                                        payer_id
                                        )
                              VALUES(
                                        '#FORM.RECEIVER_EMAIL#',
                                        '#FORM.ITEM_NUMBER#',
                                        '#FORM.QUANTITY#',
                                        '#FORM.PAYMENT_STATUS#',
                                        #CreateODBCDateTime(Now())#,
                                        '#FORM.PAYMENT_GROSS#',
                                        '#FORM.PAYMENT_FEE#',
                                        '#FORM.TXN_ID#',
                                        '#FORM.TXN_TYPE#',
                                        '#FORM.PAYMENT_TYPE#',
                                        '#FORM.PAYER_ID#'
                                        )
               </cfquery>

          <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="../../index.cfm" addtoken="no"/>

</cfif>

Open in new window

0
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

by:_agx_
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.
0
 
LVL 2

Author Comment

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

Assisted Solution

by:_agx_
_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.
http://www.dougboude.com/blog/1/2009/11/PayPal-IPN-Coldfusion-CFC.cfm
0
 
LVL 52

Expert Comment

by:_agx_
ID: 34170650
>> MUST better

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

Author Comment

by:Panos
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.


0
 
LVL 2

Author Closing Comment

by:Panos
ID: 34179979
Thank you
regards
panos
0

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