# API Basics source: https://developer.mastercard.com/mastercard-processing-digital/documentation/api-basics/index.md ## Overview {#overview} The Mastercard Processing APIs follow Representational State Transfer (REST) principles. The APIs: * Have predictable resource-oriented URLs * Accept JavaScript Object Notation ([JSON](https://www.json.org/json-en.html)) request bodies * Return JSON-encoded responses * Use standard Hypertext Transfer Protocol (HTTP) response codes, authentication, and verbs All `POST`, `PUT`, and `GET` requests must include the header `Content-Type` of `application/json;charset=utf-8`. Other charsets return `415 UNSUPPORTED_CHARSET_ERROR`. ## Client authentication {#client-authentication} Warning: **Key Expiry:** Mastercard Processing API (Sandbox/MTF and Production) keys expire after 13 months. You have to generate a new set of keys when they expire. To generate it, go to your project dashboard and under **API Keys** , select **Add Key**. | Authentication Protocol | Details | |--------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [OAuth 1.0a](https://oauth.net/core/1.0a/) | Mastercard uses OAuth 1.0a with a body hash extension for authenticating the API clients. OAuth 1.0a is an authentication and authorization protocol that guarantees the integrity and authenticity of incoming API calls and allows for non-repudiation of requests. | OAuth requires every request that you send to Mastercard to be signed with an RSA private key. A private-public RSA key pair must be generated consisting of: 1. A **private key** for signing OAuth API requests. It is recommended to keep the private key in a password-protected or hardware keystore. The private key is used to encrypt the signature base string hash and is decrypted using the public key at the server. 2. A **public key** is shared with Mastercard during the project setup process through either a Certificate Signing Request (CSR) or an API Key Generator. Mastercard uses the public key to verify the OAuth signature that is provided on every API call. * Requests with a body must be signed using the [Google Request Body Hash](https://datatracker.ietf.org/doc/id/draft-eaton-oauth-bodyhash-00.html) extension for OAuth. * The OAuth keys are created during the process of project creation on Mastercard Developers. Additionally, you can add new OAuth keys inside your project dashboard, if needed. Tip: Do you want to learn more about the authentication scheme Mastercard uses? If so, read our [Using OAuth 1.0a to Access Mastercard APIs](https://developer.mastercard.com/platform/documentation/authentication/using-oauth-1a-to-access-mastercard-apis/) guide. ## Transport encryption {#transport-encryption} The transport over the Internet between client applications and Mastercard is secured using [TLS/SSL](https://en.wikipedia.org/wiki/Transport_Layer_Security), which means data is secured by default when transmitted across networks. Mastercard Processing supports **TLS 1.2 and TLS 1.3 only**. Integrations must support at least one of the following approved cipher suites: * TLS_AES_256_GCM_SHA384 (TLS 1.3) * TLS_AES_128_GCM_SHA256 (TLS 1.3) * TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (TLS 1.2) * TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (TLS 1.2) Mastercard Processing Digital API additionally uses JSON Web Encryption (JWE) to provide end-to-end payload encryption to encrypt sensitive data, such as Personally Identifiable Information (PII). ### JWE {#jwe} | Encryption Protocol | Details | |----------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [JSON Web Encryption](https://datatracker.ietf.org/doc/html/rfc7516) | JSON Web Encryption (JWE) represents encrypted content using JSON-based data structures [RFC7159](https://datatracker.ietf.org/doc/html/rfc7159) and `base64url` encoding. Mastercard uses [JWE compact serialization](https://datatracker.ietf.org/doc/html/rfc7516#section-7.1) for the encryption of sensitive data and supports full body payload encryption. | Tip: Do you want to learn more about the encryption scheme Mastercard uses? If so, visit our [JWE Encryption Guide](https://developer.mastercard.com/platform/documentation/authentication/securing-sensitive-data-using-payload-encryption/#jwe-encryption). We highly recommend using [Mastercard client encryption libraries](https://github.com/Mastercard?q=client-encryption) available in several popular programming languages. ## How to consume the API? {#how-to-consume-the-api} There are two ways of integrating with the Mastercard Processing API: * [Generating your own Mastercard Processing Digital API client](https://developer.mastercard.com/mastercard-processing-digital/documentation/api-basics/index.md#generating-your-own-mastercard-processing-digital-api-client) * [Configuring your client using our client libraries](https://developer.mastercard.com/mastercard-processing-digital/documentation/api-basics/index.md#configuring-your-client-using-our-client-libraries) ### Generating your own Mastercard Processing Digital API client {#generating-your-own-mastercard-processing-digital-api-client} Create customizable API clients from the Mastercard Processing Digital API specification and let Mastercard open-source client libraries handle the authentication and encryption for you. This approach offers more flexibility and is strongly recommended. To learn how to generate your own client, follow the [Generating and Configuring a Mastercard API Client](https://developer.mastercard.com/platform/documentation/security-and-authentication/generating-and-configuring-a-mastercard-api-client/) tutorial using: * The following Mastercard Processing Digital API specification file: [oas_digital.yaml](https://static.developer.mastercard.com/content/mastercard-processing-digital/uploads/oas_digital.yaml) (98KB) * An API client library generated using [OpenAPI Generator](https://openapi-generator.tech/docs/installation) and the development framework of your choice (see also: [Generators List](https://openapi-generator.tech/docs/generators/)): Example command (ensure that the specification file name matches the actual file you are using): * Sh ```sh openapi-generator-cli generate -g java -i oas_digital.yaml -o api_client ```
* The following payload encryption code configurations are available: * Java * C# * JavaScript * Python * Go ```java @Bean public EncryptionConfig fullBodyEncryptionConfig() throws EncryptionException, GeneralSecurityException, IOException { Certificate encryptionCertificate = EncryptionUtils.loadEncryptionCertificate(encryptionCertificateFilePath); PrivateKey decryptionKey = EncryptionUtils.loadDecryptionKey(decryptionKeyFilePath, decryptionKeyAlias, decryptionKeyPassword); return JweConfigBuilder.aJweEncryptionConfig() .withEncryptionCertificate(encryptionCertificate) .withEncryptionPath("$", "$") .withDecryptionPath("$", "$") .withDecryptionKey(decryptionKey) .build(); } ``` ```csharp public JweConfig FullBodyEncryptionConfig() { var encryptionCertificate = EncryptionUtils.LoadEncryptionCertificate(encryptionCertificateFilePath); var decryptionKey = EncryptionUtils.LoadDecryptionKey(decryptionKeyFilePath, decryptionKeyPassword); return JweConfigBuilder.AJweEncryptionConfig() .WithEncryptionCertificate(encryptionCertificate) .WithDecryptionKey(decryptionKey) .WithEncryptionPath("$", "$") .WithDecryptionPath("$", "$") .Build(); } ``` ```JavaScript function createFullBodyEncryptionConfig() { return { paths: [ { path: ".*", toEncrypt: [{ element: "$", obj: "$" }], toDecrypt: [{ element: "$", obj: "$" }] } ], mode: "JWE", encryptionCertificate: "./path/to/encryptionCertificate.pem", privateKey: "./path/to/decryptionKey.pem" }; } const encryptionConfigForAdoptions = createEncryptionConfigForAdoptions(); const fullBodyEncryptionConfig = createFullBodyEncryptionConfig(); ``` ```Python def build_full_body_encryption_config(): return JweEncryptionConfig({ "paths": { ".*": { "toEncrypt": {"$": "$"}, "toDecrypt": {"$": "$"} } }, "encryptionCertificate": "./path/to/encryptionCertificate.pem", "decryptionKey": "./path/to/decryptionKey.pem" }) encryption_config = build_encryption_config() full_body_encryption_config = build_full_body_encryption_config() ``` ```Go cbFullBody := jwe.NewJWEConfigBuilder() fullBodyEncryptionConfig := cbFullBody.WithDecryptionKey(decryptionKey). WithCertificate(encryptionCertificate). WithEncryptionPath("$", "$"). WithDecryptionPath("$", "$"). Build() ``` ### Configuring your client using our client libraries {#configuring-your-client-using-our-client-libraries} These libraries are available in several languages, and we recommend that you utilize these libraries to encrypt the sensitive data used by this service. | | ![Java](https://static.developer.mastercard.com/content/mastercard-processing-digital/uploads/java.svg) | ![C#](https://static.developer.mastercard.com/content/mastercard-processing-digital/uploads/csharp.svg) | ![Python](https://static.developer.mastercard.com/content/mastercard-processing-digital/uploads/python.svg) | ![Node.js](https://static.developer.mastercard.com/content/mastercard-processing-digital/uploads/nodejs.svg) | |----------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | **Download/install** | [![Java version](https://img.shields.io/maven-central/v/com.mastercard.developer/client-encryption.svg?style=flat&color=f99f1c&label=)](https://central.sonatype.com/artifact/com.mastercard.developer/client-encryption) | [![C# version](https://img.shields.io/nuget/v/Mastercard.Developer.ClientEncryption.Core.svg?style=flat&color=f99f1c&label=)](https://www.nuget.org/packages/Mastercard.Developer.ClientEncryption.Core/) | [![Python version](https://img.shields.io/pypi/v/mastercard-client-encryption.svg?style=flat&color=f99f1c&label=)](https://pypi.org/project/mastercard-client-encryption/) | [![Node.js version](https://img.shields.io/npm/v/mastercard-client-encryption.svg?style=flat&color=f99f1c&label=)](https://www.npmjs.com/package/mastercard-client-encryption) | | **View on GitHub** | [![Java GitHub stars](https://img.shields.io/github/stars/Mastercard/client-encryption-java.svg?label=&style=social)](https://github.com/Mastercard/client-encryption-java) | [![C# GitHub stars](https://img.shields.io/github/stars/Mastercard/client-encryption-csharp.svg?label=&style=social)](https://github.com/Mastercard/client-encryption-csharp) | [![Python GitHub stars](https://img.shields.io/github/stars/Mastercard/client-encryption-python.svg?label=&style=social)](https://github.com/Mastercard/client-encryption-python) | [![Node.js GitHub stars](https://img.shields.io/github/stars/Mastercard/client-encryption-nodejs.svg?label=&style=social)](https://github.com/Mastercard/client-encryption-nodejs) | To get started, add the package that matches your application development language to your project. You can also refer to the different README.md files for detailed how-to information. ## Environment descriptions {#environment-descriptions} The following table describes the three different environments that are available. | Environment | Base URL | Description | |--------------------------------|----------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | Sandbox | `https://sandbox.api.mastercard.com/global-processing/digital` | The Sandbox environment is an open, self-service test environment where developers can experiment with API calls without affecting real data or systems, ensuring that any errors or issues can be safely identified and resolved. To access Sandbox: \* Select **Mastercard Processing Digital** when creating a project. \* Generate your project keys. | | Mastercard Test Facility (MTF) | `https://mtf.api.mastercard.com/global-processing/digital` | The MTF environment provides access to the latest Production release version of the APIs to conduct full User Acceptance Tests (UAT) before moving to Production. It supports end-to-end testing of product functionality through API, batch, and GUI interfaces. MTF is maintained and supported by Mastercard Processing, ensuring it remains functionally aligned with the Production environment. Note: Access to the MTF environment is included as part of the onboarding and implementation process offered by Mastercard Processing. To access MTF, use the same keys generated for Sandbox. | | Production | `https://api.mastercard.com/global-processing/digital` | The Production environment is the live environment where the API interacts with actual users and data. To access Production, select [Request Production Access](https://developer.mastercard.com/dashboard) in the Mastercard Processing Digital project that you have set up. | Note: **Environment-specific auth and encryption:** OAuth 1.0a authentication and JWE payload encryption work the same way across Sandbox, MTF, and Production. The only difference is the base URL. No additional auth or encryption steps are required when promoting to Production. ## Versioning (must read) {#versioning-must-read} As per Mastercard API standards, the Mastercard Processing APIs do not expose versioning in their interfaces. APIs evolve through backwards-compatible changes to ensure that existing client integrations continue to work without modification. The following table provides examples of changes that are considered backwards-compatible (non-breaking) or backwards-incompatible (breaking). | Backward-compatible (non-breaking) changes | Backward-incompatible (breaking) changes | |---------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------| | Adding an API interface to an API service | Removing or renaming a service, interface, field, method, or enum value | | Adding a method to an API interface | Changing an HTTP binding | | Adding an HTTP binding to a method | Changing the data type of a field | | Adding an optional field to a request with backward-compatible default behavior | Changing a resource name format | | Adding a field to a response message | Changing the visible behavior of existing requests | | Adding an output-only resource field | Changing the URL format in the HTTP definition | | Adding a new optional query parameter with a default value (`?parameter=value`) | Adding a read or write field to a resource message | | Adding an HTTP header field to a request/response message | Modifications (adding or modifying) a value to an enum in a response | | Adding a new error code without changing the documented behavior of existing requests | Adding a new mandatory field to a request message without setting a field default value | Note: These examples are not exhaustive. Whether a change is backwards-compatible depends on its impact on the existing API contract and client behavior. Alert: Design your integration to tolerate backwards-compatible API changes. For example, your application must not fail when a response contains a new field that was not present when the integration was originally implemented. Clients should ignore unknown response fields unless explicitly documented otherwise. Mastercard Processing provides a minimum of three months' notice for API changes; see [Announcements](https://developer.mastercard.com/mastercard-processing-digital/documentation/announcements/index.md) and [Release History](https://developer.mastercard.com/mastercard-processing-digital/documentation/release-history/index.md). ## API configuration {#api-configuration} Mastercard Processing Digital API supports a customized configuration for each issuer to align with specific implementation requirements. The configuration includes supported characters, PAN masking, and the API operations enabled for the issuer. The set of available API operations depends on the product being implemented. As part of the onboarding process, the issuer must specify the API operations to be enabled by completing **Worksheet 5 - API Operations** in the **PPW Interfaces** document. Only the operations enabled in the issuer's API configuration can be used. Note: If you try to execute an operationId that is not enabled in your API configuration, you will receive a dedicated error. For more information, see [Error Codes](https://developer.mastercard.com/mastercard-processing-digital/documentation/code-and-formats/index.md). ### PAN masking {#pan-masking} Mastercard Processing Digital API can mask sensitive card data, such as the PAN, in API responses. PAN masking is enabled when the issuer selects **PAN-less** for the **PC.2.1.002 - PAN scope** parameter in the PPW. When PAN masking is enabled, the first six and last four digits of the PAN remain visible, while the remaining digits are replaced with asterisks. For example: 512345XXXXXX3456 ## Idempotency {#idempotency} Idempotency ensures that retrying the same request does not result in the same operation being processed more than once. This is particularly important for `POST` operations, where retrying a request after a timeout or connection failure could otherwise result in duplicate processing. To achieve idempotency, you should send an `Idempotency-Key` header that is unique to each request. The server uses this header, along with the request body, to identify subsequent retries of the same request. The mechanism is intended to work for all `POST` methods. The `Idempotency-Key` header is optional. If the header is not specified in the request, the request is processed normally without idempotency protection. When an `Idempotency-Key` is provided, the following rules apply: * **New `Idempotency-Key`:** If the `Idempotency-Key` has not been used before, the API processes the request normally. After processing is complete, the `Idempotency-Key`, request body, and response body are stored for 24 hours. * **The original request is still being processed:** If the same `Idempotency-Key` is reused while the original request is still being processed, the API rejects the retry with `HTTP 409` and the `IDEMPOTENCY_KEY_ALREADY_IN_PROGRESS` error. Do not submit the same logical operation with a new `Idempotency-Key` while the original request is still being processed, as this could result in duplicate processing. * **Same `Idempotency-Key` and same request body:** If the same Idempotency-Key is reused with the same request body within 24 hours after the original request has completed, the API identifies the request as a retry and returns the previously stored response without processing the operation again. * **Same `Idempotency-Key` and different request body:** If the same `Idempotency-Key` is reused with a different request body within 24 hours, the API rejects the request with `HTTP 422` and the `IDEMPOTENCY_KEY_ALREADY_USED` error because an idempotency key must not be reused for a different payload. * **`Idempotency-Key` reused after 24 hours:** Idempotency records are automatically removed after 24 hours. If an `Idempotency-Key` is reused after this period, the request is processed as a new request. Note: Generate a unique `Idempotency-Key` for each new logical request. Reuse the same key only when retrying the same request with the same request body. ## Correlation-ID {#correlation-id} The Mastercard Processing platform dynamically generates a universally unique identifier (UUID) and assigns it to the request header `X-MC-Correlation-ID`. The UUID is always added to the response header to provide end-to-end traceability. In addition to the `X-MC-Correlation-ID`, you can generate your request identifier and pass it in the `Correlation-ID` header. It is recommended to generate a UUID in compliance with [RFC 4122](https://datatracker.ietf.org/doc/html/rfc4122). ## Next Steps {#next-steps} Now that you have an understanding of the service's authentication and encryption, proceed to the [Use Cases](https://developer.mastercard.com/mastercard-processing-digital/documentation/use-cases/index.md) section to learn about the different use cases of the service.