#!revolution --| PayPal Postback CGI --| --| updated March 1, 2006 --| Used for confirming payments to PayPal --| Will email customers with their key on startup --StartCGI --read info put empty into theTermsArray repeat until length(theTermsArray) = $CONTENT_LENGTH read from stdin until empty put it after theTermsArray end repeat put theTermsArray into tparam --for mailing put "myLibUrl.rev" into theStack start using stack theStack put tparam & "&cmd=_notify-validate" into temparray post temparray to url "http://www.sandbox.paypal.com/cgi-bin/webscr" --PAYPAL'S RESPONSE IS IN THE 'IT' VARIABLE put it into treply if "VERIFIED" is not in treply then --SOMETHING VERY WRONG-- put "SERIOUS PROBLEM: unverified IPN message" & cr & treply into pMessage get mailout("speakup@mac.com","IPN Trouble:",pMessage) put "trouble encountered: unable to verify" into thtml else put "Thank you." into t_html split theTermsArray by "&" and "=" put urlDecode(theTermsArray["payment_status"]) into tstatus put urlDecode(theTermsArray["txn_id"]) into customerID put urlDecode(theTermsArray["receiver_email"]) into receiver_email put urlDecode(theTermsArray["payment_gross"]) into tprice put urlDecode(theTermsArray["mc_currency"]) into tcurrency put urlDecode(theTermsArray["item_name"]) into item_name put urlDecode(theTermsArray["first_name"]) into customerf_name put urlDecode(theTermsArray["last_name"]) into customerl_name put urlDecode(theTermsArray["payer_email"]) into customer_email put urlencode(theTermsArray["custom"]) into _custom -------------------GET THE KEY_LOG INFO-------------------- put url "file:../reg/key_log.txt" into t_base put itemoffset("FirstName",t_base) into fname_item --Notice these are 'ITEMoffset' put itemoffset("LastName",t_base) into lname_item put itemoffset("email",t_base) into mail_item put itemoffset("price",t_base) into price_item put itemoffset("key",t_base) into key_item put itemoffset("FirstName",t_base) into name_item put itemoffset("IPN_stat",t_base) into status_item --> PDT: status item, IPN: IPN_stat put itemoffset("type",t_base) into type_item put lineoffset(_custom,t_base) into tlinenum --Notice this is 'LINEoffset' put line tlinenum of t_base into tline --- now get all the info ---- put item price_item of tline into thePrice put item type_item of tline into theType replace "$" with "" in thePrice put item key_item of tline into theKey --update our key log--- put tstatus into item status_item of tline put tline into line tlinenum of url "file:../reg/key_log.txt" ----THE FOLLOWING IS NOT WORKING---- ----PUT A LOG UPDATE LINE BY LINE TO SEE THE PROBLEM--- put "true" into tresult if tstatus is not "completed" then put "false" into tresult put cr & "tstatus check: " & tresult after tparam if urldecode(receiver_email) is not "YOURNAME@SOMEWHERE.com" then put "false" into tresult put cr & "email check: " & tresult & tab & urldecode(receiver_email) after tparam if tcurrency is not "USD" then put "false" into tresult put cr & "currency check: " & tresult & tab & tcurrency after tparam if tprice <> thePrice then put "false" into tresult put cr & "Price check: " & tresult & tab & thePrice after tparam --if item_name is not theType then put "false" into tresult --The school name is here! if payer_email is empty then put "false" into tresult ----MIGHT BE A GOOD IDEA TO GO BACK TO USING A STACK TO STORE THIS!--- if tresult is "true" then put urldecode(theType) & cr & urldecode(thekey) into _key if "individual" is in theType then put "School: " & urldecode(theType) before _key put "This email is to notify you of the successful completion of your payment via Paypal." & cr & "Your license key: " & cr & "Your license keys should be one line. Be careful of wraps, and your key should not contain spaces." & cr & cr & _key into pMessage get mailout(customer_email,"Payment Completed: YOUR PRODUCT NAME",pMessage) else -----SOMETHING VERY WRONG put "This email is to notify you of the status of your payment via Paypal." & cr & "A problem was encountered: Please contact our sales department if you think this an error." into pMessage put "Date: " & (the short date) & cr & "-----------------" & cr & cr & pMessage into pMessage get mailout(customer_email,"IPN issue: YOUR PRODUCT NAME",pMessage) put tstatus & cr & tparam after pMessage put "******@******.com" into z put urlencode(z) into z get mailout(z,"Payment Not Completed: START SELLING YOUR POSSESIONS",pMessage) end if end if put cr& "=============="& the date && the time & "==============" & cr & "Original: " & tparam & cr & "IPN reply to my post:" & treply &cr after url "file:IPN_log.txt" put "Content-Type: text/html" & cr & cr put thtml end startup function mailout toWhom,tSubject,pMessage put "/usr/sbin/sendmail -t" into mprocess open process mprocess for write write "From:" && "*******@*******.com" & cr to process mprocess write "To:" && urldecode(toWhom) & cr to process mprocess write "Subject:" && tSubject & cr & cr to process mprocess write pMessage & cr to process mprocess close process mprocess wait until the openProcesses is empty end mailout