OneShopNotificationListener.pl
From Developer's API
(Difference between revisions)
(PERL OneShopNotificationListener.pl) |
m (Updated OneShopNotificationListener.pl) |
||
Line 34: | Line 34: | ||
} | } | ||
+ | # retrieve xml response | ||
my $current_xml_response = read_raw_post(); | my $current_xml_response = read_raw_post(); | ||
+ | # retrieve notification type and token from xml response | ||
my $current_return = lex_response($current_xml_response); | my $current_return = lex_response($current_xml_response); | ||
+ | # open simple log for troubleshooting purposes | ||
+ | open(OSCLOG, ">>oneshop_notifications.log"); | ||
+ | |||
+ | #perform action with | ||
if($current_return->{type} eq "NewOrder") | if($current_return->{type} eq "NewOrder") | ||
{ | { | ||
− | # perform action with the new order notification | + | # perform action with the new order notification |
+ | print OSCLOG join(' ',localtime(time)) . " : new order notification received.\n"; | ||
} | } | ||
elsif($current_return->{type} eq "OtherNotification") | elsif($current_return->{type} eq "OtherNotification") | ||
{ | { | ||
# perform action with the other notification | # perform action with the other notification | ||
+ | print OSCLOG join(' ',localtime(time)) . " : other notification received.\n"; | ||
} | } | ||
else | else | ||
{ | { | ||
# script received invalid post information | # script received invalid post information | ||
− | } | + | print OSCLOG join(' ',localtime(time)) . " : invalid post information received.\n"; |
+ | } | ||
+ | close(OSCLOG); | ||
</pre> | </pre> |
Revision as of 16:11, 28 May 2008
use Library::OneShopAPI; use strict; use CGI qw(:standard); print "Content-Type: text/html\n\n"; sub read_raw_post { my $current_length = $ENV{'CONTENT_LENGTH'}; my $current_remaining = 0; my $current_buffer; while($current_remaining < $current_length) { my $current_read = read(STDIN, $current_buffer, $current_length - $current_remaining, $current_remaining); die("Unable to read from stream : $!") unless defined($current_read); return $current_buffer if $current_read == 0; $current_remaining += $current_read; } return $current_buffer; } sub lex_response { my ($current_xml_response) = @_; my $current_return = {type => "",token => ""}; if($current_xml_response =~ /<(\w+)>\s*<Token>\s*(\d)\s*<\/Token>\s*<\/\1>/) { $current_return->{type} = $1; $current_return->{token} = $2; } return($current_return); } # retrieve xml response my $current_xml_response = read_raw_post(); # retrieve notification type and token from xml response my $current_return = lex_response($current_xml_response); # open simple log for troubleshooting purposes open(OSCLOG, ">>oneshop_notifications.log"); #perform action with if($current_return->{type} eq "NewOrder") { # perform action with the new order notification print OSCLOG join(' ',localtime(time)) . " : new order notification received.\n"; } elsif($current_return->{type} eq "OtherNotification") { # perform action with the other notification print OSCLOG join(' ',localtime(time)) . " : other notification received.\n"; } else { # script received invalid post information print OSCLOG join(' ',localtime(time)) . " : invalid post information received.\n"; } close(OSCLOG);