Add common cart summary template variables to the PayDriver. Add a summary screen for Cash. i18n fixes for Cash.

This commit is contained in:
Colin Kuskie 2010-04-28 11:19:34 -07:00
parent d48d9bc90f
commit a472f9ebdd
5 changed files with 106 additions and 67 deletions

View file

@ -78,15 +78,11 @@ The amount to calculate the deduction against. Defaults to calculateTotal().
sub calculateShopCreditDeduction {
my ($self, $total) = @_;
# cannot use in-shop credit on recurring items
foreach my $item (@{$self->getItems}) {
if ($item->getSku->isRecurring) {
return $self->formatCurrency(0);
}
}
unless (defined $total) {
$total = $self->calculateTotal
}
# cannot use in-shop credit on recurring items
return $self->formatCurrency(0) if $self->requiresRecurringPayment;
return $self->formatCurrency(WebGUI::Shop::Credit->new($self->session, $self->get('posUserId'))->calculateDeduction($total));
}

View file

@ -80,6 +80,33 @@ sub _buildObj {
}
#-------------------------------------------------------------------
=head2 appendCartVariables ( $var )
Append the subtotal, shipping, tax, and shop credeductions to a set of template
variables.
=cut
sub appendCartVariables {
my ($self, $var) = @_;
$var ||= {};
my $cart = $self->getCart;
$var->{shippableItemsInCart} = $cart->requiresShipping;
$var->{subtotal} = $cart->calculateSubtotal;
$var->{shipping} = $cart->calculateShipping;
$var->{taxes} = $cart->calculateTaxes;
my $totalPrice = $var->{subtotal} + $var->{shipping} + $var->{taxes};
my $session = $self->session;
my $credit = WebGUI::Shop::Credit->new($session, $cart->getPosUser->userId);
$var->{inShopCreditAvailable} = $credit->getSum;
$var->{inShopCreditDeduction} = $credit->calculateDeduction($var->{totalPrice});
$var->{totalPrice } = $self->formatCurrency($totalPrice + $var->{inShopCreditDeduction});
return $self;
}
#-------------------------------------------------------------------
=head2 cancelRecurringPayment ( transaction )

View file

@ -55,6 +55,15 @@ sub definition {
my $i18n = WebGUI::International->new($session, 'PayDriver_Cash');
tie my %fields, 'Tie::IxHash';
%fields = (
summaryTemplateId => {
fieldType => 'template',
label => $i18n->get('summary template'),
hoverHelp => $i18n->get('summary template help'),
namespace => 'Shop/Credentials',
defaultValue => '30h5rHxzE_Q0CyI3Gg7EJw',
},
);
push @{ $definition }, {
name => $i18n->get('label'),
@ -92,46 +101,28 @@ sub www_getCredentials {
my ($self, $addressId) = @_;
my $session = $self->session;
# Process address from address book if passed
$addressId = $session->form->process( 'addressId' );
my $address;
if ( $addressId ) {
$address = eval{ $self->getAddress( $addressId ) };
}
else {
$address = $self->getCart->getShippingAddress;
}
my $billingAddressHtml = $address->getHtmlFormatted;
# Generate the json string that defines where the address book posts the selected address
my $callbackParams = {
url => $session->url->page,
params => [
{ name => 'shop', value => 'pay' },
{ name => 'method', value => 'do' },
{ name => 'do', value => 'setBillingAddress' },
{ name => 'paymentGatewayId', value => $self->getId },
],
};
my $callbackJson = JSON::to_json( $callbackParams );
# Generate 'Choose billing address' button
my $addressButton = WebGUI::Form::formHeader( $session )
. WebGUI::Form::hidden( $session, { name => 'shop', value => 'address' } )
. WebGUI::Form::hidden( $session, { name => 'method', value => 'view' } )
. WebGUI::Form::hidden( $session, { name => 'callback', value => $callbackJson } )
. WebGUI::Form::submit( $session, { value => 'Choose billing address' } )
. WebGUI::Form::formFooter( $session);
# Generate 'Proceed' button
my $proceedButton = WebGUI::Form::formHeader( $session )
. $self->getDoFormTags('pay')
. WebGUI::Form::hidden($session, {name=>"addressId", value=>$address->getId})
. WebGUI::Form::submit( $session, { value => 'Pay' } )
. WebGUI::Form::formFooter( $session);
my $i18n = WebGUI::International->new($session, 'PayDriver_Cash');
my $var = {
proceedButton => WebGUI::Form::formHeader( $session )
. $self->getDoFormTags('pay')
. WebGUI::Form::submit( $session, { value => $i18n->get('Pay') } )
. WebGUI::Form::formFooter( $session)
,
};
$self->appendCartVariables($var);
return $session->style->userStyle($addressButton.'<br />'.$billingAddressHtml.'<br />'.$proceedButton);
my $template = WebGUI::Asset::Template->new($session, $self->get("summaryTemplateId"));
my $output;
if (defined $template) {
$template->prepare;
$output = $template->process($var);
}
else {
$output = $i18n->get('template gone', 'PayDriver_ITransact');
}
return $session->style->userStyle($output);
}
#-------------------------------------------------------------------
@ -144,36 +135,14 @@ Checks credentials, and completes the transaction if those are correct.
sub www_pay {
my $self = shift;
my $session = $self->session;
my $cart = $self->getCart;
my $i18n = WebGUI::International->new($session, 'PayDriver_Cash');
my $var;
# Make sure we can checkout the cart
return "" unless $self->canCheckoutCart;
# Make sure all required credentials have been supplied
my $billingAddress = $self->getAddress( $session->form->process('addressId') );
return $self->www_getCredentials unless $billingAddress;
# Complete the transaction
my $transaction = $self->processTransaction( $billingAddress );
my $transaction = $self->processTransaction( );
return $transaction->thankYou();
}
#-------------------------------------------------------------------
=head2 www_setBillingAddress {
Stores the selected billing address in this instance.
=cut
sub www_setBillingAddress {
my $self = shift;
my $session = $self->session;
return $self->www_getCredentials($session->form->process('addressId'));
}
1;

View file

@ -158,6 +158,33 @@ our $I18N = {
message => q|When set to 'yes', the transaction is completed when the user submits payment details. When set to 'no', the transaction is set to pending and must be manually set to complete. This may be useful if you wish to allow site visitors to select the Cash Payment method, but would like to wait for payment to clear before completing the transaction.|,
lastUpdated => 0,
},
'summary template' => {
message => q|Summary Template|,
lastUpdated => 0,
context => q|Form label in the configuration form of the Cash module.|
},
'summary template help' => {
message => q|Pick a template to display the screen where the user confirms the cart summary info and agrees to pay.|,
lastUpdated => 0,
context => q|Hover help for the summary template field in the configuration form of the Cash module.|
},
'password' => {
message => q|Password|,
lastUpdated => 0,
context => q|Form label in the configuration form of the iTransact module.|
},
'password help' => {
message => q|The password for your ITransact account.|,
lastUpdated => 0,
context => q|Hover help for the password field in the configuration form of the iTransact module.|
},
'Pay' => {
message => q|Pay|,
lastUpdated => 0,
context => q|Button label|
},
};
1;