Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PayPal IPN 2

Status
Not open for further replies.

coldfused

Technical User
Jan 27, 2001
2,442
0
0
US
Can't get my IPN script to post back, or PayPal is not posting to my script "Verified".

Code:
<cfset x = GetHttpRequestData()>
<cfset str="cmd=_notify-validate&" & x.content>

<!-- POST BACK FOR VALIDATION -->
<cfhttp url="[URL unfurl="true"]https://www.paypal.com/cgi-bin/webscr?#str#"[/URL] method="get" resolveurl="false">

<CFIF #CFHTTP.FileContent# is "VERIFIED">
    <!-- check that payment_status=Completed -->
    <cfif FORM.payment_status eq "Completed">
    <!-- check that receiver_email is your email address -->
     <cfif #FORM.RECEIVER_EMAIL# eq "mypaypalemail@mysite.com">

<!-- Simplified for testing-->

<cfmail 
to="myemail@me.com"
from="myemail@me.com"
subject="Pay Pal Order ">

Success

</cfmail>

</cfif>
</cfif>
</cfif>

The form:
Code:
<cfset paypalAccount = "myemail@me.com">
<cfset returnURL = "[URL unfurl="true"]http://www.mywebsite/paymentthanks.cfm">[/URL]
<cfset cancelURL = "[URL unfurl="true"]http://www.mywebsite/canceledpayment.cfm">[/URL]
<!-- Loop Through Cart Session To Get Total -->
<cfset ordertotal = 0>
<cfloop from="1" to="#ArrayLen(Session.Cart.ProductID)#" index="ThisItem">
<cfquery name="getItem" datasource="#request.dsn#" username="#request.dsnUsername#" password="#request.dsnPassword#">
SELECT ProductPrice,ProductCatID,ProductID,ProductName FROM Products WHERE ProductID = '#Session.Cart.ProductID[ThisItem]#'
</cfquery>
<cfset total = 0>
<cfset total = total + (getItem.ProductPrice * Session.Cart.Qty[ThisItem]) >
<cfset ordertotal = ordertotal  + total>
</cfloop>
<!-- Find Member Id to submit to paypal as invoice -->
<cfquery name="getNewMemberID" datasource="#request.dsn#" username="#request.dsnUsername#" password="#request.dsnPassword#">
SELECT ID FROM Members WHERE ID = '#Session.InvoiceNumber#'
</cfquery>



<form action="[URL unfurl="true"]https://www.paypal.com/cgi-bin/webscr"[/URL] method="post">
<input type="hidden" name="cmd" value="_ext-enter" />
<input type="hidden" name="redirect_cmd" value="_xclick" />
<input type="hidden" name="business" value="<cfoutput>#paypalAccount#</cfoutput>" />
<input type="hidden" name="return" value="<cfoutput>#returnURL#</cfoutput>" />
<input type="hidden" name="cancel_return" value="<cfoutput>#cancelURL#</cfoutput>" />
<input type="hidden" name="item_name" value="Florida Council for the Social Studies Purchase" />
<input type="hidden" name="amount" value="<cfoutput>#DollarFormat(ordertotal)#</cfoutput>" />
<input type="hidden" name="no_shipping" value="1" />
<input type="hidden" name="no_note" value="1" />
<input type="hidden" name="invoice" value="<cfoutput>#getNewMemberID.ID#</cfoutput>" />
<input type="hidden" name="email" value="<cfoutput>#getNewMemberID.Email#</cfoutput>" />
<input type="hidden" name="notify_url" value="[URL unfurl="true"]http://www.fcss.org/gateway/paypal.cfm">[/URL] 
<input type="hidden" name="rm" value="1">
<input type="image" src="[URL unfurl="true"]https://www.paypal.com/en_US/i/btn/x-click-but5.gif"[/URL] border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!" />
</form>

The funny thing is if I remove:
Code:
<CFIF #CFHTTP.FileContent# is "VERIFIED">

The email comes through. Seems I just can't get the cfhttp to post back, or paypal is not posting back verified.

