PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, November 11, 2022

[FIXED] How to pass the customer id dynamically in the tap payment method to save the card value

 November 11, 2022     django, payment-gateway, python, tap-payment     No comments   

Issue

I am sending the post request to the TAP PAYMENT GATEWAY in order to save the card, the url is expecting two parameters like one is the source (the recently generated token) and inside the url the {customer_id}, I am trying the string concatenation, but it is showing the error like Invalid JSON request.

views.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_**********************",
        '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)

Their expected url = https://api.tap.company/v2/card/{customer_id}

Their documentation link: https://tappayments.api-docs.io/2.0/cards/create-a-card


Solution

Try this.. First convert dict. into JSON and send post request with 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_**************************",
        '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)

Please tell me this works or not...



Answered By - Pradip
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing