gchecky

Package gchecky |
[hide private]
[frames] | no frames]

# Source Code for Package gchecky

      1  """
      2  Gchecky provides an abstraction layer between google checkout API and user code.
      3
      4  It wraps-up the clumsy Level 2 integration API into a human-friendly form.
      5
      6  All the interaction between Checkout API and user code is handled by
      7  the library, which includes the following topics:
      8    - generating/validating/parsing XML messages for/from Google Checkout API
      9    - transforming the xml DOM trees into a human-friendly structures
     10      almost word-by-word following the official specification from google.
     11    - does the technical low-level tasks such as generating authentication
     12      token from user vendor_id and merchant_key etc.
     13    - parses Google Checkout API notification messages and runs
     14      the corresponding hook methods.
     15
     16  Intergration of the library consists of four phases:
     17    1. gather your account settings such as your vendor_id, merchant_key,
     18       your local currency symbol (ATM either 'USD' or 'GBP')
     19    2. create a unique instance of L{gchecky.ControllerLevel_2} class by
     20       subclassing it. Provide custom implementation to the abstract methods.
     21       Basically all you need is to define your reaction to various API
     22       notifications (see step 5 for details).
     23    3. set up a separate background thread for sending requests to
     24       U{Google Checkout API <http://code.google.com/apis/checkout/developer/index.html#order_processing_api>}.
     25    4. set up a web-handler at a publicly accessible url. Refer to the
     26       U{Google Checkout Notification API
     27       <http://code.google.com/apis/checkout/developer/index.html#handling_notifications>}.
     28       But instead of processing incoming XML messages yourself, it should
     29       pass the incoming request text to your customized instance of
     30       L{gchecky.ControllerLevel_2} (to L{gchecky.ControllerLevel_2.recieve}).
     31    5. Provide your local order-processing system integration by overriding
     32       abstract methods of your custom instance of L{gchecky.ControllerLevel_2}
     33       (see steps 2 and 3).
     34       Basically you will need to store Orders in your custom order-processing
     35       system, update it state every time you receive a notification from
     36       Google Checkout Notification API (notifications correspond to abstract
     37       Controller.on_XXX methods). Plus in the step 3 you will need to scan your
     38       Order list and perform actions on those orders which are ready for the
     39       further processing (charging, refunding, delivering etc.)
     40
     41  @author: etarassov
     42  @version: $Revision $
     43  @contact: gchecky at gmail
     44  """
     45
     46  import os.path
     47  import re
     48
     49  VERSION = (0, 2, 1)
     50
     51 -def version(version=VERSION):
     52      """
     53      Return version string.
     54      >>> version((0,1,1))
     55      '0.1.1'
     56      >>> version((0,1,0))
     57      '0.1.0'
     58      >>> version(VERSION) == version()
     59      True
     60      """
     61      return '.'.join([str(v) for v in version])
     62
     63 -def human_version(version=VERSION):
     64      """
     65      Return human-friendly version string.
     66      >>> human_version((0,1,0))
     67      '0.1'
     68      >>> human_version(VERSION) == human_version()
     69      True
     70      """
     71      # For a release version do not include the minor revision number '.0'
     72      human_version = '.'.join([str(v) for v in version[:-1]])
     73      # For maintenance versions replace the minor number by SVN revision.
     74      if version[-1]:
     75          rev = None
     76          # Do as django does - try to manually parse svn/entries file:
     77          import gchecky
     78          entries_path = '%s/.svn/entries' % (gchecky.__path__[0])
     79          if os.path.exists(entries_path):
     80              entries = open(entries_path, 'r').read()
     81              # Versions >= 7 of the entries file are flat text.  The first line is
     82              # the version number. The next set of digits after 'dir' is the revision.
     83              if re.match('(\d+)', entries):
     84                  rev_match = re.search('\d+\s+dir\s+(\d+)', entries)
     85                  if rev_match:
     86                      rev = rev_match.groups()[0]
     87              # Older XML versions of the file specify revision as an attribute of
     88              # the first entries node.
     89              else:
     90                  from xml.dom import minidom
     91                  dom = minidom.parse(entries_path)
     92                  rev = dom.getElementsByTagName('entry')[0].getAttribute('revision')
     93          if not rev:
     94              rev = 'unknown'
     95          human_version = '%s-%s-SVN%s' % (human_version, version[-1], rev)
     96      return human_version
     97
     98  if __name__ == "__main__":
     99 -    def run_doctests():
    100          import doctest
    101          doctest.testmod()
    102      run_doctests()
    103