Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在tap支付方式中动态传递客户id以保存卡值_Python_Django_Payment Gateway_Tap Payment - Fatal编程技术网

Python 如何在tap支付方式中动态传递客户id以保存卡值

Python 如何在tap支付方式中动态传递客户id以保存卡值,python,django,payment-gateway,tap-payment,Python,Django,Payment Gateway,Tap Payment,我将post请求发送到点击支付网关以保存卡,url需要两个参数,其中一个是源(最近生成的令牌),在url中的{customer\u id}中,我正在尝试字符串连接,但它显示的错误类似于无效的JSON请求 视图。py: ifCustomerExits = CustomerIds.objects.filter(email=email) totalData = ifCustomerExits.count() if totalData > 1: for data in ifCustomer

我将
post
请求发送到点击支付网关以保存卡,
url
需要两个参数,其中一个是源(最近生成的令牌),在
url
中的
{customer\u id}
中,我正在尝试
字符串
连接,但它显示的错误类似于无效的
JSON
请求

视图。py:

ifCustomerExits = CustomerIds.objects.filter(email=email)
totalData = ifCustomerExits.count()
if totalData > 1:
    for data in ifCustomerExits:
        customerId = data.customer_id
        print("CUSTOMER_ID CREATED ONE:", customerId)
    tokenId = request.session.get('generatedTokenId')
    payload = {
        "source": tokenId
    }

    headers = {                        
        'authorization': "Bearer sk_test_XKokBfNWv6FIYuTMg5sLPjhJ",
        'content-type': "application/json"
    }

    # HERE DOWN IS THE url of TAP COMPANY'S API:

    url = "https://api.tap.company/v2/card/%7B"+customerId+"%7D"
    response = requests.request("POST", url, data=payload, headers=headers)
    json_data3 = json.loads(response.text)
    card_id = json_data3["id"]
    return sponsorParticularPerson(request, sponsorProjectId)
他们期望的url=

他们的文档链接:

试试这个。。 首先转换
dict
。进入
JSON
并发送
post
请求和
request。post

    import json
    ...
    customerId = str(data.customer_id)
    print("CUSTOMER_ID CREATED ONE:", customerId)
    tokenId = request.session.get('generatedTokenId')
    payload = {
    "source": tokenId
    }

    headers = {                        
        'authorization': "Bearer sk_test_XKokBfNWv6FIYuTMg5sLPjhJ",
        'content-type': "application/json"
    }
    pd = json.dumps(payload)
    # HERE DOWN IS THE url of TAP COMPANY'S API:

    url = "https://api.tap.company/v2/card/%7B"+customerId+"%7D"
    response = requests.post(url, data=pd, headers=headers)
    json_data3 = json.loads(response.text)
    card_id = json_data3["id"]
    return sponsorParticularPerson(request, card_id)
导入json
...
customerId=str(data.customer\u id)
打印(“客户ID已创建:”,客户ID)
tokenId=request.session.get('generatedTokenId')
有效载荷={
“源”:令牌ID
}
标题={
“授权”:“承载sk_测试”\XKokBfNWv6FIYuTMg5sLPjhJ”,
“内容类型”:“应用程序/json”
}
pd=json.dumps(有效负载)
#下面是TAP公司API的url:
url=”https://api.tap.company/v2/card/%7B“+客户ID+%7D”
response=requests.post(url,data=pd,headers=headers)
json_data3=json.load(response.text)
卡片id=json\U数据3[“id”]
返回赞助商或参与者(请求、卡id)

请告诉我这是否有效…

非常感谢,先生,它进展了一点,至少现在它正确地发送了请求,现在它显示了错误状态,如下所示,可能是因为,我使用了伪安全密钥,如sk_test。。。错误消息:{'status':'fail','type':'card_not_saved','MESSAGE':'Failed to save the card'}@USAMAREHMANYOUSAF如果欢迎您的话。我从未使用过
点击支付网关
。但每个支付网关都提供测试密钥和私钥。转到您的支付网关仪表板并生成测试密钥。请参阅:先生,它现在工作正常,感谢您的帮助。。。!