# Handle Transaction Results

This guide explains how to capture and process the results of a payment or refund transaction initiated by your application.

After you launch the payment intent using `startActivityForResult`, the Get Smart application processes the transaction. Upon completion (or cancellation), it returns control to your application via the standard Android `onActivityResult` callback. You must implement this method to determine if the transaction was successful and to extract relevant financial data.

## Understanding Result Codes

The transaction result involves two levels of status checking:

1. **Android Result Code**: Indicates if the Get Smart app completed its flow  
2. **Transaction Result**: Indicates if the payment was authorized

## Step 1: Implement onActivityResult

Override the `onActivityResult` method in your Activity. You need to verify two things:

1. Ensure the result matches the request code you defined when starting the intent  
2. Check the standard Android result code to see if the operation finished or was canceled

```java
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == REQUEST_CODE_PAYMENT) {
        if (resultCode == RESULT_OK) {
            // The flow completed. Check if the payment was authorized.
            processTransactionResponse(data);
        } else if (resultCode == RESULT_CANCELED) {
            // The user canceled the operation
            handleCancellation();
        }
    }
}
```

### Android Result Codes

| Result Code | Meaning |
|------------|---------|
| `RESULT_OK` | The Get Smart app completed its flow and returned a result (which could be authorization or denial) |
| `RESULT_CANCELED` | The user canceled the operation or the system aborted it |

<Callout type="warning">

`RESULT_OK` does **not** mean the payment was authorized. It only means the Get Smart app completed its process without crashing or being cancelled. You must parse the extras to verify the financial status.

</Callout>

## Step 2: Parse Transaction Response

If the `resultCode` is `RESULT_OK`, the `Intent data` object contains "extras" with the details of the transaction. You need to extract these values to determine the final status.

### Check Authorization Status

The most critical field is `RESULT`, which tells you if the bank authorized the transaction:

```java
private void processTransactionResponse(Intent data) {
    if (data == null) {
        Log.e("Payment", "No data returned from payment app");
        return;
    }

    // Extract the main status
    String operationResult = data.getStringExtra("RESULT");

    if ("AUTORIZADA".equals(operationResult)) {
        // Payment was authorized
        handleAuthorizedTransaction(data);
    } else if ("DENEGADA".equals(operationResult)) {
        // Payment was denied
        handleDeniedTransaction(data);
    } else {
        // Unexpected result
        Log.e("Payment", "Unexpected result: " + operationResult);
    }
}
```

### Transaction Result Values

| Value | Meaning |
|-------|---------|
| `"AUTORIZADA"` | The payment was successfully authorized |
| `"DENEGADA"` | The payment was denied or failed |

## Step 3: Handle Authorized Transactions

When a transaction is authorized, extract the relevant details for your records:

```java
private void handleAuthorizedTransaction(Intent data) {
    // Extract authorization details
    String authNumber = data.getStringExtra("AUTORIZATION_NUMBER");
    String orderNumber = data.getStringExtra("ORDER");
    String cardBrand = data.getStringExtra("CARDBRAND");
    String transactionId = data.getStringExtra("IDENTIFIER_RTS");

    // Log success
    Log.i("Payment", "Payment authorized!");
    Log.i("Payment", "Authorization: " + authNumber);
    Log.i("Payment", "Order: " + orderNumber);
    Log.i("Payment", "Card: " + cardBrand);

    // Update your business logic
    saveSuccessfulTransaction(orderNumber, authNumber, transactionId);
    updateOrderStatus(orderNumber, "PAID");

    // Notify the user
    showSuccessMessage("Payment successful! Authorization: " + authNumber);
}
```

> **Spelling Note**: The authorization number field is spelled `"AUTORIZATION_NUMBER"` (missing the 'H'). You must use this exact string as the key.

## Step 4: Handle Denied Transactions

When a transaction is denied, extract the error details to understand why:

```java
private void handleDeniedTransaction(Intent data) {
    // Extract denial details
    int respCode = data.getIntExtra("RESPCODE", -1);
    String errorMsg = data.getStringExtra("ERROR_MSG");

    // Log the denial
    Log.w("Payment", "Payment denied");
    Log.w("Payment", "Response code: " + respCode);
    Log.w("Payment", "Error: " + errorMsg);

    // Update your business logic
    logFailedTransaction(respCode, errorMsg);

    // Notify the user
    showErrorMessage("Payment declined: " + errorMsg);
}
```

## Step 5: Handle Cancellations

When the user cancels the transaction:

