diff --git a/docs/upgrades/upgrade_7.9.3-7.9.4.pl b/docs/upgrades/upgrade_7.9.3-7.9.4.pl
index d247e6ddb..862559599 100644
--- a/docs/upgrades/upgrade_7.9.3-7.9.4.pl
+++ b/docs/upgrades/upgrade_7.9.3-7.9.4.pl
@@ -24,6 +24,7 @@ use WebGUI::Storage;
use WebGUI::Asset;
use WebGUI::Asset::WikiPage;
use WebGUI::Exception;
+use WebGUI::Shop::Pay;
my $toVersion = '7.9.4';
@@ -40,6 +41,7 @@ alterCartTable($session);
alterAddressBookTable($session);
addWizardHandler( $session );
addTemplateExampleImage( $session );
+addPayDriverTemplates( $session );
finish($session); # this line required
@@ -150,6 +152,24 @@ sub alterCartTable {
print "DONE!\n" unless $quiet;
}
+#----------------------------------------------------------------------------
+sub addPayDriverTemplates {
+ my $session = shift;
+ print "\tAdd templates to the Payment Drivers that need them... " unless $quiet;
+ # and here's our code
+ my $pay = WebGUI::Shop::Pay->new($session);
+ my @gateways = @{ $pay->getPaymentGateways };
+ GATEWAY: foreach my $gateway (@gateways) {
+ next GATEWAY unless $gateway;
+ my $properties = $gateway->get;
+ if ($gateway->isa('WebGUI::Shop::PayDriver::Cash')) {
+ $properties->{summaryTemplateId} = '30h5rHxzE_Q0CyI3Gg7EJw';
+ }
+ $gateway->update($properties);
+ }
+ print "DONE!\n" unless $quiet;
+}
+
# -------------- DO NOT EDIT BELOW THIS LINE --------------------------------
#----------------------------------------------------------------------------
diff --git a/lib/WebGUI/Shop/Cart.pm b/lib/WebGUI/Shop/Cart.pm
index 8396e1486..f33ead3b4 100644
--- a/lib/WebGUI/Shop/Cart.pm
+++ b/lib/WebGUI/Shop/Cart.pm
@@ -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));
}
diff --git a/lib/WebGUI/Shop/PayDriver.pm b/lib/WebGUI/Shop/PayDriver.pm
index 055600090..fbeb56eba 100644
--- a/lib/WebGUI/Shop/PayDriver.pm
+++ b/lib/WebGUI/Shop/PayDriver.pm
@@ -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 )
diff --git a/lib/WebGUI/Shop/PayDriver/Cash.pm b/lib/WebGUI/Shop/PayDriver/Cash.pm
index d0d8afb5c..348adfe1c 100644
--- a/lib/WebGUI/Shop/PayDriver/Cash.pm
+++ b/lib/WebGUI/Shop/PayDriver/Cash.pm
@@ -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.'
'.$billingAddressHtml.'
'.$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;
-
diff --git a/lib/WebGUI/i18n/English/PayDriver_Cash.pm b/lib/WebGUI/i18n/English/PayDriver_Cash.pm
index e41f35d62..2e75be4b4 100644
--- a/lib/WebGUI/i18n/English/PayDriver_Cash.pm
+++ b/lib/WebGUI/i18n/English/PayDriver_Cash.pm
@@ -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;