https://github.com/mastercard/merchant-identifier-reference-app
Reference application for Merchant Identifier API
https://github.com/mastercard/merchant-identifier-reference-app
Last synced: about 1 year ago
JSON representation
Reference application for Merchant Identifier API
- Host: GitHub
- URL: https://github.com/mastercard/merchant-identifier-reference-app
- Owner: Mastercard
- License: apache-2.0
- Created: 2017-01-19T08:38:23.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2023-12-18T17:04:20.000Z (over 2 years ago)
- Last Synced: 2024-04-16T10:43:19.605Z (over 2 years ago)
- Language: Java
- Size: 943 KB
- Stars: 8
- Watchers: 4
- Forks: 7
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Merchant Identifier API Reference Application
[](https://github.com/Mastercard/loyalty-user-management-reference/blob/master/LICENSE)
## Table of Contents
- [Overview](#overview)
* [Compatibility](#compatibility)
* [References](#references)
* [Frameworks](#frameworks)
- [Setup](#setup)
* [Prerequisites](#prerequisites)
* [Application Configuration](#configuration)
* [Build and Execute](#build-and-execute)
* [Reference Application Usage](#reference-application-usage)
* [Integrating with OpenAPI Generator](#integrating-with-openapi-generator)
- [Use Cases](#use-cases)
* [Parameters](#parameters)
* [Merchant Identifier](#merchant-identifier)
- [API Reference](#api-reference)
- [Reference App API Reference](#ref-app-api-reference)
- [Merchant Identifier API Reference](#merchant-identifier-api-reference)
- [Authentication](#authentication)
* [Mastercard's OAuth Library](#oauth-library)
- [Support](#support)
- [License](#license)
## Overview
This project showcases retrieving merchant name and addresses using the [Merchant Identifier API](https://developer.mastercard.com/merchant-identifier/documentation/api-reference/).
This application illustrates connecting to the Merchant Identifier API using Mastercard's OAuth library, and an OpenAPI generated client.
### Compatibility
* [Java 11](https://www.oracle.com/java/technologies/javase-jdk15-downloads.html) or later
### References
* [Mastercard’s OAuth Signer library](https://github.com/Mastercard/oauth1-signer-java)
* [Using OAuth 1.0a to Access Mastercard APIs](https://developer.mastercard.com/platform/documentation/using-oauth-1a-to-access-mastercard-apis/)
## Frameworks
- OpenAPI Generator
- [Java 11+](https://www.oracle.com/java/technologies/downloads)
- [Maven](https://maven.apache.org/download.cgi)
* [Mastercard Developers Account](https://developer.mastercard.com/dashboard)
* A text editor or IDE
* [Java 11+](https://www.oracle.com/java/technologies/downloads)
* [Apache Maven 3.3+](https://maven.apache.org/download.cgi)
* Set up the `JAVA_HOME` environment variable to match the location of your Java installation.
### Application Configuration
1. Follow this [credentials quick guide](https://developer.mastercard.com/platform/documentation/getting-started-with-mastercard-apis/quick-start-guide/) to get the credentials needed to run this application
- Be sure to add `Merchant Identifier` to your project.
- A zip file will be downloaded automatically with your key.
2. Take note of the given **consumer key**, **keyalias**, and **keystore password** given upon the project creation.
3. Extract zip and place the `.p12` file in `/src/main/resources` of the project.
4. Update the properties found in `/src/main/resources/application.properties`.
#### application.properties
`mastercard.api.base-path=https://sandbox.api.mastercard.com/merchant-identifier`, This is the URL that the application will use to connect to Mastercard. For production usage, just remove `sandbox.`.
**Below properties will be required for authentication of API calls.**
`mastercard.p12.path=`, this refers to .p12 file found in the signing key. Place .p12 file at src\main\resources in the project folder then add the filename here.
`mastercard.consumer.key=`, this refers to your consumer key. Copy it from "Keys" section on your project page in [Mastercard Developers](https://developer.mastercard.com/dashboard)
`mastercard.keystore.alias=keyalias`, this is the default value of key alias. If it is modified, use the updated one from keys section in [Mastercard Developers](https://developer.mastercard.com/dashboard).
`mastercard.keystore.pass=keystorepassword`, this is the default value of key pass. If it is modified, use the updated one from keys section in [Mastercard Developers](https://developer.mastercard.com/dashboard).
### Build and Execute
1. Run `mvn clean install` from the root of the project directory.
* When install is run, the [OpenAPI Generator plugin](#integrating-with-openapi-generator) will generate the sources for connecting to the Merchant Identifier API.
2. run `java -jar target/merchantidentifier-api-reference-app-X.X.X.jar` to start the project.
- **Notice**: Replace `X` with version of the reference app.
- **Example**: `java -jar target/merchantidentifier-api-reference-app-1.0.0.jar`
### Reference Application Usage
- Use the merchant identifier reference app by providing merchant descriptor to get the matches.
- click on a marker to open more information on the right panel.
### Integrating with OpenAPI Generator
[OpenAPI Generator](https://github.com/OpenAPITools/openapi-generator) generates API client libraries from [OpenAPI Specs](https://github.com/OAI/OpenAPI-Specification).
It provides generators and library templates for supporting multiple languages and frameworks.
See also:
* [OpenAPI Generator (maven Plugin)](https://mvnrepository.com/artifact/org.openapitools/openapi-generator-maven-plugin)
* [OpenAPI Generator (executable)](https://mvnrepository.com/artifact/org.openapitools/openapi-generator-cli)
* [CONFIG OPTIONS for java](https://github.com/OpenAPITools/openapi-generator/blob/master/docs/generators/java.md)
#### OpenAPI Generator Plugin Configuration
```xml
org.openapitools
openapi-generator-maven-plugin
4.3.0
generate
${project.basedir}/src/main/resources/merchant-identifier-api-spec.yaml
java
okhttp-gson
${project.basedir}/src/main/resources/openapi-config.json
false
false
src/gen/java/main
```
#### Parameters
These are the parameters used for the Merchant Identifier API.
| Name | Type | Default Value | Purpose |
|-----------------------|-----------|--------------------|---------------|
| merchant_descriptor | string | 0 | To find merchant list with identifier. |
| match_type | string | ExactMatch | To perform a type of the search for merchant identifiers |
| card_acceptor_id | string | - | To find merchant list matched by card acceptor id |
> Get information on a Merchant Identifier.
| MerchantIdentfier API URL | Method | Parameters | Request Model | Response model |
|-----------------------------------|---------------|-----------------------------------|---------------|---------------------------|
| /merchants | GET | merchant_descriptor, match_type | string | merchant list with address and merchant descriptor |
| /merchants-by-card-acceptor-ids | GET | card_acceptor_id | string | merchant list with address and card acceptor id |
### Reference Application API Reference
| Reference App URL | Parameters | Reference App Usage | Merchant Identifier Endpoint Used |
|-----------------------------------------------------------|-----------------------------------|-------------------------------------------------------------------|-------------------------------------------------------|
|**/merchant-identifier/merchants** | merchant_descriptor, match_type | Search for merchant list with merchant identifier by match type | /merchant-identifier/merchants |
|**/merchant-identifier/merchants-by-card-acceptor-ids** | card_acceptor_id | Search for merchant list with card acceptor id | /merchant-identifier/merchants-by-card-acceptor-ids |
Example Search Requests in a rest client of your choice:
* `https://sandbox.api.mastercard.com/merchant-identifier/merchants?merchant_descriptor=DOLIUMPTYLTDWELSHPOOLWA&match_type=ExactMatch`
* `https://sandbox.api.mastercard.com/merchant-identifier/merchants?merchant_descriptor=DOLIUMPTYLTDWELSHPOOLWA&match_type=FuzzyMatch`
* `https://sandbox.api.mastercard.com/merchant-identifier/merchants-by-card-acceptor-ids?card_acceptor_id=C928456`
### Merchant Identifier API Reference
See the [API Reference](https://developer.mastercard.com/merchant-identifier/documentation/api-reference) page in the documentation.
| API Endpoint | Description |
| ----------------------------- | ----------------------------------------------------------------- |
| [Merchant Identifier](https://developer.mastercard.com/merchant-identifier/documentation/api-reference#api) | Search for merchant list with matching merchant identifier |
### Mastercard oauth1 Signer Library
This dependency is required to properly call the API.
```xml
com.mastercard.developer
oauth1-signer
1.2.3
```
[Link to the oauth1 library's Github](https://github.com/Mastercard/oauth1-signer-java)
[Looking for other languages?](https://github.com/Mastercard?q=oauth&type=&language=)
See the code used in this application to utilize the library.
```Java
Found in /src/java/com.mastercard.midreferenceapplciation.config.ApiClientConfiguration
ApiClient client = new ApiClient();
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(logger::info);
loggingInterceptor.level(HttpLoggingInterceptor.Level.BASIC);
try {
client.setBasePath(basePath);
client.setHttpClient(
client.getHttpClient()
.newBuilder()
.addInterceptor(new OkHttpOAuth1Interceptor(consumerKey, getSigningKey()))
.addInterceptor(loggingInterceptor)
.build()
);
return client;
} catch (Exception e) {
logger.error("Error occurred while configuring ApiClient", e);
}
return client;
```
## Support
If you would like further information, please send an email to apisupport@mastercard.com
## License
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
**Copyright © 1994-2022, All Rights Reserved by Mastercard.**