YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

Working IPN code! Options
somecoder
#1 Posted : Friday, April 02, 2004 4:36:26 AM
Rank: Starting Member

Groups: Registered

Joined: 4/2/2004
Posts: 2
Location: ,
I've had no luck with the example ipn code provided. I finally discovered why I was having so much trouble (several reasons). Thought I would share the code that works. Bottom line: instead of CFLOOPing the formfields sent by paypal and recreating the content-request, just include the content sent by paypal, byte for byte: <cfset x = GetHttpRequestData()> <CFSET str="cmd=_notify-validate&" & x.content> <!--- post back to PayPal system to validate ---> <CFHTTP URL="https://www.paypal.com/cgi-bin/webscr?#str#" METHOD="GET" RESOLVEURL="false"> </CFHTTP> Hope that helps someone.
Sponsor  
 
paypal_jess
#2 Posted : Tuesday, April 06, 2004 5:46:37 PM
Rank: Starting Member

Groups: Registered

Joined: 8/1/2003
Posts: 4
Location: ,
I currently have a working CF IPN script, and it still uses the code sample from PayPal. This is what I have before I set my local variables. Do you still have the code that you were using previous to the change?

&lt;!-- read post from PayPal system and add 'cmd' --&gt;
&lt;CFSET str="cmd=_notify-validate"&gt;

&lt;CFLOOP INDEX="TheField" list="#Form.FieldNames#"&gt;
&lt;CFSET str = str & "#LCase(TheField)#=#URLEncodedFormat(Evaluate(TheField))#"&gt;
&lt;/cfloop&gt;


&lt;CFIF IsDefined("FORM.payment_date")&gt;
&lt;CFSET str = str & "&payment_date=#URLEncodedFormat(Form.payment_date)#"&gt;
&lt;/CFIF&gt;

&lt;CFHTTP URL="https://www.paypal.com/cgi-bin/webscr?#str#" METHOD="GET" RESOLVEURL="false"&gt;
&lt;/CFHTTP&gt;

Sincerely,
Jessica
PayPal Tech Support
PayPal, an eBay Company
somecoder
#3 Posted : Wednesday, April 07, 2004 1:55:41 PM
Rank: Starting Member

Groups: Registered

Joined: 4/2/2004
Posts: 2
Location: ,
Yes I do have the old code. It's almost identical to yours:

&lt;!-- read post from PayPal system and add 'cmd' --&gt;
&lt;CFSET str="cmd=_notify-validate"&gt;
&lt;CFLOOP INDEX="TheField" list="#Form.FieldNames#"&gt;
&lt;CFSET str = str & "#LCase(TheField)#=#URLEncodedFormat(Evaluate(TheField))#"&gt;
&lt;/CFLOOP&gt;
&lt;CFIF IsDefined("FORM.payment_date")&gt;
&lt;CFSET str = str & "&payment_date=#URLEncodedFormat(Form.payment_date)#"&gt;
&lt;/CFIF&gt;
&lt;CFIF IsDefined("FORM.subscr_date")&gt;
&lt;CFSET str = str & "&subscr_date=#URLEncodedFormat(Form.subscr_date)#"&gt;
&lt;/CFIF&gt;

&lt;!-- post back to PayPal system to validate --&gt;
&lt;CFHTTP URL="https://www.paypal.com/cgi-bin/webscr?#str#" METHOD="GET" RESOLVEURL="false"&gt;
&lt;/CFHTTP&gt;


It didn't work for me at http://www.eliteweaver.co.uk/testing/ipntest.php or during my live ipn tests with paypal.

Problems I had with the example code:
1) Eliteweaver apparently requires you to return variables in the original order they were sent. My tests suggested paypal had a similar requirement.

2) The form.fieldnames list happens to be ordered properly but is stripped of any reference to _date variables because they are used internally by ColdFusion. Appending them to the end will change the return field order. The FORM structure doesn't have any such limitation, but it's ordered by variable name, which also conflicts with point #1.

3) Although this may not be a problem for paypal or for Eliteweaver's ipntest, I've noticed many CGI scripts don't work well with ColdFusion's URLEncodedFormat() implementation. ColdFusion unnecessarily encodes certain characters in hex (-. ).

4) Even if I weren't having these problems, sending the form content back to PayPal seems to require the least effort. For example, unless you modify your ipn code for each additional _date field paypal adds in the future, your code will fail. Furthermore, your code will fail to return a subscr_date if you ever need IPN confirmation for a subscription payment.

5) Lastly, it may be possible to exploit the Evaluate() function. CGI security policy dictates that client-submitted data shouldn't be trusted. At the very least, Evaluate(TheField) should be replaced by a structure call, such as form[TheField].

