Solved

Coldfusion - Paypal

Posted on 2010-11-16
9
1,052 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 15

Accepted Solution

by:
myselfrandhawa 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 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

17 Experts available now in Live!

Get 1:1 Help Now