Does anyone see any problems? Any ideas? Has anyone gotten this to work?

I've been through PayPals script a 1000 times, paypal developer network script, easycfm.com's script. Im exausted and this is all I have left for this project to be complete ...

----------------------------------------
Florida Web Design
Orlando Web Hosting
Florida Coldfusion Hosting
 
try this:

Code:
<cfif find("verified", cfhttp.filecontent)>
 ...
<cfelse>
  <cfif isdefined("cfhttp.filecontent")>
    <cfdump var="#cfhhtp#">
  </cfif>
</cfif>

I do this when I need to know if "cfhttp.filecontent" is returning anything.

The <cfif find("verified", cfhttp.filecontent)> will find the value 'verified' in filecontent as oppose to equaling to that value (this is a better way to making sure the <cfif> works). And the <cfelse> just outputs the cfhttp vars (if any) onto the screen. If the email fails then this will output everything CF sees and you can then determine what the issue is.

[sub]
____________________________________
Just Imagine.
[sub]
 
For debugging purposes do this:

Code:
<cfset x = GetHttpRequestData()>
<cfset str="cmd=_notify-validate&" & x.content>

<!-- POST BACK FOR VALIDATION -->
<cfhttp url="[URL unfurl="true"]https://www.paypal.com/cgi-bin/webscr?#str#"[/URL] method="get" resolveurl="false">
	<!--- finds the 'VERIFIED' syntax anywhere in cfhttp.FileContent --->
	[COLOR=red]<cfif findnocase("VERIFIED", CFHTTP.FileContent)>[/color]
		<!-- check that payment_status=Completed -->
		<cfif FORM.payment_status eq "Completed">
			<!-- check that receiver_email is your email address -->
			<cfif #FORM.RECEIVER_EMAIL# eq "mypaypalemail@mysite.com">
				<!-- Simplified for testing-->
				<cfmail to="myemail@me.com" from="myemail@me.com" subject="Pay Pal Order ">
					Success
				</cfmail>
			</cfif>
		</cfif>
	[COLOR=red]<cfelse>
		<cfif isdefined("cfhttp.FileContent")>
			<cfdump var="#cfhttp#">
		</cfif>
		<!--- aborts here to display the cfhttp vars on the screen --->
		<cfabort>[/color]
	</cfif>

The point of this is to see what gets retruned in cfhttp. Your code is looking to see if CFHTTP.FileContent is equal to "VERIFIED". If cfhttp throws back anything else the if statement is fals, ergo the email didn't go out.

Try this to see what happens.

[sub]
____________________________________
Just Imagine.
[sub]
 
it's been a while since i've messed with paypal IPN but i think this page is triggered by Paypal doing an http request so it never shows in a browser. however if that's the case FORM.payment_status, and FORM.RECEIVER_EMAIL should be undefined and is probably where the page is erroring out not getting to the mail tag. but on any event instead of the code posted above try this
Code:
<cfset x = GetHttpRequestData()>
<cfset str="cmd=_notify-validate&" & x.content>

<!-- POST BACK FOR VALIDATION -->
<cfhttp url="[URL unfurl="true"]https://www.paypal.com/cgi-bin/webscr?#str#"[/URL] method="get" resolveurl="false">
    <!--- finds the 'VERIFIED' syntax anywhere in cfhttp.FileContent --->
    <cfif findnocase("VERIFIED", CFHTTP.FileContent)>
        <!-- check that payment_status=Completed -->
        <cfif FORM.payment_status eq "Completed">
            <!-- check that receiver_email is your email address -->
            <cfif #FORM.RECEIVER_EMAIL# eq "mypaypalemail@mysite.com">
                <!-- Simplified for testing-->
                <cfmail to="myemail@me.com" from="myemail@me.com" subject="Pay Pal Order ">
                    Success
                </cfmail>
            </cfif>
        </cfif>
    <cfelse>
        <cfif isdefined("cfhttp.FileContent")>
[COLOR=red]<cfmail to="myemail@me.com" from="myemail@me.com" subject="crap it's not working ">
            <cfdump var="#cfhttp#">
