# Reference Application
source: https://developer.mastercard.com/pclo-presentment/documentation/reference-application-tutorial/index.md

Note: Mastercard supports OAuth 2.0 for authenticating application HTTP requests. Refer to the following resources for guidance and documentation:   

* [Offers for Publishers (Legacy) OAuth 2.0 authentication and first call tutorial](https://developer.mastercard.com/pclo-presentment/documentation/tutorials-and-guides/index.md)
* [Using OAuth 2.0 to Access Mastercard APIs](https://developer.mastercard.com/platform/documentation/authentication/using-oauth-2-to-access-mastercard-apis/)
* [OAuth 2.0 reference application on GitHub](https://github.com/Mastercard/oauth2-client-java): Customers are advised to update the specification file and certificates as instructed in the README.md file to ensure access and alignment with OAuth 2.0 requirements.
* [Offers for Publishers API](https://developer.mastercard.com/presentment/documentation/release-history/) updated documentation

<br />

Support for OAuth 1.0a authentication remains available.

## Introduction {#introduction}

This section showcases reference implementations of Offers for Publishers APIs.

The reference application contains a REST client that supports all the use cases shown in this documentation. It is built using Spring Boot and can generate an API client library through OpenAPI Generator using the Offers for Publishers OpenAPI Specification. The reference application can be used to call the Offers for Publishers endpoints.
Note: Offers for Publishers leverages APIs from [User Account Management](https://developer.mastercard.com/user-account-management-service/documentation/) for key functionalities, including user management for cardholder enrollment, account updates, lost or stolen card replacements, and accessing sensitive identifiers. Refer to the [Reference App](https://developer.mastercard.com/user-account-management-service/documentation/reference-app/) section within User Account Management to test the following use cases:

* Users
* Accounts
* Lost Stolen
* Lookup Identifiers

## Technologies Used {#technologies-used}

* [Spring Boot](https://spring.io/projects/spring-boot)
* [Okhttp](https://square.github.io/okhttp/)
* [Lombok](https://projectlombok.org/)
* [Mockito](https://site.mockito.org/)
* [OpenAPI Generator](https://openapi.tools/)
* [Apache Maven](https://maven.apache.org/)

## Prerequisites {#prerequisites}

* [Java 8](http://www.oracle.com/technetwork/java/javase/downloads/index.html) or above.
* [Lombok](https://projectlombok.org/)
  * [Plugin for IntelliJ](https://plugins.jetbrains.com/plugin/6317-lombok/)
  * [Setup for Eclipse](https://projectlombok.org/setup/eclipse)
  * [Setup for Netbeans](https://projectlombok.org/setup/netbeans)

## Clone the Reference Implementation {#clone-the-reference-implementation}

The Offers for Publishers reference implementation is provided in the Mastercard GitHub repository.

In IntelliJ IDEA, for example,

* Clone the personalized-offers-reference-implementation from the [Mastercard GitHub repository](https://github.com/Mastercard/personalized-offers-reference-implementation).
* Open it as a maven project. ![Alt text](https://static.developer.mastercard.com/content/pclo-presentment/images/clone-reference-implementation.PNG "Clone the personalized-offers-reference-implementation")

## Configuration {#configuration}

1. Create a Mastercard Developers account [here](https://developer.mastercard.com/account/sign-up).
2. Login and create a new project [here](https://developer.mastercard.com/account/log-in).
3. Add the `Offers for Publishers` API to your project and click continue.
4. Configure the project and click continue.
5. Download Sandbox Signing Key.
6. A `.p12` file automatically downloads. Note: On Safari, the file name will be `Unknown`. Rename it to a `.p12` extension.
7. Copy the downloaded `.p12` file to `src/main/resources` folder in the code.
8. Open `src/main/resources/application.properties` and configure the following:

   |           Configuration            |          Description          |                                          Note                                          |
   |------------------------------------|-------------------------------|----------------------------------------------------------------------------------------|
   | `mastercard.api.p12.path`          | Path to keystore `.p12` file. | Since the `.p12` is under the same resources folder, pass the name of the `.p12` here. |
   | `mastercard.api.consumer.key`      | Consumer key.                 | Copy this from "Sandbox/Production Keys" on your project page.                         |
   | `mastercard.api.key.alias`         | Key alias.                    | Default key alias for Sandbox is `keyalias`.                                           |
   | `mastercard.api.keystore.password` | Keystore password.            | Default keystore password for sandbox project is `keystorepassword`.                   |

## Execute the Offers for Publishers Use Cases {#execute-the-offers-for-publishers-use-cases}

1. Run `./mvnw clean install` from the root of the project directory.
2. Execute the use cases using one of two options.

### Option 1: Execute the premade test cases {#option-1-execute-the-premade-test-cases}

Pre-made test cases that make API calls to the Offers for Publishers sandbox environment are created for all User Presentment and Platform Admin Use Cases.

1. Go to the `src/main/java/com/mastercard/developer/usecases` folder.
2. Execute each test case. Note the following considerations for each test case.

   |             Test case             |                                                                                  Note                                                                                  |
   |-----------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
   | `PlatformAdminServiceTest.java`   | A Financial Institution Identifier (f-id) provided by Mastercard during implementation is required while executing all test cases.                                     |
   | `UserPresentmentServiceTest.java` | An access token is created using the Financial Institution Identifier, user ID and UTC time offset. The access token is used while executing all the other test-cases. |

### Option 2: Use the REST API-based Client {#option-2-use-the-rest-api-based-client}

1. Run the `./mvnw spring-boot:run` command to run the application.
2. Use any REST API-based Client such as [Insomnia](https://insomnia.rest/download/core/) or [Postman](https://www.postman.com/downloads/) to test the functionality of all the endpoints exposed by this reference application, using `localhost:8080` as the Host.

Note: Refer to the `README.MD` file within the code for additional information on the Offers for Publishers reference implementation.

## Next Steps {#next-steps}

* Refer to the [API Tutorial](https://developer.mastercard.com/pclo-presentment/documentation/api-tutorial/index.md) section for information on connecting to Offers for Publishers.
* To learn more about any error codes you receive, refer to [Code and Formats](https://developer.mastercard.com/pclo-presentment/documentation/code-and-formats/index.md).