It seems that a lot of people have gotten the example CFML code to work. All I know is that it didn't work for me (either on Elite's testipn or live with paypal). Not only does the x.content method seem to work well for me it, also lets me use Elite's testipn (which is very useful) and requires no future maintenance in the event paypal adds another _date field.
PayPal_Paulam
#4 Posted : Thursday, April 08, 2004 11:47:37 AM
Rank: Starting Member

Groups: Registered

Joined: 11/21/2003
Posts: 511
Location: ,
Hi somecoder,

Please use the following example to test your script. All you need to do is change the action for your IPN url. And you received a 'Verified' response. If so, your code is working and the next step will be check how are you handling the data from a normal transaction? and debug from that point.

If you get 'Invalid' response that means that you code is not working. And I will recommend you as next step. Use the CF sample code that you provide on our site http://www.paypal.com/cg...cl/rec/ipn-code-outside

&lt;form method="post" action="http://www.dsul.org/notify.asp" ID="Form1"&gt;
&lt;input type="hidden" name="mc_gross" value="0.01" ID="Hidden1"&gt;
&lt;input type="hidden" name="address_status" value="unconfirmed" ID="Hidden2"&gt;
&lt;input type="hidden" name="payer_id" value="QGVDAFGZ9XHLJ" ID="Hidden11"&gt;
&lt;input type="hidden" name="tax" value="0.00" ID="Hidden12"&gt;
&lt;input type="hidden" name="payment_date" value="13:50:26 Mar 11, 2004 PST" ID="Hidden13"&gt;
&lt;input type="hidden" name="address_street" value="1840 Embarcadero Road" ID="Hidden14"&gt;
&lt;input type="hidden" name="payment_status" value="Pending" ID="Hidden15"&gt;
&lt;input type="hidden" name="address_zip" value="94303" ID="Hidden16"&gt;
&lt;input type="hidden" name="first_name" value="Patrick" ID="Hidden17"&gt;
&lt;input type="hidden" name="address_name" value="Patrick Breitenbach" ID="Hidden18"&gt;
&lt;input type="hidden" name="notify_version" value="1.6" ID="Hidden19"&gt;
&lt;input type="hidden" name="custom" value="" ID="Hidden20"&gt;
&lt;input type="hidden" name="payer_status" value="unverified" ID="Hidden21"&gt;
&lt;input type="hidden" name="business" value="pb-pdn@paypal.com" ID="Hidden22"&gt;
&lt;input type="hidden" name="address_country" value="United States" ID="Hidden23"&gt;
&lt;input type="hidden" name="address_city" value="Palo Alto" ID="Hidden24"&gt;
&lt;input type="hidden" name="quantity" value="1" ID="Hidden25"&gt;
&lt;input type="hidden" name="verify_sign" value="AkU-lzGsIkV0gazwa9nDVpmsx9X0AMF3KqbmhBuM8UTVNO5CFNAptk78" ID="Hidden26"&gt;
&lt;input type="hidden" name="payer_email" value="pb-test@paypal.com" ID="Hidden27"&gt;
&lt;input type="hidden" name="txn_id" value="4MX09190KB7728256" ID="Hidden28"&gt;
&lt;input type="hidden" name="payment_type" value="instant" ID="Hidden29"&gt;
&lt;input type="hidden" name="last_name" value="Breitenbach" ID="Hidden30"&gt;
&lt;input type="hidden" name="address_state" value="CA" ID="Hidden31"&gt;
&lt;input type="hidden" name="receiver_email" value="pb-pdn@paypal.com" ID="Hidden32"&gt;
&lt;input type="hidden" name="receiver_id" value="WAT63H8628SRN" ID="Hidden33"&gt;
&lt;input type="hidden" name="pending_reason" value="verify" ID="Hidden34"&gt;
&lt;input type="hidden" name="txn_type" value="web_accept" ID="Hidden35"&gt;
&lt;input type="hidden" name="item_name" value="Test" ID="Hidden36"&gt;
&lt;input type="hidden" name="mc_currency" value="USD" ID="Hidden37"&gt;
&lt;input type="hidden" name="item_number" value="" ID="Hidden38"&gt;
&lt;input type="hidden" name="payment_gross" value="0.01" ID="Hidden39"&gt;
&lt;input type="submit" value="Test IPN" ID="Submit1" NAME="Submit1"&gt;
&lt;/form&gt;


Paulam
PayPal Tech Support Agent
PayPal an eBay company
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAFVision Theme by Jaben Cargman (Tiny Gecko)
Powered by YAF | YAF © 2003-2009, Yet Another Forum.NET
This page was generated in 0.299 seconds.