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 strongm 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
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
 
Damn Eliteweaver!!!

I took off the closing </cfhttp> tag and tested it live with PayPal and what do you know it worked.

You are a wonderful person.

Posted below is my IPN script in it's entirety for enyone who wants to see a known working script...

<!---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">

<!---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.email3#">

<!---process payment--->
<cftry>
<cfquery name="postOrder" datasource="#application.datasource#">
INSERT INTO orders(
item_name,
quantity,
payment_date,
mc_gross,
mc_fee,
first_name,
last_name,
address_street,
address_city,
address_state,
address_zip,
address_country,
payer_email
)
VALUES(
'#FORM.item_name#',
'#FORM.quantity#',
#CreateODBCDateTime(Now())#,
'#FORM.mc_gross#',
'#FORM.mc_fee#',
'#FORM.first_name#',
'#FORM.last_name#',
'#FORM.address_street#',
'#FORM.address_city#',
'#FORM.address_state#',
'#FORM.address_zip#',
'#FORM.address_country#',
'#FORM.payer_email#'
)
</cfquery>
<cfcatch>
<!---log error inserting order--->
<cffile action="append" file="C:\CFusionMX\logs\lifesaversfoundation\paypal.log" output="ERROR INSERTING ORDER">
</cfcatch>
</cftry>

<cftry>
<!---send email thanking customer for purchase--->
<cfmail to="#FORM.payer_email#" from="#application.email3#" subject="Your LifeSavers Foundation Purchase" type="HTML">
Thank you for your generosity!
<br>
<br>
Item Purchased : #FORM.item_name#
<br>
Purchase Price : #DOLLARFORMAT(FORM.mc_gross)#
<br>
<br>
If you have questions or concerns please submit feedback :
<br>
<a href="<br>
<br>
Thanks again for your generosity!
<br>
The LifeSavers Foundation
<br>
</cfmail>
<!---send email alerting that sale was completed--->
<cfmail to="#application.email#" from="#application.email3#" subject="LifeSavers Foundation Website Purchase" type="HTML">
An order was placed by: #FORM.first_name# #FORM.last_name#
<br>
<br>
Item Purchased : #FORM.item_name#
<br>
Purchase Price : #DOLLARFORMAT(FORM.mc_gross)#
<br>
PayPal Fee : #DollarFORMAT(FORM.mc_fee)#
<hr>
Profit : #DollarFormat(Evaluate("#FORM.mc_gross# - #FORM.mc_fee#"))#
<br>
<br>
Login to view transaction details :
<br>
<a href="</cfmail>
<cfcatch>
<!---log error sending email--->
<cffile action="append" file="C:\CFusionMX\logs\lifesaversfoundation\paypal.log" output="ERROR SENDING EMAIL">
</cfcatch>
</cftry>
</cfif>
</cfif>
</cfif>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top