# Testing
source: https://developer.mastercard.com/transaction-notifications/documentation/testing/index.md

Testing for Transaction Notifications starts in Sandbox and validates transaction simulation and notification retrieval.

## Prerequisites {#prerequisites}

Confirm the following before testing:

* Your project includes both Transaction Notifications and Consent Management \& Enrollment APIs.
* Sandbox OAuth credentials are configured.
* You have completed consent enrollment and obtained a valid `cardReference` or `cardNumber` (PAN).
* You have the Sandbox base URL: `https://sandbox.api.mastercard.com/openapis`.

## Testing Workflow {#testing-workflow}

Follow these steps to validate your integration end-to-end. For detailed test cases, see the [Test Cases](https://developer.mastercard.com/transaction-notifications/documentation/testing/index.md#test-cases) section.

| # | Test                                  | Endpoint                                                                                               | What to Verify                                                                           |
|:--|:--------------------------------------|:-------------------------------------------------------------------------------------------------------|:-----------------------------------------------------------------------------------------|
| 1 | Enroll card consent                   | [Consent Management \& Enrollment](https://developer.mastercard.com/consent-management/documentation/) | Card is enrolled and `cardReference` is returned.                                        |
| 2 | Simulate transaction                  | `POST /notifications/transactions`                                                                     | `200 OK` and notification generation for the enrolled card                               |
| 3 | Retrieve undelivered notifications    | `GET /notifications/undelivered-notifications`                                                         | Notification payload can be fetched using the `after` sequence number for pagination     |
| 4 | Validate retry handling behavior      | Webhook acknowledgment + undelivered retrieval                                                         | Non-2xx acknowledgments are retried; failed deliveries are available via undelivered API |
| 5 | Validate clearing search (if enabled) | `POST /notifications/transactions/search`                                                              | Clearing details are returned for supported query patterns                               |

## Test Cases {#test-cases}

### Positive Example {#positive-example}

`POST /notifications/transactions`

```json
{
  "cardholderAmount": 10.99,
  "cardholderCurrency": "USD",
  "merchantName": "Merchant",
  "cardReference": "<CARD_REFERENCE>"
}
```

**Expected result:** `200 OK` and a notification is generated for the enrolled card.

### Negative Example {#negative-example}

`POST /notifications/transactions`

```json
{
  "cardholderAmount": 10.99,
  "merchantName": "Merchant"
}
```

**Expected result:** `400 MissingFields` because `cardholderCurrency` and `cardReference` (or `cardNumber`) are missing.

### Positive Example {#positive-example}

`GET /notifications/undelivered-notifications`

**Expected result:** Stored notifications are returned with the `nextCursor` sequence number when additional undelivered events are available.

### Negative Example {#negative-example}

`GET /notifications/undelivered-notifications?after=-1`

**Expected result:** An empty result set or error is returned because the sequence number is not valid.

### Positive Example {#positive-example}

`POST /notifications/transactions/search`

```json
{
  "afterTransactionDate": "2024-04-01"
}
```

**Expected result:** `200 OK` and clearing details are returned for supported consented transactions.

### Negative Example {#negative-example}

`POST /notifications/transactions/search`

```json
{
  "transactionStartDate": "2024-04-31",
  "transactionEndDate": "2024-04-01"
}
```

**Expected result:** `400 MissingFields` because the request body contains invalid date values.

## Troubleshooting {#troubleshooting}

|                                           Issue                                            |                                                                                             Solution                                                                                              |
|--------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Required request fields are missing or malformed.                                          | Validate payload fields and data types against [API Reference](https://developer.mastercard.com/transaction-notifications/documentation/api-reference/index.md).                                  |
| Notification is not delivered to your webhook endpoint.                                    | Return `200` or `201` immediately and retrieve missed payloads from `GET /notifications/undelivered-notifications`.                                                                               |
| Duplicate notifications are observed.                                                      | Acknowledge delivery quickly and deduplicate using stable identifiers in the payload.                                                                                                             |
| `POST /notifications/transactions`: `400 MissingFields`, `404 UnknownCard`                 | Validate required request fields and `cardReference` enrollment against [Codes and Formats](https://developer.mastercard.com/transaction-notifications/documentation/codes-and-formats/index.md). |
| `GET /notifications/undelivered-notifications`: Empty result set (no undelivered messages) | Confirm the `after` sequence number and whether events were previously acknowledged.                                                                                                              |
| `POST /notifications/transactions/search`: `400 MissingFields`, `404 UnknownCard`          | Validate date format, query body fields, and card references against [Codes and Formats](https://developer.mastercard.com/transaction-notifications/documentation/codes-and-formats/index.md).    |

For reason codes and response structure, see [Codes and Formats](https://developer.mastercard.com/transaction-notifications/documentation/codes-and-formats/index.md).

## Next Steps {#next-steps}

* Run endpoint-level tests from [Postman Collection](https://developer.mastercard.com/transaction-notifications/documentation/developer-tools/postman-collection/index.md) or [Insomnia Collection](https://developer.mastercard.com/transaction-notifications/documentation/developer-tools/insomnia-collection/index.md).
* Continue with implementation walkthroughs in [Tutorials](https://developer.mastercard.com/transaction-notifications/documentation/tutorials-and-guides/index.md).
