[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1090
  • Last Modified:

Coldfusion - Paypal

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
Panos
Asked:
Panos
  • 5
  • 3
2 Solutions
 
Gurpreet Singh RandhawaWeb DeveloperCommented:
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
 
PanosAuthor Commented:
Hi myselfrandhawa
I have to configure my dyndns account to check this.
I will come back as soon as i can.
0
 
PanosAuthor Commented:
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
_agx_Commented:
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
 
PanosAuthor Commented:
Hi agx.
Can you a better tutorial using ipn?
0
 
_agx_Commented:
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
 
_agx_Commented:
>> MUST better

Haha... I fat fingered that one.  I meant, it: looks MUCH better   ;-)
0
 
PanosAuthor Commented:
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
 
PanosAuthor Commented:
Thank you
regards
panos
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now