Getnet DocsGetnet Docs

Handle Transaction Results

This guide walks you through handling transaction results returned by the Get Mini application. You’ll learn how to register a result callback, check the result code, and extract transaction data from the response.

Requirements

Before following the steps, ensure you have:

Always register your result launcher before launching any transaction Intent.

Result Handling Process

This section guides you through implementing the result callback to process transaction responses from the Get Mini application.

Step 1: Register the Activity Result Launcher

Register an ActivityResultLauncher in your Activity’s onCreate() method or Fragment’s initialization. This launcher will receive the callback when the Get Mini app completes the transaction.

The following code shows how to register the launcher:

ActivityResultLauncher<Intent> paymentLauncher = registerForActivityResult(
    new ActivityResultContracts.StartActivityForResult(),
    result -> {
        // Handle the result here
        handleTransactionResult(result);
    }
);

Step 2: Check the Result Code

When the Get Mini app returns control to your application, first check the result code. A result code of RESULT_OK indicates the operation completed successfully, while RESULT_CANCELED indicates it was cancelled or failed.

private void handleTransactionResult(ActivityResult result) {
    if (result.getResultCode() == Activity.RESULT_OK) {
        // Transaction successful
        processSuccessfulTransaction(result.getData());
    } else if (result.getResultCode() == Activity.RESULT_CANCELED) {
        // Transaction cancelled or failed
        processFailedTransaction(result.getData());
    }
}

Step 3: Extract Transaction Data

Extract the relevant data from the Intent extras based on the operation type. For successful payments, you’ll receive authorization numbers and receipt paths. For failures, you’ll receive error messages and state codes.

private void processSuccessfulTransaction(Intent data) {
    if (data != null) {
        String authNumber = data.getStringExtra("AUTHORIZATION_NUMBER");
        String order = data.getStringExtra("ORDER");
        String state = data.getStringExtra("STATE");

        // Display success message
        showSuccessMessage("Payment approved. Auth: " + authNumber);
    }
}

private void processFailedTransaction(Intent data) {
    if (data != null) {
        String errorMsg = data.getStringExtra("ERROR_MSG");
        String state = data.getStringExtra("STATE");

        // Display error message
        showErrorMessage("Transaction failed: " + errorMsg);
    }
}

Even when the result code is RESULT_CANCELED, the Intent extras often contain valuable debugging information in the ERROR_MSG and STATE fields. Always parse the extras to provide meaningful feedback to the user.

Next Steps

Now that you know how to handle transaction results, you can: