Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Metadeta error on stripe transaction using python

I am doing stripe payment integration using python 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 give the metadata it gives error '{\n "error": {\n "message": "Invalid hash",\n "param": "metadata",\n "type": "invalid_request_error"\n }\n}\n' but according to stripe documentation metadata can be used( https://stripe.com/docs/api/curl#create_source-metadata)

Can anyone tell the solution why it gives that error.

like image 259
user_123 Avatar asked Dec 01 '25 06:12

user_123


1 Answers

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)
like image 111
user_123 Avatar answered Dec 03 '25 19:12

user_123



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!