Jump to content


Photo

Code Sample Incuding Query String


  • This topic is locked This topic is locked
No replies to this topic

#1 Guest(old)

Guest(old)

    Junior Member

  • Members
  • 312 posts

Posted 24 November 2002 - 06:53 PM

ColdFusion working script plus query string to post payments details to your database

<!--- http://www.YourWebAddress/ipn/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(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.paypal.com/cgi-bin/webscr?#str#" METHOD="GET" RESOLVEURL="false">
</CFHTTP>
<cfparam name="Product_ID" default="0">
<cfparam name="Form.receiver_email" default="">
<cfparam name="Form.item_name" default="">
<cfparam name="Form.item_number" default="">
<cfparam name="Form.quantity" default="">
<cfparam name="Form.invoice" default="">
<cfparam name="Form.custom" default="">
<cfparam name="Form.payment_status" default="">
<cfparam name="Form.pending_reason" default="">
<cfparam name="Form.payment_date" default="">
<cfparam name="Form.payment_gross" default="">
<cfparam name="Form.payment_fee" default="">
<cfparam name="Form.txn_id" default="">
<cfparam name="Form.txn_type" default="">
<cfparam name="Form.first_name" default="">
<cfparam name="Form.last_name" default="">
<cfparam name="Form.address_street" default="">
<cfparam name="Form.address_city" default="">
<cfparam name="Form.address_state" default="">
<cfparam name="Form.address_zip" default="">
<cfparam name="Form.address_country" default="">
<cfparam name="Form.address_status" default="">
<cfparam name="Form.payer_email" default="">
<cfparam name="Form.payer_status" default="">
<cfparam name="Form.payment_type" default="">
<cfparam name="Form.notify_version" default="">
<cfparam name="Form.verify_sign" default="">
<!-- check notification validation -->
<!--- <CFIF #CFHTTP.FileContent# is "VERIFIED"> --->
<!-- check that payment_status=Completed -->
<!-- check that txn_id has not been previously processed -->
<cfquery name="Check" datasource="#ds#">
Select txn_ID from
PayedListings
Where txn_ID = '#Form.txn_ID#'
</cfquery>
<cfset strError = "">
<cfif Not Check.RecordCount is 0>
<cfset strError = " Transaction has been previously processed. ">
</cfif>
<!-- check that receiver_email is your email address -->
<cfif not CompareNoCase(trim(Form.receiver_email), "admin@buybackbooks.com")>
<cfset strError = strError & " Receiver email is not correct. ">
</cfif>
<cfif CompareNoCase(trim(CFHTTP.FileContent), "INVALID")>
<cfset strError = strError & " Payment posting was invalid. ">
</cfif>
<cfif strError is "">
<cfset Product_ID = ReplaceNoCase(Form.item_number, "-Listing", "")>
<cfquery name="deleteRecords" datasource="#ds#">
Delete PayedListings
Where Product_ID = #Product_Id#
</cfquery>
<cfset strIntoDates = ",ListingStartDate, ListingEndDate">
<!--- Add 60 days to the start date --->
<cfset strValueDates = ",#CreateODBCDateTime(now())#, #CreateODBCDateTime(DateAdd("d", "60", Now()))#">
<cfelse>
<cfset strIntoDates = "">
<cfset strValueDates = "">
</cfif>
<cfquery name="InsertPaymentRecord" datasource="#ds#">
Insert Into PayedListings(
Product_ID,
receiver_email,
item_name,
item_number,
quantity,
invoice,
custom,
payment_status,
pending_reason,
payment_date,
payment_gross,
payment_fee,
txn_id,
txn_type,
first_name,
last_name,
address_street,
address_city,
address_state,
address_zip,
address_country,
address_status,
payer_email,
payer_status,
payment_type,
notify_version,
verify_sign,
Response,
Errors
#strIntoDates#)
Values(
#Product_ID#,
'#Form.receiver_email#',
'#Form.item_name#',
'#Form.item_number#',
'#Form.quantity#',
'#Form.invoice#',
'#Form.custom#',
'#Form.payment_status#',
'#Form.pending_reason#',
'#Form.payment_date#',
'#Form.payment_gross#',
'#Form.payment_fee#',
'#Form.txn_id#',
'#Form.txn_type#',
'#Form.first_name#',
'#Form.last_name#',
'#Form.address_street#',
'#Form.address_city#',
'#Form.address_state#',
'#Form.address_zip#',
'#Form.address_country#',
'#Form.address_status#',
'#Form.payer_email#',
'#Form.payer_status#',
'#Form.payment_type#',
'#Form.notify_version#',
'#Form.verify_sign#',
'#CFHTTP.FileContent#',
'#strError#'
#PreserveSingleQuotes(strValueDates)#)
</cfquery>

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





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users