Order API Programming, help suggestions anything
Posted: Thu Jul 19, 2001 11:34 am
Hello,
I need a really good perl programmer to
write a script for me using the order api. Thescript should grap order
data and scan for item number and or sku, if found send user an email
with download information.
I'd like to take it further and have a conditonal statement to check for
more downloadable products and emails to send.
I think maybe using perl DBI and stroing the info in MySQL would work
better but my perl isn't that hot yet.
I've tried and it's not working, anyone please help
anyone have a suggestion?
Thanks, Chris
here is the script:
--------------------------------------------------------------------
#!/usr/bin/perl
#download.cgi
##############READ INPUT##############
# Process the order data and put it into the order_data variable
# for future reference
@nvpairs = split(/&/, $buffer);
@order_data = ();
foreach $pair (@nvpairs)
{
($name, $value) = split(/=/, $pair);
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$order_data{$name}=$value;
}
######################################
#CONFIG
$sendmail="/usr/sbin/sendmail";
$subject="NetNanny Product";
$adminemail="webmaster\@familycow.com";
$useremail = $order_data{"O-Email"};
$num_items = $order_data{"O-NumItems"};
for ($i=0;$i<$num_items;$i++) {
#for $i(0..$num_items){
$item_upc = sprintf("B01-Name", $i+1);
if ($order_data{$item_upc} eq "nn41full-test"){
#email file to user
$file="nnv41\.html";
$filebase=".";
$boundary="84842840284";
$contenttype="application/x-zip-compressed";
open (MAIL, "| $sendmail -t");
print MAIL "To: $useremail\n";
print MAIL "From: $adminemail\n";
print MAIL "MIME-Version: 1.0\n";
print MAIL "Subject: $subject\n";
print MAIL "Content-Type: multipart/mixed;
boundary=\"------------$boundary\"\n";
print MAIL "\n";
print MAIL "This is a multi-part message in MIME formats.\n";
print MAIL "--------------$boundary\n";
print MAIL "Content-Type: text/plain; charset=us-ascii\n";
print MAIL "Content-Transfer-Encoding: 7bit\n\n";
print MAIL <<EOF;
Here is NetNanny
EOF
print MAIL "\n";
print MAIL "--------------$boundary\n";
print MAIL "Content-Type: $contenttype; name=\"$file\"\n";
print MAIL "Content-Transfer-Encoding: base64\n";
print MAIL "Content-Disposition: inline; filename=\"$file\"\n\n";
my $buf; $/=0;
open INPUT, "$filebase/$file"; # should be readable, we checked above
[-r]
binmode INPUT if ($^O eq 'NT' or $^O eq 'MSWin32');
while(read(INPUT, $buf, 60*57)){
print MAIL &encode_base64($buf);
}
close INPUT;
print MAIL "\n--------------$boundary--\n";
print MAIL "\n";
close (MAIL);
sub encode_base64 {
my ($res, $eol, $padding) = ("", "\n", undef);
while (($_[0] =~ /(.{1,45})/gs))
{
$res .= substr(pack('u', $1), 1);
chop $res;
}
$res =~ tr#` -_#AA-Za-z0-9+/#; # ` help emacs
$padding = (3 - length($_[0]) % 3) % 3; # fix padding at the
end
$res =~ s#.{$padding}$#'=' x $padding#e if $padding; # pad
eoedv data with ='s
$res =~ s#(.{1,76})#$1$eol#g if (length $eol); # lines of
at least 76 characters
return $res;
}
}
}
exit;
I need a really good perl programmer to
write a script for me using the order api. Thescript should grap order
data and scan for item number and or sku, if found send user an email
with download information.
I'd like to take it further and have a conditonal statement to check for
more downloadable products and emails to send.
I think maybe using perl DBI and stroing the info in MySQL would work
better but my perl isn't that hot yet.
I've tried and it's not working, anyone please help
anyone have a suggestion?
Thanks, Chris
here is the script:
--------------------------------------------------------------------
#!/usr/bin/perl
#download.cgi
##############READ INPUT##############
# Process the order data and put it into the order_data variable
# for future reference
@nvpairs = split(/&/, $buffer);
@order_data = ();
foreach $pair (@nvpairs)
{
($name, $value) = split(/=/, $pair);
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$order_data{$name}=$value;
}
######################################
#CONFIG
$sendmail="/usr/sbin/sendmail";
$subject="NetNanny Product";
$adminemail="webmaster\@familycow.com";
$useremail = $order_data{"O-Email"};
$num_items = $order_data{"O-NumItems"};
for ($i=0;$i<$num_items;$i++) {
#for $i(0..$num_items){
$item_upc = sprintf("B01-Name", $i+1);
if ($order_data{$item_upc} eq "nn41full-test"){
#email file to user
$file="nnv41\.html";
$filebase=".";
$boundary="84842840284";
$contenttype="application/x-zip-compressed";
open (MAIL, "| $sendmail -t");
print MAIL "To: $useremail\n";
print MAIL "From: $adminemail\n";
print MAIL "MIME-Version: 1.0\n";
print MAIL "Subject: $subject\n";
print MAIL "Content-Type: multipart/mixed;
boundary=\"------------$boundary\"\n";
print MAIL "\n";
print MAIL "This is a multi-part message in MIME formats.\n";
print MAIL "--------------$boundary\n";
print MAIL "Content-Type: text/plain; charset=us-ascii\n";
print MAIL "Content-Transfer-Encoding: 7bit\n\n";
print MAIL <<EOF;
Here is NetNanny
EOF
print MAIL "\n";
print MAIL "--------------$boundary\n";
print MAIL "Content-Type: $contenttype; name=\"$file\"\n";
print MAIL "Content-Transfer-Encoding: base64\n";
print MAIL "Content-Disposition: inline; filename=\"$file\"\n\n";
my $buf; $/=0;
open INPUT, "$filebase/$file"; # should be readable, we checked above
[-r]
binmode INPUT if ($^O eq 'NT' or $^O eq 'MSWin32');
while(read(INPUT, $buf, 60*57)){
print MAIL &encode_base64($buf);
}
close INPUT;
print MAIL "\n--------------$boundary--\n";
print MAIL "\n";
close (MAIL);
sub encode_base64 {
my ($res, $eol, $padding) = ("", "\n", undef);
while (($_[0] =~ /(.{1,45})/gs))
{
$res .= substr(pack('u', $1), 1);
chop $res;
}
$res =~ tr#` -_#AA-Za-z0-9+/#; # ` help emacs
$padding = (3 - length($_[0]) % 3) % 3; # fix padding at the
end
$res =~ s#.{$padding}$#'=' x $padding#e if $padding; # pad
eoedv data with ='s
$res =~ s#(.{1,76})#$1$eol#g if (length $eol); # lines of
at least 76 characters
return $res;
}
}
}
exit;