</cfmail>[/color]
        </cfif>
        <!--- aborts here to display the cfhttp vars on the screen --->
        <cfabort>
    </cfif>

that way when the page is called by paypal it will send you an emil with the cfdump in it so you can see what is being returned with cfhttp when "verified" can't be found.



Beware of programmers who carry screwdrivers.
 
SimulatedFun beat me to it. That was going to be my solution also. Don't know why (maybe I was at work and typed to quick and didn't check my post) but I always use the <cfmail> to mail me the <cfdump> vars (or any debugging info) so I know what's going on.

Anyways, let us know if this helped.

[sub]
____________________________________
Just Imagine.
[sub]
 
coldfused glad you got it working. You should write an FAQ on this. I see many posts asking how to set up CF with Paypal IPN.

[sub]
____________________________________
Just Imagine.
[sub]
 
coldfused, LOL. Use plain english to describe what you did and how it worked. That's what I do when I write all my tutorials.

SimulatedFun, I looked at that also when I did payapl, sadly that tutorial wasn't much help.

[sub]
____________________________________
Just Imagine.
[sub]
 
Yes, Thats what I started with but theres so much more that goes into it then what he explains. And he doesnt really explain much for someone like me who is learning as I go. I can tell you today though I have learned tons, and all hands on so what better way right.

So back and forth between that script, paypal developer network scripts, PayPAl Manual for the actual form itself and all the variables passed, etc.

Regardless one more thing under my belt.

I think for newbies there needs to be a better tutorial written so maybe I mught do that one day when I get time.

Just look here:


Not just me that couldnt figure it out, its a mess...

----------------------------------------
Florida Web Design
Orlando Web Hosting
Florida Coldfusion Hosting
 
I think i write some pretty good FAQ's try doing it like this to explain what you do.

faq232-5680

Beware of programmers who carry screwdrivers.
 
That's pretty much what I do also when I write tutorials. The main difference about write a tutorial and actually coding is: comments. A well-written tutorial (or application) should have as much comments as possible.

I wrote this faq232-3469 on how to do a login feature and I think it was worded nicely. :)

[sub]
____________________________________
Just Imagine.
[sub]
 
Would you please post the code for the IPN script. I had a working IPN script that looks very similiar to your original posting but now it isn't working. I am wondering if it had something to do with installing windows server 2003 service pack 1.

I am running coldfusion mx 6.1 w/ most receent updates.

I have been working on this all weekend and would greatly appreciate any help you could give me.

Thanks,

David
 
Here is a sample. When testing with eliteweaver's script it reports an HTTP 200 OK and then times out. It used to work fine.


<!---read post from PayPal system--->
<cfset x = GetHttpRequestData()>
<cfset str="cmd=_notify-validate&" & x.content>
<!---post back to PayPal for validation--->
<cfhttp url=" method="GET" resolveurl="no">
</cfhttp>

<!---check notification validation--->
<cfif #CFHTTP.FileContent# is "VERIFIED">
<!---check that payment_status=Completed--->
<cfif #FORM.payment_status# eq "Completed">
<!---check that txn_id has not been previously processed--->
<!---check that receiver_email is your Primary PayPal email--->
<cfif #FORM.receiver_email# eq "#application.email#">

</cfif>
</cfif>
</cfif>
 
Hi, I am also having some problems when setting up my IPN with Paypal. Any ideas on how to do this?
Thanks.
 
Lanmansolutions have you tried your script live and not through eliteweaver? Eliteweaver gave me the same problems and kept timing out, after a while I gave up and tested it live after exausting all possibilities and knowing that the code was right. And guess what, it worked fine. Eliteweaver's script wasted 6 hours of my life that i'll never get back.

I experienced a couple more problems when I started testing live but they were with my actual form, not the IPN.

Try it live and see what happens, if not then we can look more into it. At first glance the script looks fine.

Wannalearn do you have code you tried as well? Or just need a general idea how to get started?

----------------------------------------
Florida Web Design
Orlando Web Hosting
Florida Coldfusion Hosting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top