Solved

Coldfusion - Paypal

Posted on 2010-11-16
9
1,056 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
  • 5
  • 3
9 Comments
 
LVL 16

Accepted Solution

by:
Gurpreet Singh Randhawa earned 250 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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 250 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
404 Error after upgrading from Coldfusion 9 to Coldfusion 11 2 153
Coldfusion update database with CFLOOP 5 64
CSS HELP 6 87
Application.cfc - what is the order of events? 4 29
The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

816 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now