# Java Tutorial
source: https://developer.mastercard.com/transaction-notifications/documentation/developer-tools/reference-app/java-tutorial/index.md

## Overview {#overview}

This tutorial uses the Java reference app
[tn-java-ref-app.zip](https://static.developer.mastercard.com/content/transaction-notifications/uploads/tn-java-ref-app.zip) (42KB) to simulate a test transaction for an enrolled card and shows how to receive transaction notification events at a webhook endpoint. This app is only available for use in the Sandbox environment.

## Prerequisites {#prerequisites}

* [Java 17+](https://www.oracle.com/java/technologies/downloads/#java17l)
* [Apache Maven 3.3+](https://maven.apache.org/download.cgi)
* [Mastercard API signing library](https://github.com/Mastercard/oauth1-signer-java)

## Application Configuration {#application-configuration}

The signing properties in `src/main/resources/application.properties` specify the details of your Mastercard Developers project. Update the following properties with your consumer key and p12 filename and password. For information about creating a Mastercard Developers project, see the [Quick Start Guide](https://developer.mastercard.com/transaction-notifications/documentation/quick-start-guide/index.md).

```properties
signing.consumerKey=
signing.pkcs12KeyFile=
signing.keyAlias=
signing.keyPassword=
```

Note: In a real application, the keys and passwords must be kept secure, for example in an HSM.

## Build and Run {#build-and-run}

Run the following commands from the root of the project directory:

```bash
mvn clean compile
mvn spring-boot:run
```

When the compile step runs, the [OpenAPI Generator plugin](https://developer.mastercard.com/transaction-notifications/documentation/developer-tools/reference-app/java-tutorial/index.md#integrating-with-openapi-generator) generates the sources for connecting to the Transaction Notifications APIs.

Open <http://localhost:8083> in your browser.

## Test Transaction {#test-transaction}

To send a test transaction using the reference app:

1. Open <http://localhost:8083> in a browser. The home page shows two API cards.

   ![The Transaction Notifications reference app home page, showing the Test Transaction API and Undelivered Notifications API cards](https://static.developer.mastercard.com/content/transaction-notifications/uploads/refapp-home.png)
2. Select **Test Transaction API**.

   ![The Test Transaction API form, showing the Test Cases drop-down, Payload field, and Send Test Transaction button](https://static.developer.mastercard.com/content/transaction-notifications/uploads/refapp-test-transaction-form.png)

   The Test Transaction API page shows the **Test cases** drop-down and the **Payload** field, populated with the corresponding JSON. Edit the payload if needed.
3. Select **Send test transaction**. A success message confirms that the notification was created and sent to your registered webhook.

Note: To receive the notification at your webhook endpoint, your webhook endpoint (on which you want to receive the transaction notifications) must be onboarded onto Mastercard Developers. You must also have enrolled the card through [Consent Management \& Enrollment](https://developer.mastercard.com/consent-management/documentation/) before calling the test transaction API. If sandbox webhook delivery is not configured, fetch notifications from the [Undelivered Notifications API](https://developer.mastercard.com/transaction-notifications/documentation/developer-tools/reference-app/java-tutorial/index.md#undelivered-notifications).

## Undelivered Notifications {#undelivered-notifications}

If you have not set up your webhook endpoint yet, you can use the Undelivered Notifications API to view the test notification you created.

To fetch undelivered notifications using the reference app:

1. Open <http://localhost:8083> in a browser.

2. Select **Undelivered Notifications API**.

   ![The Undelivered Notifications API form](https://static.developer.mastercard.com/content/transaction-notifications/uploads/refapp-undelivered-transaction-form.png)
3. Optionally, enter a cursor value in the **Next cursor** field to page through results.

4. Select **Send request**.

   The **Response** field shows the notifications returned by the API.

Sample response:

```json
{
  "nextCursor": 5621260951,
  "data": [
    {
      "notificationSequenceId": "5621260801",
      "cardAcceptorId": "123456",
      "financialNetworkCode": "MCU",
      "recurringTransaction": "false",
      "channel": "ECOM",
      "transactionLocalDate": "2023-09-08",
      "cardReference": "e7917328-983f-410a-9c58-afc83ff5c856",
      "systemDateTime": "2023-09-08T20:46:03+0000"
    }
  ]
}
```

Use the `nextCursor` value in the **Next cursor** field to fetch the next page of results.
