Created
September 19, 2012 20:31
-
-
Save robrocker7/3752082 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import httplib, urllib | |
from django.utils import simplejson | |
""" | |
curl -s --insecure -H "X-PAYPAL-SECURITY-USERID: Your_API_username" | |
-H "X-PAYPAL-SECURITY-PASSWORD: Your_API_password" | |
-H "X-PAYPAL-SECURITY-SIGNATURE: Your_API_signature" | |
-H "X-PAYPAL-REQUEST-DATA-FORMAT: NV" | |
-H "X-PAYPAL-RESPONSE-DATA-FORMAT: NV" | |
-H "X-PAYPAL-APPLICATION-ID: Your_AppID" | |
https://svcs.sandbox.paypal.com/Invoice/CreateInvoice | |
-d "requestEnvelope.errorLanguage=en_US \ | |
&invoice.merchantEmail=merchant%40domain.com \ | |
&invoice.payerEmail=jbui-us-business2%40paypal.com \ | |
&invoice.currencyCode=USD \ | |
&invoice.itemList.item(0).name=Banana+Leaf+--+001 \ | |
&invoice.itemList.item(0).description=Banana+Leaf \ | |
&invoice.itemList.item(0).quantity=1 \ | |
&invoice.itemList.item(0).unitPrice=1 \ | |
&invoice.itemList.item(0).taxName=Tax1 \ | |
&invoice.itemList.item(0).taxRate=10.25 \ | |
&invoice.paymentTerms=Net10 \ | |
&invoice.logoUrl=https%3A%2F%2Fwww.example.com%2FYour_logo.jpg" | |
""" | |
class Paypal(object): | |
url = '' | |
username = 'richard_api1sdfasdfaasdftions.com' | |
password = 'KYSFRQXYDH6G2dfsasdfasdf5PF' | |
signature = 'ARlxMGPncf0dyEVdfsasdafsdfMtrYwM8Z6fevoAebymVUG0ooCYo7hN9BGKXP1L0rx' | |
def send(self, params): | |
headers = { | |
'X-PAYPAL-SECURITY-USERID': self.username, | |
'X-PAYPAL-SECURITY-PASSWORD': self.password, | |
'X-PAYPAL-SECURITY-SIGNATURE': self.signature, | |
'X-PAYPAL-REQUEST-DATE-FORMAT': 'JSON', | |
'X-PAYPAL-RESPONSE-DATA-FORMAT': 'JSON', | |
} | |
conn = httplib.HTTPSConnection(self.url) | |
conn.request("POST", "/Invoice/CreateInvoice", urllib.urlencode(params), headers) | |
response = conn.getresponse() | |
print response.status, response.reason | |
print response.read() | |
conn.close() | |
class Create(Paypal): | |
def __init__(self): | |
self.url = 'svcs.sandbox.paypal.com' | |
self.send({ | |
'invoice': { | |
'merchantEmail': '[email protected]', | |
'payerEmail': '[email protected]', | |
'currencyCode': 'USD', | |
'itemList': { | |
'item': [ | |
{ | |
'name': 'IRA Intake Packet', | |
'description': 'The steps to take', | |
'quantity': '1', | |
'unitPrice': '1950', | |
'taxName': 'TaxName', | |
'taxRate': '0.00', | |
} | |
] | |
}, | |
'paymentTerms': 'Net10', | |
'logoUrl': '' | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment