Copy link to clipboard
Copied
Hello;
I am using this code to grab the users information from paypal, I have the correct IPN and it brings it in fine, BUT here is my issues. I have 2 of them I can't figure out.
1. When the information comes back it is URL Encoded, how do I change it back to normal format so the email address actually uses the @ sign and not %004, and other issues with the information it brings back.
2. I get an error. In this page, I have a form that is populated by the information that comes back from paypal, when the user submits this form to send that info as well as the new info we need from them I get this error:
Element TX is undefined in URL. | |
The error occurred in C:\Inetpub\wwwroot\paypal\step2.cfm: line 60 | |
58 : <p align="left"><img src="../images/bridalText.jpg" width="257" height="59"></p> |
I know this is a lot of code, but it is pretty simple. How do I define TX in the form? and how do I unencode the information back from paypal?
My code: (I'm cutting a lot out, so you can see the main portion of what I am doing)
<!--- paypal IPN and code --->
<cfset authToken="MYIPN NUMBER GOES HERE">
<cfset txToken = url.tx>
<cfset query="cmd=_notify-synch&tx=" & txToken & "&at=" & authToken>
<CFHTTP url="https://www.paypal.com/cgi-bin/webscr?#query#" method="GET" resolveurl="false">
</CFHTTP>
<cfif left(cfhttp.FileContent,7) is "SUCCESS">
<cfloop list="#cfhttp.FileContent#"
index="curLine"
delimiters="#chr(10)#">
<cfif listGetAt(curLine,1,"=") is "first_name">
<cfset firstName=listGetAt(curLine,2,"=")>
</cfif>
<cfif listGetAt(curLine,1,"=") is "last_name">
<cfset lastName=listGetAt(curLine,2,"=")>
</cfif>
<cfif listGetAt(curLine,1,"=") is "payer_email">
<cfset email=listGetAt(curLine,2,"=")>
</cfif>
<cfif listGetAt(curLine,1,"=") is "address_street">
<cfset streetAdd=listGetAt(curLine,2,"=")>
</cfif>
<cfif listGetAt(curLine,1,"=") is "address_city">
<cfset city=listGetAt(curLine,2,"=")>
</cfif>
<cfif listGetAt(curLine,1,"=") is "address_state">
<cfset state=listGetAt(curLine,2,"=")>
</cfif>
<cfif listGetAt(curLine,1,"=") is "address_zip">
<cfset zip=listGetAt(curLine,2,"=")>
</cfif>
<cfif listGetAt(curLine,1,"=") is "item_name">
<cfset itemName=listGetAt(curLine,2,"=")>
</cfif>
<cfif listGetAt(curLine,1,"=") is "mc_gross">
<cfset mcGross=listGetAt(curLine,2,"=")>
</cfif>
<cfif listGetAt(curLine,1,"=") is "mc_currency">
<cfset mcCurrency=listGetAt(curLine,2,"=")>
</cfif>
</cfloop>
<cfoutput>
<p><h3>Your order has been successfully received.</h3></p>
<b>Details</b><br>
<li style="line-height:15px; margin-left:20px;">Name: #firstName# #lastName#</li>
<li style="line-height:15px; margin-left:20px;">Description: #itemName#</li>
<li style="line-height:15px; margin-left:20px;">Amount: #mcCurrency# #mcGross#</li>
<hr>
</cfoutput>
<cfelse>
ERROR: Check to make sure the authToken value set is EXACTLY what PayPal gave
</cfif>
<!--- end paypal IPN --->
<!--- My form using the IPN information --->
<cfparam name="FORM.firstName" default="#firstName#">
<cfparam name="FORM.lastName" default="#lastName#">
<cfparam name="FORM.email" default="#email#">
<cfparam name="FORM.cPhone" default="#phone#">
<cfparam name="FORM.streetAdd" default="#streetAdd#">
<cfparam name="FORM.city" default="#city#">
<cfparam name="FORM.state" default="#state#">
<cfparam name="FORM.zip" default="#zip#">
<cfparam name="FORM.mype" default="">
<cfparam name="FORM.bgName" default="">
<cfparam name="FORM.bgEmail" default="">
<cfparam name="FORM.bgAdd" default="">
<cfparam name="FORM.bgCity" default="">
<cfparam name="FORM.bgState" default="">
<cfparam name="FORM.bgZip" default="">
<cfparam name="FORM.message" default="">
<!--- this is where it checks to make sure all the required fields are filled in, if not it posts back a message requesting they fill it in, if it is all filled in, then it sends an email with all the info in it, and gives them a thank you message. I wanted to cut out this part, you don't need to proof it, the problem is in my paramiters and form--->
<cfoutput>
<cfform action="#cgi.script_name#" method="post" enctype="application/x-www-form-urlencoded">
<input type="text" name="firstName" id="firstName" value="#firstName#" />
<input type="text" name="lastName" id="lastName" value="#lastName#" />
<input type="text" name="email" id="email" value="#email#" />
<input type="text" name="streetAdd" id="streetAdd" value="#streetAdd#" />
<input type="text" name="city" id="city" value="#city#" />
<input type="text" name="state" id="state" value="#state#" />
<input type="text" name="zip" id="zip" value="#zip#" />
</cfform>
</cfoutput>
I also took out a bunch of fields I need to have the user fill out, but this is the meat of what I'm trying to do.
Can anyone help me??? Please? It's driving me nuts!
Thank you!
URLDecode()
Copy link to clipboard
Copied
When the information comes back it is URL Encoded, how do I change it back to normal format
Take a look at the URLDecode function
How do I define TX in the form?
What is the source of the TX value ?
<cfif listGetAt(curLine,1,"=") is "first_name">
<cfset firstName=listGetAt(curLine,2,"=")>
</cfif>
<cfif listGetAt(curLine,1,"=") is "last_name">
<cfset lastName=listGetAt(curLine,2,"=")>
</cfif>
......
You could simplify that code by using a structure instead of multiple CFIF statements. On each iteration, grab the first list element (ie parameter name). Use it as the structure key (ie "first_name"). The rest of the list becomes the parameter value. Not tested, but something like this
<cfset results = {} >
<cfloop list="#cfhttp.FileContent#" .....>
<!--- decode the VALUE if needed ....---->
<cfset results[ listFirst(curLine, "=") ] = listRest(curLine, "=")>
</cfloop>
<cfdump var="#results#">
That should populate the structure with of the parameters returned, without lines and lines of CFIF statements.
Message was edited by: -==cfSearching==-
Copy link to clipboard
Copied
I get this error when I use your loop:
Invalid token '{' found on line 70 at column 18. | |
The CFML compiler was processing:
| |
The error occurred in C:\Inetpub\wwwroot\ISPDial_com\chefworldinc_com\paypal\ipn.cfm: line 70 | |
68 : |
This is the value if TX:
<cfset txToken = url.tx>
<cfset query="cmd=_notify-synch&tx=" & txToken & "&at=" & authToken>
when I hit submit on the form on this page, it throws the other error, tx is undefined in form.
FYI: Thi ssite is sitting on a CF 6.1 server. (not my choice) if this makes a difference.
Thanks
Copy link to clipboard
Copied
This is the value if TX: <cfset txToken = url.tx>
<cfset query="cmd=_notify-synch&tx=" & txToken & "&at=" & authToken>
Perhaps I missed it, but ... where are you defining "url.tx" in the code? That variable has to be declared somewhere before you can use it. Otherwise, CF will rightly complain that the variable is not defined.
FYI: Thi ssite is sitting on a CF 6.1 server. (not my choice) if this makes a difference.
Well, as mentioned the snippet is just psuedo-code. So it will not work exactly "as is". But yes, your version of CF does make a difference. The snippet posted uses a shortcut for creating a new structure ie "{ }", which does not exist in 6.1. So instead of
<cfset results = {} >
... use structNew() instead.
<cfset results = structNew() >
Message was edited by: -==cfSearching==-
Copy link to clipboard
Copied
Well, not I don't really need to use the IPN code after it gets to the form, BUT it is still calling it up for some reason, I even tried to put the form on a 2nd page, and use hidden form fields to hold the ipn info and it still throws this error. so to define it.. I need to do something like this?
<cfparam name="url.tx" type="integer" default="">
and in my form....
<input type="hidden" name="tx" value="#url.tx#">
Is this correct?
The code works as a loop, but it isn't decoding the urlecoding it's still showing up as encoded lines.
Copy link to clipboard
Copied
I am really not sure what you mean by "it is still calling it up" .. All I was saying is that the error message seems very clear. You are trying to use a variable that does not exist, or perhaps does not exist in that scope (ie URL). You either have to define the variable properly, or if you do not need it, remove it from the code.
Copy link to clipboard
Copied
wrong account, this is one of my employees.
Copy link to clipboard
Copied
URLDecode()
Copy link to clipboard
Copied
I have my code (original code) working now without errors.. all I need to do now
is decode the url encoding. I've been looking it up, and I haven't been able to find a way to decode the
information passed back to the site via the ipn. How would I do this in CF 6.1 using my original code I posted? Then I'm all set.
Copy link to clipboard
Copied
Wow. I don't think you really understand what you are getting with PayPal IPN. Do you have somebody helping you that is a PayPal expert by chance?
Copy link to clipboard
Copied
bi help and it's fixed and working. thanks