Handling errors

The Payment Service response provides error_id and error_text attributes. You can also use the error_info attribute to find out more about the error.

/**
 * Handle the failure case for either event. 
 * Format a string that has the error information in it.
 */
void failureCommon(bps_event_t *event, char** buffer)
{
    unsigned request_id = 
        paymentservice_event_get_request_id(event);

    int error_id = 
        paymentservice_event_get_error_id(event);

    const char* error_info = 
        paymentservice_event_get_error_info(event);

    const char* error_text = 
        paymentservice_event_get_error_text(event);

    char *errorIDmatch = NULL;

    switch(error_id) {
        case PAYMENTSERVICE_ERROR_USER_CANCELLED:
            errorIDmatch = 
                "Error was PAYMENTSERVICE_ERROR_USER_CANCELLED.";
            break;
        case PAYMENTSERVICE_ERROR_SYSTEM_BUSY:
            errorIDmatch = 
                "Error was PAYMENTSERVICE_ERROR_SYSTEM_BUSY.";
            break;
        case PAYMENTSERVICE_ERROR_PAYMENTSERVICE_FAILED:
            errorIDmatch = 
                "Error was PAYMENTSERVICE_ERROR_PAYMENTSERVICE_FAILED.";
            break;
        case PAYMENTSERVICE_ERROR_NO_NETWORK:
            errorIDmatch = 
                "Error was PAYMENTSERVICE_ERROR_NO_NETWORK.";
            break;
        default:
            errorIDmatch = 
                "Error did not match any paymentservice_error_t's!";
            break;
    }

    sprintf(*buffer, 
        "PS FAILURE. RequestID: %d\n Error ID: %d\n Error Info: %s\n %s\n %s", 
        request_id, 
        error_id, 
        error_info?error_info:"n/a", 
        error_text?error_text:"n/a", 
        errorIDmatch?errorIDmatch:"");
}

You can use the paymentservice_event_get_error_id function to determine why a payment transaction failed. The paymentservice_event_get_error_id returns a paymentservice_event_get_error_code, which can be one of the following values:

  • PAYMENTSERVICE_ERROR_USER_CANCELLED = 1

    This error occurs when a user cancels the request.

  • PAYMENTSERVICE_ERROR_SYSTEM_BUSY = 2

    This error occurs when a user tries to purchase more than one item at a time.

  • PAYMENTSERVICE_ERROR_PAYMENTSERVICE_FAILED = 3

    If this error is received, you can use paymentservice_event_get_error_text() and paymentservice_event_get_error_info() for more information.

  • PAYMENTSERVICE_ERROR_NO_NETWORK = 8

    This error occurs when there is no network connectivity on the device. The request cannot be completed until the BlackBerry device connects to a network.

You can use the paymentservice_event_get_error_code to run code that checks the next level of error information, which is found in paymentservice_event_get_error_text and paymentservice_event_get_error_info.

The error_text contains a localized message describing the problem. The error_info is attached to the error_text message along with a series of tags (for example, AW30242PWAT) which help identify the context of an error.

The paymentservice_event_get_error_info contains an error code that originates from the Payment Service, the BlackBerry World storefront, PayPal, or Digital River. When an error occurs, the paymentservice_event_get_error_info function returns a detailed error code. You can use this error code to identify the context of the error. For a list of error codes, see Payment Service error messages.

Last modified: 2014-09-30



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus