X-Git-Url: http://git.freeside.biz/gitweb/?p=Business-OnlinePayment-Bambora.git;a=blobdiff_plain;f=lib%2FBusiness%2FOnlinePayment%2FBambora.pm;fp=lib%2FBusiness%2FOnlinePayment%2FBambora.pm;h=a61cda05516ca47c23647d0589cf1665f4766b1b;hp=9d07c5ae8ba1d9d3200500ac5a22cd00dbb5ef4f;hb=a2c0deaa1ef38f442ac596cd61c6373277aa7258;hpb=40669843fb6bf03fd80cb0311cdfa90aec55bb1a diff --git a/lib/Business/OnlinePayment/Bambora.pm b/lib/Business/OnlinePayment/Bambora.pm index 9d07c5a..a61cda0 100755 --- a/lib/Business/OnlinePayment/Bambora.pm +++ b/lib/Business/OnlinePayment/Bambora.pm @@ -122,6 +122,30 @@ sub submit_normal_authorization { } $self->path('/v1/payments'); + my $response = $self->submit_api_request( $post_body ); + + # Error messages already populated upon failure + return unless $self->is_success; + + # Populate transaction result values + $self->message_id( $response->{message_id} ); + $self->authorization( $response->{auth_code} ); + $self->order_number( $response->{id} ); + $self->txn_date( $response->{created} ); + $self->avs_code( $response->{card}{avs_result} ); + $self->is_success( 1 ); +} + +=head2 submit_api_request json_string + +Make the appropriate API request with the given JSON string + +=cut + +sub submit_api_request { + my $self = shift; + my $post_body = shift + or die 'submit_api_request() requires a json_string parameter'; my ( $response_body, $response_code, %response_headers ) = $self->https_post( { @@ -146,16 +170,20 @@ sub submit_normal_authorization { }); } - # API should always return a JSON response, - die $response_body || 'connection error' - if $@ || !$response; + # API should always return a JSON response, likely network problem + if ( $@ || !$response ) { + $self->error_message( $response_body || 'connection error' ); + $self->is_success( 0 ); + return; + } } $self->response_decoded( $response ); + # Response returned an error if ( $response->{code} && $response->{code} != 1 ) { - $self->is_success( 0 ); $self->result_code( $response->{code} ); + return $self->error_message( sprintf '%s %s', $response->{code}, @@ -163,28 +191,11 @@ sub submit_normal_authorization { ); } - # success - # Populate transaction result values - $self->message_id( $response->{message_id} ); - $self->authorization( $response->{auth_code} ); - $self->order_number( $response->{id} ); - $self->txn_date( $response->{created} ); - $self->avs_code( $response->{card}{avs_result} ); + # Success + # Return the decoded json of the response back to handler $self->is_success( 1 ); -} - -=head2 submit_api_request json_string - -Make the appropriate API request with the given JSON string - -=cut - -sub submit_api_request { - my $self = shift; - my $json_string = shift - or die 'submit_api_request() requires a json_string parameter'; + return $response; - } =head2 submit_action_unsupported