diff --git a/lib/WebGUI/Shop/PayDriver.pm b/lib/WebGUI/Shop/PayDriver.pm index 9ee1cec62..b432660f2 100644 --- a/lib/WebGUI/Shop/PayDriver.pm +++ b/lib/WebGUI/Shop/PayDriver.pm @@ -268,6 +268,29 @@ sub get { #------------------------------------------------------------------- +=head2 getAddress ( addressId ) + +Returns an instantiated WebGUI::Shop::Address object for the passed address id. + +=head3 addressId + +The id of the adress to instantiate. + +=cut + +sub getAddress { + my $self = shift; + my $addressId = shift; + + if ($addressId) { + return $self->getCart->getAddressBook->getAddress( $addressId ); + } + + return undef; +} + +#------------------------------------------------------------------- + =head2 getButton ( ) Returns the form that will take the user to check out. diff --git a/lib/WebGUI/Shop/PayDriver/Cash.pm b/lib/WebGUI/Shop/PayDriver/Cash.pm index a19f34f50..07b0e152c 100644 --- a/lib/WebGUI/Shop/PayDriver/Cash.pm +++ b/lib/WebGUI/Shop/PayDriver/Cash.pm @@ -37,16 +37,6 @@ sub definition { return $class->SUPER::definition($session, $definition); } -#------------------------------------------------------------------- -sub getAddress { - my ($self, $addressId) = @_; - if ($addressId) { - return $self->getCart->getAddressBook->getAddress( $addressId ); - } - # No billing address selected yet so return undef. - return undef; -} - #------------------------------------------------------------------- sub getButton { diff --git a/lib/WebGUI/Shop/PayDriver/ITransact.pm b/lib/WebGUI/Shop/PayDriver/ITransact.pm index 2259a7f11..7af443c9d 100644 --- a/lib/WebGUI/Shop/PayDriver/ITransact.pm +++ b/lib/WebGUI/Shop/PayDriver/ITransact.pm @@ -550,8 +550,8 @@ sub processPayment { # Process response if ($response->is_success) { # We got some XML back from iTransact, now parse it. - $session->errorHandler->info('Starting request'); - my $transactionResult = XMLin( $response->content ); + my $transactionResult = XMLin( $response->content, SuppressEmpty => '' ); + #### TODO: More checking: price, address, etc unless (defined $transactionResult->{ TransactionData }) { # GatewayFailureResponse: This means the xml is invalid or has the wrong mime type @@ -574,7 +574,9 @@ sub processPayment { my $gatewayCode = $transactionData->{ XID }; my $isSuccess = $status eq 'OK'; - return ( $isSuccess, $gatewayCode, $status, "" ); + my $message = ($errorCategory) ? " $errorMessage Category: $errorCategory" : $errorMessage; + + return ( $isSuccess, $gatewayCode, $status, $message ); } } else { # Connection Error @@ -597,7 +599,7 @@ sub www_getCredentials { my $addressId = $session->form->process('addressId'); my $addressData = {}; if ( $addressId ) { - $addressData = eval{ $self->getCart->getAddressBook->getAddress( $addressId )->get() } || {}; + $addressData = eval{ $self->getAddress( $addressId )->get() } || {}; } my $output; @@ -690,9 +692,9 @@ sub www_getCredentials { #------------------------------------------------------------------- sub www_pay { - my $self = shift; - my $session = $self->session; - my $addressId = $session->form->process( 'addressId' ) || undef; + my $self = shift; + my $session = $self->session; + my $address = $self->getAddress( $session->form->process( 'addressId' ) ); # Check whether the user filled in the checkout form and process those. my $credentialsErrors = $self->processCredentials; @@ -701,7 +703,7 @@ sub www_pay { return $self->www_getCredentials( $credentialsErrors ) if $credentialsErrors; # Payment time! - my $transaction = $self->processTransaction( $addressId ); + my $transaction = $self->processTransaction( $address ); if ($transaction->get('isSuccessful')) { return $transaction->thankYou(); }