From: Marius Gavrilescu Date: Sat, 7 May 2016 17:44:29 +0000 (+0100) Subject: Send email when an order is placed X-Git-Tag: 0.000_006~1 X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=8526cf2b23162d75ad55a4ee7587224a921b9ec2;p=app-web-oof.git Send email when an order is placed --- diff --git a/Makefile.PL b/Makefile.PL index ffc13b0..fb896ce 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -13,6 +13,8 @@ WriteMakefile( qw/Plack::App::File 0 Plack::Builder 0 DBIx::Simple 0 + Email::Sender::Simple 0 + Email::Simple 0 File::Slurp 0 HTML::TreeBuilder 0 HTML::Element::Library 0 diff --git a/README b/README index db4dc62..b316bf1 100644 --- a/README +++ b/README @@ -23,9 +23,13 @@ This module requires these other modules and libraries: * Plack * DBIx::Simple +* Email::Simple +* Email::Sender::Simple +* File::Slurp * HTML::Element * HTML::Element::Library * JSON::MaybeXS +* Try::Tiny COPYRIGHT AND LICENCE diff --git a/lib/App/Web/Oof.pm b/lib/App/Web/Oof.pm index fa256a6..405ffb5 100644 --- a/lib/App/Web/Oof.pm +++ b/lib/App/Web/Oof.pm @@ -9,6 +9,8 @@ use parent qw/Plack::Component/; our $VERSION = '0.000_005'; use DBIx::Simple; +use Email::Sender::Simple 'sendmail'; +use Email::Simple; use File::Slurp; use HTML::TreeBuilder; use HTML::Element::Library; @@ -208,6 +210,14 @@ sub order_app { } $db{$$}->insert(orders => {id => $id, %parms}); $db{$$}->commit; + sendmail (Email::Simple->create( + header => [ + From => $ENV{OOF_EMAIL_FROM}, + To => $ENV{OOF_EMAIL_TO}, + Subject => "Order $id placed", + ], + body => 'A new order was placed.', + )) if $ENV{OOF_EMAIL_TO}; } catch { $db{$$}->rollback; $err = [500, ['Content-type', 'text/plain'], ["Error: $_"]]