- Overview
- Prerequisites
- Frameworks/Libraries
- Integrating with OpenAPI Generator
- Configuration
- Use-Cases
- Execute the Use-Cases
- Service Documentation
- API Reference
- Support
This is a reference application to demonstrate how Carbon Calculator API can be used. To call these API, the consumer key and .p12 file are required from your project on Mastercard Developers.
- Java 11
- IntelliJ IDEA (or any other IDE)
- Spring Boot
- Apache Maven
- OpenAPI Generator
OpenAPI Generator generates API client libraries from OpenAPI Specs. It provides generators and library templates for supporting multiple languages and frameworks. Check Generating and Configuring a Mastercard API Client to know more about how to generate a simple API client for consuming API.
The Mastercard Encryption Library provides an interceptor class that you can use when configuring your API client. This interceptor will encrypt the payload before sending the request.
Encryption Config
FieldLevelEncryptionConfig config = FieldLevelEncryptionConfigBuilder
.aFieldLevelEncryptionConfig()
.withEncryptionCertificate(cert)
.withEncryptionPath("$", "$")
.withEncryptedValueFieldName("encryptedData")
.withEncryptedKeyFieldName("encryptedKey")
.withOaepPaddingDigestAlgorithmFieldName("oaepHashingAlgorithm")
.withOaepPaddingDigestAlgorithm("SHA-256")
.withEncryptionKeyFingerprintFieldName("publicKeyFingerprint")
.withIvFieldName("iv")
.withFieldValueEncoding(FieldLevelEncryptionConfig.FieldValueEncoding.HEX)
.build();
See also:
- Create your account on Mastercard Developers if you don't have it already.
- Create a new project here and add Carbon Calculator to it and click continue.
- Download Sandbox Signing Key, a
.p12
file will be downloaded. - In the Client Encryption Keys section of the dashboard, click on the
Actions
dropdown and download the client encryption key, a ``.pem``` file will be downloaded. - Copy the downloaded
.p12
and.pem
files tosrc/main/resources
folder in your code. - Open
src/main/resources/application.yml
and configure:mastercard.api.environment.key-file
- Path to keystore (.p12) file, just change the name as per the downloaded file in step 5.mastercard.api.authentication.consumer-key
- Copy the Consumer key from "Sandbox/Production Keys" section on your project pagemastercard.api.authentication.keystore-alias
- Alias of your key. The default key alias for sandbox iskeyalias
.mastercard.api.authentication.keystore-password
- Password of your Keystore. The default keystore password for sandbox project iskeystorepassword
.mastercard.api.encryption.key-file
- Path to encryption key (.pem) file, just change the name as per the downloaded file in step 5.mastercard.api.encryption.fingerprint
- Fingerprint, copy the fingerprint from Client Encryption Keys section. If you have multiple client encryption keys then copy the fingerprint of the key which you want to use.test.data.bin
- Update this with one of your supported BINs
-
Transaction Footprints Calculation
Calculates carbon emission and water usage based on payment transactions. -
Get Supported Currencies
Provides a list of Merchant Category Code (MCC) supported by the application. -
Get Supported Merchant Categories
Provides a list of Currencies supported by the application. -
Add Payment Card
Allows a registered Service Provider to add a new Payment Card under its profile. -
View Historical Transaction Footprints
Fetches historical transactions and their footprints for a registered payment card. -
View Aggregate Transaction Footprints
Fetches carbon score for registered payment cards and aggregates the same on daily, weekly, monthly, and yearly basis. -
View Service Provider Details
Fetches service provider details.
More details can be found here.
- Run
mvn clean install
from the root of the project directory. - There are two ways to execute the use-cases:
-
Execute the use-cases(test cases):
- Go to
src/main/java/com/mastercard/developer/carboncalculator/usecases
folder. - Execute each test case.
- In
PaymentCardServiceTest.java
, note that a random FPAN is generated starting with your BIN while adding a new payment card and the paymentCardId of this card is used while executing the other two test-cases.
- Go to
-
Use REST API based Client( such as Insomnia or Postman)
- Run
mvn spring-boot:run
command to run the application. - Use any REST API based Client to test the functionality. Below are the endpoints exposed by this reference application, use
locahost:8080
as the Host:
- POST {Host}/demo/transaction-footprints
- GET {Host}/demo/supported-mccs
- GET {Host}/demo/supported-currencies
- POST {Host}/demo/payment-cards
- POST {Host}/demo/aggregate-transaction-footprints
- GET {Host}/demo/historical/{paymentcard_id}/transaction-footprints
- GET {Host}/demo/service-providers
- Run
-
Carbon Calculator documentation can be found here.
The Swagger API specification can be found here.
Please send an email to [email protected] with any questions or feedback you may have.