我需要帮助,这是我的代码,下面是问题:
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
测试卡数据:
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)
在第二个函数中,出现了我在文档中未找到的错误:
响应:{“错误”:{“错误”:[{“源”:“CBC”,“reasonCode”:“rest.failed”,“描述”:“400 错误请求:[{“errorCode”:“4003 ","errorDetail":"3DS 方法 URL 可用","errorDescription":"3DS 方法完成指示器错误。在缓存中找到 3DS 方法 URL。","thirdDSServerTransID":"695d7429-8a27-4ce4-90d3-7ee2c37efe90","errorComponent":"S","messageVersion":"2.2.0"}]","可恢复": false,"详细信息":"0.a1054917.1705427566.ad3570"}]}}
我尝试将第一个函数的响应放入身份验证,但没有任何变化
您在“pan”字段(/卡号)中使用整数,但它 可能预期为字符串。
该错误表明在以下位置找到了 3D 安全方法 URL: 缓存。清除 3D 安全事务所在的缓存 已处理。
验证您的 3D 安全配置(包括方法 URL)是 正确。
确保配置符合您的规格 支付网关或卡处理器。