Guest User

Untitled

a guest
Jun 27th, 2013
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.47 KB | None | 0 0
  1. import requests
  2. import json
  3.  
  4. client_id = '*******************************************************************'
  5. secret = '***************************************************************'
  6.  
  7. 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'})
  8.  
  9. token = r.json()['access_token']
  10.  
  11. s = """{
  12.  "intent": "sale",
  13.  "payer": {
  14.    "payment_method": "credit_card",
  15.    "funding_instruments": [
  16.      {
  17.        "credit_card": {
  18.          "number": "**********************",
  19.          "type": "visa",
  20.          "expire_month": *,
  21.          "expire_year": ****,
  22.          "cvv2": ***,
  23.          "first_name": "John",
  24.          "last_name": "Doe"
  25.        }
  26.      }
  27.    ]
  28.  },
  29.  "transactions": [
  30.    {
  31.      "amount": {
  32.        "total": "7.47",
  33.        "currency": "USD"
  34.      },
  35.      "description": "Test payment from API."
  36.    }
  37.  ]
  38. }"""
  39.  
  40. post_data = json.loads(s)
  41.  
  42. r2 = requests.post('https://api.sandbox.paypal.com/v1/payments/payment', headers = {'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token}, data = post_data)
  43.  
  44. In [10]: r2.status_code
  45. Out[10]: 400
  46.  
  47. In [11]: r2.text
  48. 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