}
$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(
{
});
}
- # 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},
);
}
- # 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