OneShopNotificationListener.pl
From Developer's API
(Difference between revisions)
m (Updated OneShopNotificationListener.pl) |
m (Added 'plus' instead of 'asterisk' in regex.) |
||
Line 25: | Line 25: | ||
my ($current_xml_response) = @_; | my ($current_xml_response) = @_; | ||
my $current_return = {type => "",token => ""}; | my $current_return = {type => "",token => ""}; | ||
− | if($current_xml_response =~ /<(\w+)>\s*<Token>\s*(\d)\s*<\/Token>\s*<\/\1>/) | + | if($current_xml_response =~ /<(\w+)>\s*<Token>\s*(\d+)\s*<\/Token>\s*<\/\1>/) |
{ | { | ||
$current_return->{type} = $1; | $current_return->{type} = $1; |
Revision as of 20:28, 29 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 according to type 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);