|
|
|
Rank: Starting Member
Groups: Registered
Joined: 6/17/2005 Posts: 1 Location: ,
|
PayPal IPN is very hard to crack indeed. This code is working!!!
Before you start, I think there is a problem in general with the way various versions of coldfusion decodes and encodes strings. Writer Pablo's code for instance is not working for me because when you examine the encoded string, there are characters missing/ changed/ moved which causes the PayPal verification to fail!
The code below worked for me. Thought I'd share it for those who struggled like I did. Good luck and let me know what you think.
<!--------------------------------------------------------------------------------------------------
Remember, this is not a graphic interface - The IPN.CFM file should run in the background. It is only
an interface between PayPal and your transaction complete, invalid or error steps.
--------------------------------------------------------------------------------------------------->
<cfset x = GetHttpRequestData()>
<cfset str="cmd=_notify-validate&" & x.content>
<!---post back to PayPal for validation--->
<cfhttp url="https://www.paypal.com/cgi-bin/webscr?#str#" method="GET" resolveurl="no">
</cfhttp>
<!--------------------------------------------------------------------------------------------------
Use the following to test your IPN.CFM file - The idea is to record the PayPal encoded and hidden
'message string' as posted by PayPal apon completion of each transaction. I record the message to
a .txt file called IPN_log.txt - Make sure you change the path to the relative path of your own web
direcory on the server.
--------------------------------------------------------------------------------------------------->
<cffile action="append"
file="d:\yourWebDirectory\IPN_log.txt"
output="
-------------------------------------------------------------
Paypal Says the transaction is: #CFHTTP.FileContent#
Transaction status: #FORM.payment_status#
Seller account: #FORM.RECEIVER_EMAIL#
-------------------------------------------------------------
"
addnewline="yes">
<CFLOOP INDEX="TheField" list="#Form.FieldNames#">
<CFSET str = str & "#LCase(TheField)#=#URLEncodedFormat(Form[TheField])#">
<cffile action="append"
file="d:\yourWebDirectory\IPN_log.txt"
output="#LCase(TheField)#---->#(Form[TheField])#"
addnewline="yes">
</CFLOOP>
<!--- Payment verified --->
<CFIF #CFHTTP.FileContent# is "VERIFIED">
<!-- check that payment_status=Completed -->
<cfif #FORM.payment_status# eq "Completed">
<!-- check that receiver_email is your email address (that money went into your account -->
<cfif #FORM.RECEIVER_EMAIL# eq "name@email.com">
Paypal says the funds went into your account<br>
<!-- Everything checked ok, add your action here (typically you would want to update your
database here -->
</cfif>
</cfif>
<CFELSEIF #CFHTTP.FileContent# is "INVALID">
<!-- The information is not valid, please investigate and trace invalid info -->
Invalid Info<br>
<!---Something that was purchased was invalid, either the order or the information provided. This is usually good to log in case someone is trying to purchase with stolen card numbers, etc. Here simply place a QUERY tag that insert the data above into a database.--->
<CFELSE>
<!-- ERROR -->
<!---This usually means that something went wrong along the way, you can use this area to log it and keep for your records.--->
</CFIF>
|
|
|
|
|
|
|
|
|
Rank: Starting Member
Groups: Registered
Joined: 12/23/2005 Posts: 2 Location: ,
|
This code is fantastic and does the trick, however is anyone experiencing a similar problem to me??
From my development server i submit to paypal, click the return to merchant button, or the cancel button, and go back to my site and the log is created and i also catch this in the database.
However when i test this from my live site to exactly the same paypal url the paypal site behaves differently.
Instead of a return to merchant button or cancel button, i get an anchor link to go back (or a -this site will redirect in 10 seconds) rather than a button, which means the form variables arent defined when i get back to my site, and the script fails?
What is going on,.. is there anyway to ensure the return to merchant and continue links (after a cancel) on paypals site are buttons so form.variablename are defined.
I know i can do the if not is defined, but i need to capture the important values!
Many Thanks in advance
Dave
|
|
|
|
Rank: Starting Member
Groups: Registered
Joined: 12/19/2005 Posts: 15 Location: ,
|
You can set the return url but not aware of a redirect variable that affects the button. Why don't you set a variable on the return url so as to pick up the session, if that's what you're doing? Let the ipn enter it in the db. Hey, have you tried your script with this test page: http://www.eliteweaver.co.uk/testing/ipntest.php
I always get an "invalid" response and think it must be their server. Can you point your script there and try and let me know?
|
|
|
|
Rank: Starting Member
Groups: Registered
Joined: 2/10/2006 Posts: 2 Location: ,
|
THANK YOU SO MUCH FOR POSTING THIS CODE! :) :)
I have been banging my head against my desk and just about pulled every strand of hair from my head for the past few weeks trying every suggestion in this forum.
You are awesome!!
|
|
|
|
Rank: Starting Member
Groups: Registered
Joined: 3/25/2006 Posts: 2 Location: ,
|
Hey! I have been trying for so long now to find some code to use Paypal IPN with Multi-Item Transactions. I can only get 1 item to go into my DB and not (for example) 3 items. I am willing to pay, or donate to anyone who can help me get code to make this work with Multi-Item Transactions. Basically when someone buys 3 items at a time on my site, I want to log them all in my DB, and not just one (prefered 1 per row in the table) Please contact me Sirseth@sympatico.caThanks! Jamie St. Pierre Sirseth Sirseth
|
|
|
|
Rank: Starting Member
Groups: Registered
Joined: 5/3/2006 Posts: 3 Location: ,
|
I just changed my ipn.cfm file to the code listed in this post and the code is not posting back to paypal. I am using the following link to test the code: http://www.eliteweaver.co.uk/testing/ipntest.php
Can anyone please help me with this? I have been trying to figure this out for 2 weeks and posting all over the place, but no one has the solution or posting the solution. I need some help Please!
|
|
|
|
Guest
|
YAFVision Theme by Jaben Cargman (Tiny Gecko)Powered by YAF |
YAF © 2003-2009, Yet Another Forum.NETThis page was generated in 0.467 seconds.