Problem with mastercard API, a bug that is not found in the documentation

93 views Asked by At

I need help, here is my code and below is the problem:

import requests
import json
from requests.auth import HTTPBasicAuth
from api_key_util_con import getAuthHeader, encrypt

BASE_URL = 'https://sandbox.api.mastercard.com/openapis/'

global card_ref

def postInitialApiRequest(request):
    global card_ref

    uri = f'{BASE_URL}authentication/consents'

    # Encrypt the request (using encryption key)
    encryptedRequest = encrypt(request)

    # Form json string
    encryptedRequestJson = json.dumps(encryptedRequest)

    # Create the OAuth signature for this request (using signing key)
    authHeader = getAuthHeader(uri, method='POST',
                               payload=encryptedRequestJson)

    # Headers - we need just authorization and content-type
    headers = {
        'Authorization' : authHeader,
        'Content-Type': 'application/json'
    }

    # Call the API
    response = requests.post(uri, headers=headers,
                             data=encryptedRequestJson, verify=False)
    print(f'Response: {response.text}')
    response_data = response.json()
    card_ref = response_data.get("cardReference")

    return card_ref, auth

def startAuthentication(card_ref, CardDetails):
    uri = f'{BASE_URL}authentication/consents/{card_ref}/start-authentication'

    # Encrypt the request (using encryption key)
    encryptedRequest = encrypt(CardDetails)
    # Form json string
    encryptedRequestJson = json.dumps(encryptedRequest)
    # Create the OAuth signature for this request (using signing key)
    authHeader = getAuthHeader(uri, method='POST', payload=encryptedRequestJson)

    # Headers - we need just authorization and content-type
    headers = {
        'Authorization': authHeader,
        'Content-Type': 'application/json'
    }

    try:
        # Call the API
        response = requests.post(uri, headers=headers,
                                 data=encryptedRequestJson, verify=False)

        # Log request and response details
        print(f'Request URI: {uri}')
        print(f'Response: {response.text}')

        return response.json()

    except Exception as e:
        print(f'Error: {e}')
        return None

Test card's data:

testCardDetails = {
    "consents": [
        {
            "name": "notification",
            "details": {
                "businessName": "CorporateA"
            }
        }
    ],
    "cardDetails": {
        "pan": 5204730541001066,
        "expiryMonth": 1,
        "expiryYear": 2025,
        "cvc": 123,
        "cardholderName": "John"
    }
}

CardDetails = {
    "auth": {
        "type": "THREEDS",
        "params": {}
    },
    "cardDetails": {
        "pan": 5204730541001066,
        "expiryMonth": 1,
        "expiryYear": 2025,
        "cvc": 123,
        "cardholderName": "John"
    }
}
card_ref, auth = postInitialApiRequest(testCardDetails)
startAuthentication(card_ref, CardDetails)

in the second function, an error occurs which I have not found in the documentation:

Response: {"Errors":{"Error":[{"source":"CBC","reasonCode":"rest.failed","description":"400 Bad Request: [{"errorCode":"4003","errorDetail":"3DS Method URL available","errorDescription":"3DS Method Completion Indicator error. 3DS Method URL found in Cache.","threeDSServerTransID":"695d7429-8a27-4ce4-90d3-7ee2c37efe90","errorComponent":"S","messageVersion":"2.2.0"}]","recoverable":false,"details":"0.a1054917.1705427566.ad3570"}]}}

I've tried to put first function's response to the auth, but nothing change

0

There are 0 answers