pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

python private pastebin - collaborative debugging tool What's a private pastebin?


Posted by Michael Atlas on Thu 13 Sep 21:16 (modification of post by Michael Atlas view diff)
report spam | View followups from Anonymous | download | new post

  1. #!/usr/bin/env python
  2.  
  3. # PayPal python NVP API wrapper class.
  4. # This is a sample to help others get started on working
  5. # with the PayPal NVP API in Python.
  6. # This is not a complete reference! Be sure to understand
  7. # what this class is doing before you try it on production servers!
  8. # ...use at your own peril.
  9.  
  10. ## see https://www.paypal.com/IntegrationCenter/ic_nvp.html
  11. ## and
  12. ## https://www.paypal.com/en_US/ebook/PP_NVPAPI_DeveloperGuide/index.html
  13. ## for more information.
  14.  
  15. # by Mike Atlas / LowSingle.com / MassWrestling.com, September 2007
  16. # No License Expressed. Feel free to distribute, modify,
  17. #  and use in any open or closed source project without credit to the author
  18.  
  19. # Example usage: ===============
  20. #       paypal = PayPal()
  21. #       pp_token = paypal.SetExpressCheckout(100)
  22. #       express_token = paypal.GetExpressCheckoutDetails(pp_token)
  23. #       url= paypal.PAYPAL_URL + express_token
  24. #       HttpResponseRedirect(url) ## django specific http redirect call for payment
  25.  
  26.  
  27. import urllib, md5, datetime
  28.  
  29. class PayPal:
  30.         """ #PayPal utility class"""
  31.         signature_values = {}
  32.         API_ENDPOINT = ""
  33.         PAYPAL_URL = ""
  34.        
  35.         def __init__(self):
  36.                 ## Sandbox values
  37.                 self.signature_values = {
  38.                 'USER' : 'xxxx_xxxxxxxx_xx.xxxxxxxxxx.com', # Edit this to your API user name
  39.                 'PWD' : 'xxxxxxxxxxxxxxx', # Edit this to your API password
  40.                 'SIGNATURE' : 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', # edit this to your API signature
  41.                 'VERSION' : '3.0',
  42.                 }
  43.                 self.API_ENDPOINT = 'https://api-3t.sandbox.paypal.com/nvp' # Sandbox URL, not production
  44.                 self.PAYPAL_URL = 'https://www.sandbox.paypal.com/webscr&cmd=_express-checkout&token=' # Sandbox URL, not production
  45.                 self.signature = urllib.urlencode(self.signature_values) + "&"
  46.  
  47.         # API METHODS
  48.         def SetExpressCheckout(self, amount):
  49.                 params = {
  50.                         'METHOD' : "SetExpressCheckout",
  51.                         'NOSHIPPING' : 1,
  52.                         'PAYMENTACTION' : 'Authorization',
  53.                         'RETURNURL' : 'http://www.yoursite.com/returnurl', #edit this
  54.                         'CANCELURL' : 'http://www.yoursite.com/cancelurl', #edit this
  55.                         'AMT' : amount,
  56.                 }
  57.  
  58.                 params_string = self.signature + urllib.urlencode(params)
  59.                 response = urllib.urlopen(self.API_ENDPOINT, params_string).read()
  60.                 response_token = ""
  61.                 for token in response.split('&'):
  62.                         if token.find("TOKEN=") != -1:
  63.                                 response_token = token[ (token.find("TOKEN=")+6):]
  64.                 return response_token
  65.        
  66.         def GetExpressCheckoutDetails(self, token):
  67.                 params = {
  68.                         'METHOD' : "GetExpressCheckoutDetails",
  69.                         'RETURNURL' : 'http://www.yoursite.com/returnurl', #edit this
  70.                         'CANCELURL' : 'http://www.yoursite.com/cancelurl', #edit this
  71.                         'TOKEN' : token,
  72.                 }
  73.                 params_string = self.signature + urllib.urlencode(params)
  74.                 response = urllib.urlopen(self.API_ENDPOINT, params_string).read()
  75.                 response_tokens = {}
  76.                 for token in response.split('&'):
  77.                         response_tokens[token.split("=")[0]] = token.split("=")[1]
  78.                 return response_tokens
  79.        
  80.         def DoExpressCheckoutPayment(self, token, payer_id, amt):
  81.                 params = {
  82.                         'METHOD' : "DoExpressCheckoutPayment",
  83.                         'PAYMENTACTION' : 'Sale',
  84.                         'RETURNURL' : 'http://www.yoursite.com/returnurl', #edit this
  85.                         'CANCELURL' : 'http://www.yoursite.com/cancelurl', #edit this
  86.                         'TOKEN' : token,
  87.                         'AMT' : amt,
  88.                         'PAYERID' : payer_id,
  89.                 }
  90.                 params_string = self.signature + urllib.urlencode(params)
  91.                 response = urllib.urlopen(self.API_ENDPOINT, params_string).read()
  92.                 response_tokens = {}
  93.                 for token in response.split('&'):
  94.                         response_tokens[token.split("=")[0]] = token.split("=")[1]
  95.                 for key in response_tokens.keys():
  96.                                 response_tokens[key] = urllib.unquote(response_tokens[key])
  97.                 return response_tokens
  98.                
  99.         def GetTransactionDetails(self, tx_id):
  100.                 params = {
  101.                         'METHOD' : "GetTransactionDetails",
  102.                         'TRANSACTIONID' : tx_id,
  103.                 }
  104.                 params_string = self.signature + urllib.urlencode(params)
  105.                 response = urllib.urlopen(self.API_ENDPOINT, params_string).read()
  106.                 response_tokens = {}
  107.                 for token in response.split('&'):
  108.                         response_tokens[token.split("=")[0]] = token.split("=")[1]
  109.                 for key in response_tokens.keys():
  110.                                 response_tokens[key] = urllib.unquote(response_tokens[key])
  111.                 return response_tokens
  112.                                
  113.         def MassPay(self, email, amt, note, email_subject):
  114.                 unique_id = str(md5.new(str(datetime.datetime.now())).hexdigest())
  115.                 params = {
  116.                         'METHOD' : "MassPay",
  117.                         'RECEIVERTYPE' : "EmailAddress",
  118.                         'L_AMT0' : amt,
  119.                         'CURRENCYCODE' : 'USD',
  120.                         'L_EMAIL0' : email,
  121.                         'L_UNIQUE0' : unique_id,
  122.                         'L_NOTE0' : note,
  123.                         'EMAILSUBJECT': email_subject,
  124.                 }
  125.                 params_string = self.signature + urllib.urlencode(params)
  126.                 response = urllib.urlopen(self.API_ENDPOINT, params_string).read()
  127.                 response_tokens = {}
  128.                 for token in response.split('&'):
  129.                         response_tokens[token.split("=")[0]] = token.split("=")[1]
  130.                 for key in response_tokens.keys():
  131.                                 response_tokens[key] = urllib.unquote(response_tokens[key])
  132.                 response_tokens['unique_id'] = unique_id
  133.                 return response_tokens
  134.                                
  135.         def DoDirectPayment(self, amt, ipaddress, acct, expdate, cvv2, firstname, lastname, cctype, street, city, state, zipcode):
  136.                 params = {
  137.                         'METHOD' : "DoDirectPayment",
  138.                         'PAYMENTACTION' : 'Sale',
  139.                         'AMT' : amt,
  140.                         'IPADDRESS' : ipaddress,
  141.                         'ACCT': acct,
  142.                         'EXPDATE' : expdate,
  143.                         'CVV2' : cvv2,
  144.                         'FIRSTNAME' : firstname,
  145.                         'LASTNAME': lastname,
  146.                         'CREDITCARDTYPE': cctype,
  147.                         'STREET': street,
  148.                         'CITY': city,
  149.                         'STATE': state,
  150.                         'ZIP':zipcode,
  151.                         'COUNTRY' : 'United States',
  152.                         'COUNTRYCODE': 'US',
  153.                         'RETURNURL' : 'http://www.yoursite.com/returnurl', #edit this
  154.                         'CANCELURL' : 'http://www.yoursite.com/cancelurl', #edit this
  155.                         'L_DESC0' : "Desc: ",
  156.                         'L_NAME0' : "Name: ",
  157.                 }
  158.                 params_string = self.signature + urllib.urlencode(params)
  159.                 response = urllib.urlopen(self.API_ENDPOINT, params_string).read()
  160.                 response_tokens = {}
  161.                 for token in response.split('&'):
  162.                         response_tokens[token.split("=")[0]] = token.split("=")[1]
  163.                 for key in response_tokens.keys():
  164.                         response_tokens[key] = urllib.unquote(response_tokens[key])
  165.                 return response_tokens

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me