#!/usr/bin/perl # read the post from paying system and add 'cmd' # # Modified for Isell Classifieds Automation of paid ads. # Copyright 2003, www.becanada.com # $mailprog = '/usr/sbin/sendmail'; read (STDIN, $query, $ENV{'CONTENT_LENGTH'}); $query .= '&cmd=_notify-validate'; # post back to PayPal system to validate use LWP::UserAgent; $ua = new LWP::UserAgent; $req = new HTTP::Request 'POST','https://www.paypal.com/cgi-bin/webscr'; $req->content_type('application/x-www-form-urlencoded'); $req->content($query); $res = $ua->request($req); # split posted variables into pairs @pairs = split(/&/, $query); $count = 0; foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $variable{$name} = $value; $count++; } # assign posted variables to local variables $receiver_email = $variable{'receiver_email'}; $item_name = $variable{'item_name'}; $item_number = $variable{'item_number'}; $custom = $variable{'custom'}; $payment_status = $variable{'payment_status'}; $payment_date = $variable{'payment_date'}; $payment_gross = $variable{'payment_gross'}; $payment_fee = $variable{'payment_fee'}; $txn_id = $variable{'txn_id'}; $first_name = $variable{'first_name'}; $last_name = $variable{'last_name'}; $address_street = $variable{'address_street'}; $address_city = $variable{'address_city'}; $address_state = $variable{'address_state'}; $address_zip = $variable{'address_zip'}; $address_country = $variable{'address_country'}; $payer_email = $variable{'payer_email'}; if ( $res->content eq 'VERIFIED' && lc($payment_status) eq 'completed' && index($item_name,"class")>-1 ) { $item_name=substr($item_name,5); # "class10" = ten credits. # # $item_name = number of credits # $item_number = ID code of buyer # $fl="credits.txt"; open(FILE, $fl ) || print "I can't open that file\n"; @credit = ; close(FILE); for ($i=0; $i<@credit ; $i++) { @words=split(/,/,@credit[$i]); if ($item_number eq @words[0]) { @words[4]=@words[4] + $item_name; print qq~Credit[s] Added today: $item_name .

You now have @words[4] credit[s] .

~; @credit[$i]=join(",",@words); chomp(@credit[$i]); @credit[$i]=@credit[$i] . "\n"; open(HTML, ">$fl") || print "I can't create that file\n"; print HTML @credit; close(HTML); last; } } open(MAIL,"|$mailprog -t"); print MAIL qq~To: $first_name $last_name <$payer_email> Cc: $receiver_email From: $receiver_email Subject: Classifieds Ad Updated. Hello $first_name $last_name : Your $payment_gross payment for your classifieds has been received and $item_name ads credits have been added to your account: ID NUMBER: $item_number Thank you for your purchase. Webmaster @ Classifieds. ~; close (MAIL); print "Content-type: text/html\n\n"; print "

Thank You - $first_name $last_name

Payment received, Your Ad credits have been updated."; exit; } if ($res->content eq 'INVALID') { print "Content-type: text/html\n\n"; print "

Thank You - $first_name $last_name

Payment could not be processed, please re-do / re-submit...

"; exit; } print "Content-type: text/html\n\n"; print "

Thank You - $first_name $last_name

Payment in processing, you will be notified via email when complete. [if you paid via cheque, this can take up to 4 business days to clear].

";