added email receipt and "my purchases" page

This commit is contained in:
JT Smith 2008-05-26 20:11:10 +00:00
parent 93454e36f9
commit 74b3d3def6
10 changed files with 203 additions and 181 deletions

View file

@ -544,7 +544,7 @@ sub convertTransactionLog {
index transactionId (transactionId),
index vendorId (vendorId)
)");
$session->setting->add('shopMyPurchasesTemplateId','');
$session->setting->add('shopMyPurchasesTemplateId','2gtFt7c0qAFNU3BG_uvNvg');
$session->setting->add('shopMyPurchasesDetailTemplateId','g8W53Pd71uHB9pxaXhWf_A');
my $transactionResults = $db->read("select * from oldtransaction order by initDate");
while (my $oldTranny = $transactionResults->hashRef) {

View file

@ -18,7 +18,7 @@ use strict;
use Tie::IxHash;
use base 'WebGUI::Asset';
use WebGUI::International;
use WebGUI::Mail::Send;
use WebGUI::Inbox;
use WebGUI::Shop::Cart;
@ -418,13 +418,13 @@ sub onCancelRecurring {
my ($self, $item) = @_;
my $session = $self->session;
my $i18n = WebGUI::International->new($session, "Shop");
my $mail = WebGUI::Mail::Send->new($session, {
my $inbox = WebGUI::Inbox->new($session);
my $message = sprintf $i18n->get('cancel recurring message','Asset_Sku'), $item->transaction->get('orderNumber'), $item->get('configuredTitle'), $item->transaction->get('username');
$inbox->addMessage({
toGroup => $self->session->setting->get('groupIdAdminCommerce'),
subject => $i18n->get('shop notice'),
message => $message,
});
my $message = sprintf $i18n->get('cancel recurring message','Asset_Sku'), $item->transaction->get('orderNumber'), $item->get('configuredTitle'), $item->transaction->get('username');
$mail->addText($message);
$mail->queue;
return undef;
}

View file

@ -65,9 +65,7 @@ TODO: DOCUMENT ME
$hash{'options.display'} = '<a href="'.$session->url->page('op=viewInbox').'">'.$i18n->get(354).'</a>';
push(@array,\%hash);
}
unless ($op eq "redeemSubscriptionCode") {
push(@array, {'options.display' => '<a href="'.$session->url->page('op=redeemSubscriptionCode').'">'.$i18n->get('redeem code', 'Subscription').'</a>'});
}
push(@array, {'options.display' => '<a href="'.$session->url->page('shop=transaction;method=manageMy').'">'.$i18n->get('my purchases', 'Shop').'</a>'});
if ($session->setting->get('userInvitationsEnabled')) {
push @array, {

View file

@ -121,12 +121,18 @@ sub www_editSettings {
$form->submit;
$form->hidden(name=>"shop", value=>"admin");
$form->hidden(name=>"method", value=>"editSettingsSave");
$form->group(
name => "groupIdAdminCommerce",
value => $setting->get("groupIdAdminCommerce"),
label => $i18n->get('who can manage'),
hoverHelp => $i18n->get('who can manage help'),
);
$form->template(
name => "shopCartTemplateId",
value => $setting->get("shopCartTemplateId"),
label => $i18n->get("shopping cart template"),
label => $i18n->get("cart template"),
namespace => "Shop/Cart",
hoverHelp => $i18n->get("shopping cart template help"),
hoverHelp => $i18n->get("cart template help"),
);
$form->template(
name => "shopAddressBookTemplateId",
@ -172,11 +178,11 @@ sub www_editSettingsSave {
my $self = shift;
return $self->session->privilege->adminOnly() unless ($self->session->user->isInGroup("3"));
my ($setting, $form) = $self->session->quick(qw(setting form));
$setting->set("shopMyPurchasesDetailTemplateId", $form->get("shopMyPurchasesDetailTemplateId", "template"));
$setting->set("shopMyPurchasesTemplateId", $form->get("shopMyPurchasesTemplateId", "template"));
$setting->set("shopCartTemplateId", $form->get("shopCartTemplateId", "template"));
$setting->set("shopAddressBookTemplateId", $form->get("shopAddressBookTemplateId", "template"));
$setting->set("shopAddressTemplateId", $form->get("shopAddressTemplateId", "template"));
foreach my $template (qw(shopMyPurchasesDetailTemplateId shopMyPurchasesTemplateId
shopCartTemplateId shopAddressBookTemplateId shopAddressTemplateId)) {
$setting->set($template, $form->get($template, "template"));
}
$setting->set("groupIdAdminCommerce", $form->get("groupIdAdminCommerce", "group"));
return $self->www_editSettings();
}

View file

@ -183,18 +183,11 @@ sub definition {
},
receiptEmailTemplateId => {
fieldType => 'template',
namespace => "Shop/ReceiptEmail",
namespace => "Shop/EmailReceipt",
label => $i18n->get("receipt email template"),
hoverHelp => $i18n->get("receipt email template help"),
defaultValue => '',
},
saleNotificationTemplateId => {
namespace => "Shop/SaleEmail",
fieldType => 'template',
label => $i18n->get("sale notification template"),
hoverHelp => $i18n->get("sale notification template help"),
defaultValue => '',
},
saleNotificationGroupId => {
fieldType => 'group',
label => $i18n->get("sale notification group"),
@ -232,6 +225,21 @@ sub delete {
#-------------------------------------------------------------------
=head2 displayPaymentError ( transaction )
The default error message that gets displayed when a payment is rejected.
=cut
sub displayPaymentError {
my ($self, $transaction) = @_;
my $i18n = WebGUI::International->new($self->session, "PayDriver");
my $output = q{<h1>}.$i18n->get('error processing payment').q{</h1><p>}.$i18n->get('error processing payment message').q{</p><p>}.$transaction->get('statusMessage').{</p>};
return $self->session->style->userStyle($output);
}
#-------------------------------------------------------------------
=head2 get ( [ $param ] )
This is an enhanced accessor for the options property. By default,
@ -521,7 +529,7 @@ sub processTransaction {
if ($success) {
$transaction->completePurchase($transactionCode, $statusCode, $statusMessage);
$cart->onCompletePurchase;
# $self->sendNotifications($transaction);
$self->sendNotifications($transaction);
}
else {
$transaction->denyPurchase($transactionCode, $statusCode, $statusMessage);
@ -551,22 +559,86 @@ Sends out a receipt and a sale notification to the buyer and the store owner res
sub sendNotifications {
my ($self, $transaction) = @_;
my $session = $self->session;
my %var = (); # this needs to be filled in with transaction data for these emails
my $i18n = WebGUI::International->new($session, 'PayDriver');
my ($style, $url) = $session->quick(qw(style url));
my %var = (
%{$transaction->get},
viewDetailUrl => $url->page('shop=transaction;method=viewMy;transactionId='.$transaction->getId,1),
amount => sprintf("%.2f", $transaction->get('amount')),
inShopCreditDeduction => sprintf("%.2f", $transaction->get('inShopCreditDeduction')),
taxes => sprintf("%.2f", $transaction->get('taxes')),
shippingPrice => sprintf("%.2f", $transaction->get('shippingPrice')),
shippingAddress => $transaction->formatAddress({
name => $transaction->get('shippingAddressName'),
address1 => $transaction->get('shippingAddress1'),
address2 => $transaction->get('shippingAddress2'),
address3 => $transaction->get('shippingAddress3'),
city => $transaction->get('shippingCity'),
state => $transaction->get('shippingState'),
code => $transaction->get('shippingCode'),
country => $transaction->get('shippingCountry'),
phoneNumber => $transaction->get('shippingPhoneNumber'),
}),
paymentAddress => $transaction->formatAddress({
name => $transaction->get('paymentAddressName'),
address1 => $transaction->get('paymentAddress1'),
address2 => $transaction->get('paymentAddress2'),
address3 => $transaction->get('paymentAddress3'),
city => $transaction->get('paymentCity'),
state => $transaction->get('paymentState'),
code => $transaction->get('paymentCode'),
country => $transaction->get('paymentCountry'),
phoneNumber => $transaction->get('paymentPhoneNumber'),
}),
);
my $i18n = WebGUI::International->new($session,'PayDriver');
# items
my @items = ();
foreach my $item (@{$transaction->getItems}) {
my $address = '';
if ($transaction->get('shippingAddressId') ne $item->get('shippingAddressId')) {
$address = $transaction->formatAddress({
name => $item->get('shippingAddressName'),
address1 => $item->get('shippingAddress1'),
address2 => $item->get('shippingAddress2'),
address3 => $item->get('shippingAddress3'),
city => $item->get('shippingCity'),
state => $item->get('shippingState'),
code => $item->get('shippingCode'),
country => $item->get('shippingCountry'),
phoneNumber => $item->get('shippingPhoneNumber'),
});
}
push @items, {
%{$item->get},
viewItemUrl => $url->page('shop=transaction;method=viewItem;transactionId='.$transaction->getId.';itemId='.$item->getId, 1),
price => sprintf("%.2f", $item->get('price')),
itemShippingAddress => $address,
orderStatus => $i18n->get($item->get('orderStatus'),'Shop'),
};
}
$var{items} = \@items;
# render
my $template = WebGUI::Asset::Template->new($session, $session->setting->get("receiptEmailTemplateId"));
my $inbox = WebGUI::Inbox->new($session);
$inbox->addMessage({
# purchase receipt
$inbox->addMessage(
message => $template->process(\%var),
subject => $i18n->get('receipt subject').' '.$transaction->get('orderNumber'),
userId => $transaction->get('userId'),
subject => $i18n->get('thank you for your order'),
message => WebGUI::Asset::Template->new($session, $self->get('receiptEmailTemplateId'))->process(\%var),
status => 'completed',
});
$inbox->addMessage({
);
# shop owner notification
$var{viewDetailUrl} = $url->page('shop=transaction;method=view;transactionId='.$transaction->getId,1);
$inbox->addMessage(
message => $template->process(\%var),
subject => $i18n->get('a sale has been made').' '.$transaction->get('orderNumber'),
groupId => $self->get('saleNotificationGroupId'),
subject => $i18n->get('a sale has been made'),
message => WebGUI::Asset::Template->new($session, $self->get('saleNotificationTemplateId'))->process(\%var),
status => 'completed',
});
status => 'unread',
);
}
#-------------------------------------------------------------------

View file

@ -28,32 +28,6 @@ sub definition {
my $i18n = WebGUI::International->new($session, 'PayDriver_Cash');
tie my %fields, 'Tie::IxHash';
%fields = (
sendReceipt => {
fieldType => 'yesNo',
label => $i18n->echo('send receipt'),
hoverHelp => $i18n->echo('send receipt help'),
defaultValue => 0,
},
receiptFromAddress => {
fieldType => 'email',
label => $i18n->echo('receipt from address'),
hoverHelp => $i18n->echo('receipt from address help'),
defaultValue => $session->setting->get('companyEmail'),
},
receiptSubject => {
fieldType => 'text',
label => $i18n->echo('receipt subject'),
hoverHelp => $i18n->echo('receipt subject help'),
},
receiptTemplate => {
fieldType => 'template',
label => $i18n->echo('receipt template'),
hoverHelp => $i18n->echo('receipt template help'),
namespace => 'PayDriver/Cash/Receipt',
defaultValue => undef,
},
);
push @{ $definition }, {
name => $i18n->echo('Cash'),
@ -88,44 +62,6 @@ sub getButton {
return $payForm;
}
#-------------------------------------------------------------------
sub getCartTemplateVariables {
my $self = shift;
my $cart = $self->getCart;
my @itemLoop;
# Process items in cart
foreach my $item (@{ $cart->getItems }) {
my $sku = $item->getSku;
$sku->applyOptions( $item->get('options') );
# Item properties
my $itemProperties = $item->get;
$itemProperties->{ itemName } = $sku->get('title');
$itemProperties->{ itemUrl } = $sku->getUrl;
$itemProperties->{ itemPrice } = $cart->formatCurrency( $sku->getPrice );
$itemProperties->{ totalItemPrice } = $cart->formatCurrency( $sku->getPrice * $item->get('quantity') );
# Custom item shipping address
my $address = eval { $item->getShippingAddress };
$itemProperties->{ itemShippingAddres } = $address->getHtmlFormatted unless (WebGUI::Error->caught);
push @itemLoop, $itemProperties;
}
my $cartProperties = $cart->get;
$cartProperties->{ totalPrice } = $cart->calculateSubtotal;
$cartProperties->{ tax } = $cart->calculateTaxes;
# Include shipping address
my $address = eval { $cart->getShippingAddress };
$cartProperties->{ shippingAddress } = $address->getHtmlFormatted unless (WebGUI::Error->caught);
# $cartProperties->{ shippingPrice } =
$cartProperties->{ item_loop } = \@itemLoop;
return $cartProperties;
}
#-------------------------------------------------------------------
@ -198,30 +134,8 @@ sub www_pay {
my $billingAddress = $self->getAddress( $session->form->process('addressId') );
return $self->www_getCredentials unless $billingAddress;
# Generate a receipt and send it if enabled.
if ( $self->get('sendReceipt') ) {
# Setup receipt tmpl_vars
my $var = $self->getCartTemplateVariables;
# Instanciate receipt template
my $template = WebGUI::Asset::Template->new( $session, $self->get('receiptTemplate') );
WebGUI::Error::ObjectNotFound->throw( id => $self->get('receiptTemplate') )
unless $template;
# Send receipt
my $receipt = WebGUI::Mail::Send->create( $session, {
to => $session->user->profileField('email'),
from => $self->get('receiptFromAddress'),
subject => $self->get('receiptSubject'),
});
$receipt->addText( $template->process( $var ) );
$receipt->queue;
}
# Complete the transaction
my $transaction = $self->processTransaction( $billingAddress );
return $transaction->thankYou();
}

View file

@ -594,8 +594,10 @@ sub www_pay {
# Payment time!
my $transaction = $self->processTransaction;
return $transaction->thankYou();
if ($transaction->get('isSuccessful')) {
return $transaction->thankYou();
}
return $self->displayPaymentError($transaction);
}
1;

View file

@ -8,6 +8,7 @@ use WebGUI::Asset::Template;
use WebGUI::Exception::Shop;
use WebGUI::Form;
use WebGUI::International;
use WebGUI::Inbox;
use WebGUI::Paginator;
use WebGUI::Shop::Admin;
use WebGUI::Shop::AddressBook;
@ -354,6 +355,27 @@ sub getPaymentGateway {
}
#-------------------------------------------------------------------
=head2 getTransactionIdsForUser (session, [ userId ])
Returns an array reference of transactionIds for a given user ordered by date descending. Class method.
=head3 userId
The id of the user to fetch transactions for. Defaults to the current user.
=cut
sub getTransactionIdsForUser {
my ($class, $session, $userId) = @_;
unless (defined $userId) {
$userId = $session->user->userId;
}
return $session->db->buildArrayRef("select transactionId from transaction where userId=? order by dateOfPurchase desc",[$userId]);
}
#-------------------------------------------------------------------
=head2 new ( session, transactionId )
@ -437,8 +459,6 @@ sub newByGatewayId {
return $class->new( $session, $transactionId );
}
#-------------------------------------------------------------------
=head2 thankYou ()
@ -745,6 +765,34 @@ STOP
}
#-------------------------------------------------------------------
=head2 www_manageMy ()
Makes transaction information printable.
=cut
sub www_manageMy {
my ($class, $session) = @_;
my %var = ();
my $url = $session->url;
# build list
foreach my $id (@{$class->getTransactionIdsForUser($session)}) {
my $transaction = $class->new($session, $id);
push @{$var{transactions}}, {
%{$transaction->get},
viewDetailUrl => $url->page('shop=transaction;method=viewMy;transactionId='.$id),
amount => sprintf("%.2f", $transaction->get('amount')),
};
}
# render
my $template = WebGUI::Asset::Template->new($session, $session->setting->get("shopMyPurchasesTemplateId"));
return $session->style->userStyle($template->process(\%var));
}
#-------------------------------------------------------------------
=head2 www_print ()

View file

@ -3,36 +3,36 @@ package WebGUI::i18n::English::PayDriver;
use strict;
our $I18N = {
'thank you for your order' => {
message => q|Thank You For Your Order|,
lastUpdated => 0,
context => q|commerce setting|
'receipt subject' => {
message => q|Receipt for Order #|,
lastUpdated => 0,
context => q|notice after purchase|,
},
'a sale has been made' => {
message => q|A Sale Has Been Made|,
message => q|A sale has been made. Order #|,
lastUpdated => 0,
context => q|commerce setting|
},
'sale notification template' => {
message => q|Sale Notification Template|,
lastUpdated => 0,
context => q|commerce setting|
},
'sale notification template help' => {
message => q|Which template should be used to generate the email that notifies this store owner about a new sale.|,
lastUpdated => 0,
context => q|commerce setting help|
},
'sale notification group' => {
message => q|Sale Notification Group|,
lastUpdated => 0,
context => q|commerce setting|
},
'error processing payment' => {
message => q|Error Processing Payment|,
lastUpdated => 0,
context => q|the title of the error screen|
},
'error processing payment message' => {
message => q|There has been an error processing your payment. Usually this is caused by typing errors. However, there may be a connectivity problem, or your account may not have the funds required to complete this transaction. The error message we received is below. Use your browser's back button to go back and correct mistakes. If this problem persists please contact us.|,
lastUpdated => 0,
context => q|the description on the error screen|
},
'sale notification group help' => {
message => q|Who should be notified of new transactions?|,
lastUpdated => 0,

View file

@ -4,7 +4,7 @@ use strict;
our $I18N = {
'thank you message' => {
message => q|Thank you for your order! Please print this page as your receipt.|,
message => q|Thank you for your order! Please save this as your receipt.|,
lastUpdated => 0,
context => q|notice after purchase|,
},
@ -44,13 +44,7 @@ our $I18N = {
lastUpdated => 0,
context => q|a help title|,
},
'edit address template' => {
message => q|Edit Address Template|,
lastUpdated => 0,
context => q|a help title|,
},
'cart template' => {
message => q|Cart Template|,
lastUpdated => 0,
@ -256,23 +250,29 @@ our $I18N = {
},
'cart template help' => {
message => q|The following variables are available in the shopping cart template.|,
message => q|This template determines what the shopping cart looks like.|,
lastUpdated => 0,
context => q|a help description|,
},
'address book template help' => {
message => q|The following variables are available for templating the Address Book.|,
message => q|This template determines what the address book will look like.|,
lastUpdated => 0,
context => q|a help description|,
},
'address book template help' => {
message => q|The following variables are available from in the address book template.|,
'who can manage help' => {
message => q|The group that has management rights over commerce.|,
lastUpdated => 0,
context => q|a help description|,
},
'who can manage' => {
message => q|Who can manage?|,
lastUpdated => 0,
context => q|a setting|,
},
'address loop help' => {
message => q|A loop containing the list of addresses in this book and their management tools.|,
lastUpdated => 0,
@ -309,12 +309,6 @@ our $I18N = {
context => q|a help description|,
},
'edit address template help' => {
message => q|The following variables are available in the edit address template.|,
lastUpdated => 0,
context => q|a help description|,
},
'saveButton help' => {
message => q|The default save button for the form.|,
lastUpdated => 0,
@ -387,6 +381,12 @@ our $I18N = {
context => q|a link label|,
},
'my purchases' => {
message => q|My Purchases|,
lastUpdated => 0,
context => q|a screen heading|
},
'my purchases template' => {
message => q|My Purchases Template|,
lastUpdated => 0,
@ -543,30 +543,12 @@ our $I18N = {
context => q|button in shipping manager|
},
'shopping cart template' => {
message => q|Cart Template|,
lastUpdated => 0,
context => q|commerce setting|
},
'shopping cart template help' => {
message => q|Choose the template that you want used to render the shopping cart.|,
lastUpdated => 0,
context => q|commerce setting help|
},
'address book template' => {
message => q|Address Book Template|,
lastUpdated => 0,
context => q|commerce setting|
},
'address book template help' => {
message => q|Choose the template you want used to render the address book.|,
lastUpdated => 0,
context => q|commerce setting help|
},
'edit address template' => {
message => q|Edit Address Template|,
lastUpdated => 0,
@ -574,7 +556,7 @@ our $I18N = {
},
'edit address template help' => {
message => q|Choose the template you want used to render the address edit form.|,
message => q|This template determines what the address editor will look like.|,
lastUpdated => 0,
context => q|commerce setting help|
},