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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IPN woes-paypal, not writing to database

Status
Not open for further replies.

radiance

Programmer
Jan 4, 2003
164
US
Hello.

I posted this to the paypal developer board, but have not gotten much of a response and I am in a serious bind. I am hoping someone can shed some light as to why my ipn is not writing to the database. Is it possible that my coldfusion code is incorrect? I have used paypal's ipn for other applications, notably my donations, but for the products (in which one value is passed), I am getting no success.

Ultimately, users are registering online for a few of the forms, or they are registering and purchasing meals. I have conditions set on the confirm.cfm page, which results in one total variable- often regisAmt which is passed for the totalAmount and then the other variables are just the meals. Is this still considered a shopping cart?

how exactly is a test page set up for the ipn? in my confirm.cfm page, am I placing additional line there???

I testing using Paypal's online tutorial to test the ipn. But, I am not sure what I should be looking. I
I got the following data for the test-ipn.cfm, but this still does not write to the database :

======Begin OUTPUT FROM ipn-test.cfm======
variables: 32.00, Tester, B

status is VERIFIED
status is COMPLETED
email is CORRECT

But nothing was written to the db. I tried this for my test form live (minus the ipn-test.cfm) and It did not Work.

What am I doing wrong?? I could not write to a log .txt file. Nothing was inserted.

=============================
REVISED CODE:

CONFIRMATION PAGE- confirm.cfm
=============================
<!--- Confirm Form Variables --->
<cfset SESSION.prefix = FORM.prefix>
<cfset SESSION.fname = FORM.fname>
<cfset SESSION.lname = FORM.lname>
<cfset SESSION.stno = FORM.stno>
<cfif IsDefined("FORM.stno2") is "true">
<cfset SESSION.stno2 = FORM.stno2>
<cfelse>
<cfset SESSION.stno2 = "">
</cfif>
<cfset SESSION.city = FORM.city>
<cfset SESSION.state = FORM.state>
<cfset SESSION.zip = FORM.zip>
<cfset SESSION.email = FORM.email>
<cfset SESSION.Comments = FORM.Comments>
<cfset SESSION.Total=FORM.Total>

<!--- Variable Output --->
<table cellpadding="3" cellspacing="2" border="0" align="center">
<tr><td class="heading4"><br><br>Tour of Winterthur Registration Confirmation<br><span class="boldtext">Senior Housing Conference 2004</span><br><br></td></tr>
<tr><td class="boldtext">You entered the following information:<br><br></td></tr>

<cfoutput>
<tr>
<Td class="text">
<b>Prefix:</b> #SESSION.prefix#<br><br>
<b>First Name:</b> #SESSION.fname#<br><br>
<b>Last Name:</b>#SESSION.lname#<br><br>
<b>Address:</b>#SESSION.stno#<br><br>
<b>Address 2:</b>#SESSION.stno2#<br><br>
<b>City:</b>#SESSION.city#<br><br>
<b>State:</b>#SESSION.state#<br><br>
<b>Zip:</b>#SESSION.zip#<br><br>
<b>Email:</b>#SESSION.email#<br><br>
<b>Number of Participants:</b>#SESSION.Total#<br><br>
<b>Guest Names:</b>#SESSION.Comments#<br><br>
</td></tr>
<!--- </table> --->
</cfoutput>

<!--- Final Output of Total Costs --->
<cfquery name="CalculateRegis" datasource="#application.dsn#">
SELECT * FROM Products
WHERE ProductID='2'
</cfquery>

<!--- <table cellpadding="2" cellspacing="2"> --->
<tr><td class="text">

<span class="boldtext">
<u>Total Cost of Tour:</u></span><br>

<cfparam name="form.regisAmt" default="">
<cfoutput>
<cfset regisAmt = (Total * CalculateRegis.Price)>

<b>#DOLLARFORMAT(regisAmt)#</b><br><br>
</td></tr>
<tr><td class="iboldtext">If this information is incorrect, select "back button" to edit, then resubmit. </td></tr>
<!--- </table> --->

<tr><td>

<!---
<form action="tourForm.cfm" method="post">
<input type="hidden" name="mode" value="cancel">
<input type="submit" value="Go Back & Edit">
</form> --->


<form action=" method="post">
<input type="hidden" name="item_name" value="Tour of WinterThur - October 2004">
<input type="hidden" name="cmd" value="_ext-enter">
<!--- <input type="hidden" name="redirect_cmd" value="_cart"> --->
<input type="hidden" name="redirect_cmd" value="_xclick">
<input type="hidden" name="business" value="website@bnaibrith.org">
<input type="hidden" name="amount" value="#DOLLARFORMAT(regisAmt)#">
<input type="hidden" name="first_name" value="#SESSION.fname#">
<input type="hidden" name="last_name" value="#SESSION.lname#">
<input type="hidden" name="payer_email" value="#SESSION.email#">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="tax" value="0">
<!--- <input type="hidden" name="return" value="<input type="hidden" name="return" value="<input type="hidden" name="return" value="<input type="hidden" name="add" value="1">
<input type="hidden" name="notify_url" value="<input type="submit" value="Confirm">
</form></td></tr></table>
</cfoutput>


