Python – Metadata errors for strip transactions using python

Metadata errors for strip transactions using python… here is a solution to the problem.

Metadata errors for strip transactions using python

I’m using python for strip payment integration and use the following data:

import requests
import json
pos = requests.post
url = "https://api.stripe.com/v1/sources"
headers = {'AUTHORIZATION': 'Bearer sk_test_NXht3wZpuYWRIWpMDDqT3RG2'}
data = {
    'type': 'alipay',
    'owner[email]': '[email protected]',
    'redirect[return_url]': 'https://www.google.com',
    'amount': '500',
    'currency': 'USD',
    'metadata': {
        'data': 'data'
    }
}
pos(url, data=data, headers=headers).text
json.loads(pos(url, data=data, headers=headers).text)

When metadata is given, it gives error ‘{\n “error”: {\n “message”: “Invalid hash”,\n “param”: “metadata”,\n “type”: “invalid_request_error”\n }\n

}\n’
However, according to the Strip documentation, metadata ( https://stripe.com/docs/api/curl#create_source-metadata)

Can anyone tell the solution why the error is occurring.

Solution

This will solve the problem.

import requests
import json
pos = requests.post
url = "https://api.stripe.com/v1/sources"
headers = {'AUTHORIZATION': 'Bearer sk_test_NXht3wZpuYWRIWpMDDqT3RG2'}
data = {
    'type': 'alipay',
    'owner[email]': '[email protected]',
    'redirect[return_url]': 'https://www.google.com',
    'amount': '500',
    'currency': 'USD',
    'metadata[data]': 'data'
}
pos(url, data=data, headers=headers).text
json.loads(pos(url, data=data, headers=headers).text)

Related Problems and Solutions