我正在尝试将 Paytm 支付网关集成到我的网站仅用于 UPI 交易,因此在浏览文档后,我能够集成Initate 支付API,但是当我尝试集成验证 VPA API 时,它总是使 VPA 无效,我正在添加代码以供参考,我将替换my_mid
为正确的 MID、my_key
正确的密钥以及7777777777@paytm
有效的 VPA
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)
如果需要更多详细信息,请告诉我,因为我已经进行了各种研究,但没有得到任何运气。