=============================
REVISED IPN
=============================

<!-- read post from PayPal system and add 'cmd' -->
<cfset x = GetHttpRequestData()>
<CFSET str="cmd=_notify-validate&" & x.content>

<!--- post back to PayPal system to validate --->
<CFHTTP URL=" METHOD="GET" RESOLVEURL="false">
</CFHTTP>

<!-- assign posted variables to local variables -->
<cfoutput>
<cfset payment_status=FORM.payment_status>
<cfset payment_currency=FORM.mc_currency>
<cfset txn_id=FORM.txn_id>
<cfset receiver_email=FORM.receiver_email>
<cfset regisAmt = FORM.mc_gross>
<!--- <cfset #Program# = #FORM.item_name#> --->
<cfset fname = FORM.first_name>
<cfset lname = FORM.last_name>
<!--- <cfset stno = FORM.address_street>
<cfset city = FORM.address_city>
<cfset state = FORM.address_state>
<cfset zip = FORM.address_zip> --->
<cfset email = FORM.payer_email>
</cfoutput>

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




<cfoutput>
variables: #regisAmt#, #fname#, #lname#<br>
</cfoutput>

<!-- check notification validation -->
<CFIF #CFHTTP.FileContent# is "VERIFIED">
<br>status is VERIFIED
<!-- check that payment_status=Completed -->
<cfif #FORM.payment_status# eq "Completed">
<br>status is COMPLETED
<!-- check that receiver_email is your email address -->
<cfif #FORM.receiver_email# eq "website@bnaibrith.org">
<br>email is CORRECT
<!-- process payment -->
<cftry>
<cfcatch>
<!--- Insert Customer Information into Customers Table --->
<cfquery name="InsertCustomer" datasource="#application.dsn#">
INSERT INTO Customers
(
fname, lname, stno, city, state, zip, email, guests, program,IsShopper, DateAdded
)
Values
(
'#fname#', '#lname#', '#stno1#', '#city#', '#state#', '#zip#', '#email#','#guests#', 'Tour of WinterThur - October 2004', 'y', GETDATE())
</cfquery>

<cfquery name="getCustomerId" datasource="#application.dsn#">
SELECT MAX(CustomerId) as LastPost
FROM Customers
</cfquery>

<!--- Insert Order Information into Orders --->

<cfquery name="InsertOrder" datasource="#application.dsn#">
INSERT INTO Orders
(
CustomerId, ProductID, Quantity, TotalPrice, Comments, OrderDate
)
Values
(
'#CustomerId.LastPost#', '2', '#Quantity#', '#regisAmt#','#Comments#', GETDATE()
)
</cfquery>
</cfcatch>
</cftry>

<cftry>
<cfcatch>
<!--- Send User an Email --->
<cfmail from="website@bnaibrith.org" to="#email#" subject="Confirmation of Tour Registration" server="mail.bnaibrith.org">
Thank You #fname# #lname# for registering for the Winterthur Tour!

We have the following information:
Total: #Quantity#

=====================================
Total Price: #DOLLARFORMAT(regisAmt)#

If you have questions, please contact jdoughten@bnaibrith.org
</cfmail></cfcatch>
</cftry>
</cfif>
</cfif>

<CFELSEIF #CFHTTP.FileContent# is "INVALID">
<!-- log for investigation -->
<cfquery name="logErrors" datasource="#application.dsn#">
INSERT INTO txnsError
(customerID, Product, fname, lname, email, errorDate)
VALUES (#Form.customerID#, '#Form.Product#', '#Form.fname#', '#Form.lname#', '#Form.email#', GETDATE()
)
</cfquery>


<CFELSE>
<!-- error -->
<cftry>
<cfcatch>
<!--- Log the received form posting to file --->
<cfset Ret = chr(13) & chr(10)>
<cfset strMsg = "">
<CFLOOP INDEX="TheField" list="#Form.FieldNames#">
<CFSET strMsg = strMsg & "#LCase(TheField)#=#Evaluate(TheField)#" & Ret>
</CFLOOP>
<!--- Write the incoming IPN to a file log request --->
<CFSET thisPath= ExpandPath("*.*")>
<CFSET thisDirectory= GetDirectoryFromPath(thisPath)>
<cfset strStamp = DatePart("yyyy", Now()) & "_" & DatePart("m", Now()) & "_" & DatePart("d", Now()) & DatePart("m", Now()) & DatePart("s", Now())>
<cfset strFileName = "IN_IPN_#strStamp#.txt">
<cfset strfilePath = "#GetDirectoryFromPath(thisPath)#posts\#strFileName#">
<CFFILE ACTION="Write"
FILE=#strfilePath#
OUTPUT=#strMsg#
ADDNEWLINE="No">
</cfcatch>
</cftry>
</CFIF>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top