Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import json
- client_id = '*******************************************************************'
- secret = '***************************************************************'
- r = requests.post('https://api.sandbox.paypal.com/v1/oauth2/token', auth = (client_id, secret), headers = {'Accept': 'application/json', 'Accept-Language': 'en_US'}, data = {'grant_type': 'client_credentials'})
- token = r.json()['access_token']
- s = """{
- "intent": "sale",
- "payer": {
- "payment_method": "credit_card",
- "funding_instruments": [
- {
- "credit_card": {
- "number": "**********************",
- "type": "visa",
- "expire_month": *,
- "expire_year": ****,
- "cvv2": ***,
- "first_name": "John",
- "last_name": "Doe"
- }
- }
- ]
- },
- "transactions": [
- {
- "amount": {
- "total": "7.47",
- "currency": "USD"
- },
- "description": "Test payment from API."
- }
- ]
- }"""
- post_data = json.loads(s)
- r2 = requests.post('https://api.sandbox.paypal.com/v1/payments/payment', headers = {'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token}, data = post_data)
- In [10]: r2.status_code
- Out[10]: 400
- In [11]: r2.text
- Out[11]: u'{"name":"MALFORMED_REQUEST","message":"The request JSON is not well formed.","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST","debug_id":"************"}'
Advertisement
Add Comment
Please, Sign In to add comment