added email receipt and "my purchases" page
This commit is contained in:
parent
93454e36f9
commit
74b3d3def6
10 changed files with 203 additions and 181 deletions
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue