我仅尝试将Paytm支付网关集成到我的网站以进行UPI交易,因此在阅读了文档之后,我能够集成Initate payment API,但是当我尝试集成{{3} } API,它始终使VPA无效,我添加了代码以供参考,我将my_mid
替换为正确的MID,将my_key
替换为正确的密钥,还将7777777777@paytm
替换为有效的VPA < / p>
import requests
import json
paytmParams = dict()
paytmParams["body"] = {
"vpa" : "7777777777@paytm"
}
paytmParams["head"] = {
"txnToken" : "4f7197de6840450e9162ddb5c067eb221590561957267"
}
post_data = json.dumps(paytmParams)
url = "https://securegw-stage.paytm.in/theia/api/v1/vpa/validate?mid=my_mid&orderId=123abcd"
response = requests.post(url, data = post_data, headers = {"Content-type": "application/json"}).json()
print(response)
执行此操作总是返回
{
"head": {
"requestId": None,
"responseTimestamp": "1590561981014",
"version": "v1"
},
"body": {
"extraParamsMap": None,
"resultInfo": {
"resultStatus": "F",
"resultCode": "501",
"resultMsg": "Sorry! We could not verify the VPA."
},
"vpa": "7777777777@paytm",
"valid": False
}
}
txnToken
是通过以下代码获得的,与VPA无关,
import requests
import json
import hashlib
import base64
import string
import random
from Crypto.Cipher import AES
IV = "@@@@&&&&####$$$$"
BLOCK_SIZE = 16
def __pad__(s): return s + (BLOCK_SIZE - len(s) %
BLOCK_SIZE) * chr(BLOCK_SIZE - len(s) % BLOCK_SIZE)
def __encode__(to_encode, iv, key):
to_encode = __pad__(to_encode)
c = AES.new(key, AES.MODE_CBC, iv)
to_encode = c.encrypt(to_encode)
to_encode = base64.b64encode(to_encode)
return to_encode.decode("UTF-8")
def __id_generator__(size=6, chars=string.ascii_uppercase + string.digits + string.ascii_lowercase):
return ''.join(random.choice(chars) for _ in range(size))
def generate_checksum_by_str(param_str, merchant_key, salt=None):
params_string = param_str
salt = salt if salt else __id_generator__(4)
final_string = '%s|%s' % (params_string, salt)
hasher = hashlib.sha256(final_string.encode())
hash_string = hasher.hexdigest()
hash_string += salt
return __encode__(hash_string, IV, merchant_key)
paytmParams = dict()
paytmParams["body"] = {
"requestType": "Payment",
"mid": "my_mid",
"websiteName": "WEBSTAGING",
"orderId": "123abcd",
"txnAmount": {
"value": "500",
"currency": "INR",
},
"userInfo": {
"custId": "1234567",
},
"enablePaymentMode": [{"mode": "UPI", "channels": ["UPIPUSH"]}]
}
checksum = generate_checksum_by_str(
json.dumps(paytmParams["body"]), "my_key")
paytmParams["head"] = {
"signature" : checksum
}
post_data = json.dumps(paytmParams)
url = "https://securegw-stage.paytm.in/theia/api/v1/initiateTransaction?mid=my_mid&orderId=123abcd"
response = requests.post(url, data=post_data, headers={
"Content-type": "application/json"}).json()
print(response)
请告诉我是否需要更多详细信息,因为我已经进行了各种研究,但没有任何运气。
答案 0 :(得分:0)
您的代码似乎没有任何问题。也许您可以再尝试一次。如果仍然遇到问题,请与Paytm开发人员联系。