Handling errors

You can use the PaymentReply::isError() function to check whether a PaymentManager request succeeds or fails. If a request fails, use errorCode() and errorText() to identify why the request failed.

You can see how errors are handled in the following code sample:

// This differentiates between successful responses 
// and error responses and emits appropriate signal 
// for each.

void PaymentServiceControl::purchaseResponse()
{
    bb::platform::PurchaseReply *reply = 
        qobject_cast<bb::platform::PurchaseReply*>(sender());
    Q_ASSERT(reply);

    // Emit an error signal if there were errors.
    if (reply->isError()) {

		emit infoResponseError(reply->errorCode(), 
                                reply->errorText());

    // Emit a success signal if the request succeeded.
    } else {
        const QString displayString = 
            receiptToString(reply->receipt());

        emit purchaseResponseSuccess(displayString);
    }

    reply->deleteLater();
}

Handling error codes Since 10.2

You can use the errorCode() function to identify why a payment transaction failed. The errorCode() function returns a PaymentErrorCode, with one of the following values:

PaymentErrorCode::None

This error code is returned when the PaymentReply is unfinished or the payment finished successfully.

PaymentErrorCode::Canceled

This error is returned when a user cancels the request.

PaymentErrorCode::Busy

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

PaymentErrorCode::Failed

This error is returned when a payment transaction fails. More information is provided in errorText and errorInfo.

PaymentErrorCode::NoNetwork

This error is returned when the device is not connected to a network. The request cannot be completed until the device connects to a network.

After you check the PaymentErrorCode and identify the type of error, you can find out more specific information about the error by using errorText() and errorInfo().

void MyApp::handleError(PaymentReply *reply) {

	log_fail("ErrorCode: " + QString::number(reply->errorCode()));
	log_fail("ErrorText: " + reply->errorText());
	log_fail("ErrorInfo: " + reply->errorInfo());

}

The errorCode() function returns one of the PaymentErrorCode values, indicating a success or failure status. The errorText() contains a localized message describing the problem. The errorInfo() is attached to the errorText() message along with a series of tags (for example, AW30242PWAT) that help to identify the context of an error. The information provided in errorInfo() helps to diagnose errors. For a list of errorInfo() values, see Payment Service error messages.

Last modified: 2013-12-21

comments powered by Disqus