```java
private void handleCancellation() {
    Log.i("Payment", "Transaction cancelled by user");

    // Update your business logic
    logCancelledTransaction();

    // Notify the user
    showInfoMessage("Transaction cancelled");
}
```

## Complete Example

Here's a complete implementation:

```java
public class PaymentActivity extends AppCompatActivity {
    private static final int REQUEST_CODE_PAYMENT = 1001;

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == REQUEST_CODE_PAYMENT) {
            if (resultCode == RESULT_OK) {
                processTransactionResponse(data);
            } else if (resultCode == RESULT_CANCELED) {
                handleCancellation();
            }
        }
    }

    private void processTransactionResponse(Intent data) {
        if (data == null) return;

        String result = data.getStringExtra("RESULT");

        if ("AUTORIZADA".equals(result)) {
            // Success
            String authNumber = data.getStringExtra("AUTORIZATION_NUMBER");
            String orderNumber = data.getStringExtra("ORDER");
            String cardBrand = data.getStringExtra("CARDBRAND");
            String transactionId = data.getStringExtra("IDENTIFIER_RTS");

            Toast.makeText(this,
                "Payment approved! Auth: " + authNumber,
                Toast.LENGTH_LONG).show();

            // Save to your system
            saveTransaction(orderNumber, authNumber, transactionId, cardBrand);

        } else {
            // Denied
            int respCode = data.getIntExtra("RESPCODE", -1);
            String errorMsg = data.getStringExtra("ERROR_MSG");

            Toast.makeText(this,
                "Payment denied: " + errorMsg,
                Toast.LENGTH_LONG).show();

            // Log the failure
            logFailure(respCode, errorMsg);
        }
    }

    private void handleCancellation() {
        Toast.makeText(this,
            "Transaction cancelled",
            Toast.LENGTH_SHORT).show();
    }
}
```

## Available Response Fields

The response Intent contains the following extras:

| Field | Type | Description |
|-------|------|-------------|
| `RESULT` | String | `"AUTORIZADA"` or `"DENEGADA"` |
| `AUTORIZATION_NUMBER` | String | Authorization code for successful transactions |
| `ORDER` | String | Order number for the transaction |
| `CARDBRAND` | String | Card brand used (VISA, MASTERCARD, etc.) |
| `IDENTIFIER_RTS` | String | Unique transaction identifier |
| `RESPCODE` | int | Response code for denials/errors |
| `ERROR_MSG` | String | Human-readable error description |

For complete details, see [Response Parameters Reference](https://docs.globalgetnet.com/en/products/local-processor-spain/get-smart-app2app?doc=getsmart-app2app-response-api-reference).

## Receipt Printing

You do not need to write code to handle receipt printing:

* If applicable, the Get Smart financial application automatically handles the printing of the merchant's copy  
* The Get Smart application provides the user interface options to print the customer's receipt

Your application waits for the `onActivityResult` callback, which occurs after all printing workflows have been handled by the Get Smart app.

## Terminal Notifications

The terminal will automatically display alerts on the device screen depending on the transaction result (authorized, denied, error, etc.). Your application should also handle these outcomes programmatically based on the data returned in the `Intent` for your own UI and business logic.

## Best Practices

* **Always Check for Null**: Verify that the `data` Intent is not null before extracting extras  
* **Save Transaction Details**: Store the authorization number, order number, and transaction ID for reconciliation  
* **Handle All Cases**: Implement handlers for authorized, denied, and cancelled transactions  
* **Use Default Values**: When extracting integer values, provide a default (e.g., `getIntExtra("RESPCODE", -1)`)  
* **Log Appropriately**: Log authorized transactions as INFO, denials as WARN, and errors as ERROR  
* **User Feedback**: Always inform the user of the transaction outcome  
* **Persist State**: Save transaction results to persistent storage, not just in-memory

## Activity Lifecycle Considerations

While the Get Smart app is processing the transaction, your Activity may be paused or even destroyed by the system. Ensure your Activity can handle recreation:

* Save transaction state in `onSaveInstanceState`  
* Restore state in `onCreate` or `onRestoreInstanceState`  
* Consider using `ViewModel` or persistent storage for critical transaction data

## Next Steps

* Review response codes in [Result Codes and Errors Reference](/en/get-smart/get-smart-app2app/reference/result-codes-and-errors)  
* See all response fields in [Response Parameters Reference](https://docs.globalgetnet.com/en/products/local-processor-spain/get-smart-app2app?doc=getsmart-app2app-response-api-reference)  
* Learn how to create a single-step payment in [Create a Single-Step Payment](/en/get-smart/get-smart-app2app/transaction-guides/transactions/create-a-single-step-payment)