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

2024-09-27 00:15:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在将post请求发送到点击支付网关以保存卡,url需要两个参数,比如一个是源(最近生成的令牌),在url{customer_id}内,我正在尝试string连接,但它显示了错误,比如无效的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=https://api.tap.company/v2/card/{customer_id}

他们的文档链接:https://tappayments.api-docs.io/2.0/cards/create-a-card


Tags: httpsapiidjsonurldataemailrequest
1条回答
网友
1楼 · 发布于 2024-09-27 00:15:51

试试这个。。 第一次转换dict。进入JSON并使用request.post发送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)

请告诉我这是否有效

相关问题 更多 >

    热门问题