[Checkins] SVN: zc.creditcard/ Initial import of zc.creditcard.
Right now this package has just a single
Albertas Agejevas
alga at pov.lt
Wed Nov 14 08:55:53 EST 2007
Log message for revision 81834:
Initial import of zc.creditcard. Right now this package has just a single
utility function: the one that detects credit card types.
Changed:
A zc.creditcard/
A zc.creditcard/trunk/
A zc.creditcard/trunk/bootstrap.py
A zc.creditcard/trunk/buildout.cfg
A zc.creditcard/trunk/setup.py
A zc.creditcard/trunk/src/
A zc.creditcard/trunk/src/zc/
A zc.creditcard/trunk/src/zc/__init__.py
A zc.creditcard/trunk/src/zc/creditcard/
A zc.creditcard/trunk/src/zc/creditcard/__init__.py
A zc.creditcard/trunk/src/zc/creditcard/tests.py
-=-
Added: zc.creditcard/trunk/bootstrap.py
===================================================================
--- zc.creditcard/trunk/bootstrap.py (rev 0)
+++ zc.creditcard/trunk/bootstrap.py 2007-11-14 13:55:52 UTC (rev 81834)
@@ -0,0 +1,48 @@
+##############################################################################
+#
+# Copyright (c) 2006 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Bootstrap a buildout-based project
+
+Simply run this script in a directory containing a buildout.cfg.
+The script accepts buildout command-line options, so you can
+use the -c option to specify an alternate configuration file.
+
+$Id$
+"""
+
+import os, shutil, sys, tempfile, urllib2
+
+tmpeggs = tempfile.mkdtemp()
+
+ez = {}
+exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
+ ).read() in ez
+ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
+
+import pkg_resources
+
+ws = pkg_resources.working_set
+assert os.spawnle(
+ os.P_WAIT, sys.executable, sys.executable,
+ '-c', 'from setuptools.command.easy_install import main; main()',
+ '-mqNxd', tmpeggs, 'zc.buildout',
+ {'PYTHONPATH':
+ ws.find(pkg_resources.Requirement.parse('setuptools')).location
+ },
+ ) == 0
+
+ws.add_entry(tmpeggs)
+ws.require('zc.buildout')
+import zc.buildout.buildout
+zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])
+shutil.rmtree(tmpeggs)
Property changes on: zc.creditcard/trunk/bootstrap.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: zc.creditcard/trunk/buildout.cfg
===================================================================
--- zc.creditcard/trunk/buildout.cfg (rev 0)
+++ zc.creditcard/trunk/buildout.cfg 2007-11-14 13:55:52 UTC (rev 81834)
@@ -0,0 +1,12 @@
+[buildout]
+develop = .
+parts = test mypython
+
+[mypython]
+recipe = zc.recipe.egg
+interpreter = python
+eggs = zc.creditcard
+
+[test]
+recipe = zc.recipe.testrunner
+eggs = zc.creditcard
Property changes on: zc.creditcard/trunk/buildout.cfg
___________________________________________________________________
Name: svn:keywords
+ Id
Added: zc.creditcard/trunk/setup.py
===================================================================
--- zc.creditcard/trunk/setup.py (rev 0)
+++ zc.creditcard/trunk/setup.py 2007-11-14 13:55:52 UTC (rev 81834)
@@ -0,0 +1,21 @@
+from setuptools import setup, find_packages
+
+setup(
+ name = "zc.creditcard",
+ version = "1.0",
+ author = "Zope Corporation",
+ author_email = "zope3-dev#zope.org",
+ description = "Utilities for credit card processing",
+ keywords = "cc credit card",
+
+ packages = find_packages('src'),
+ include_package_data = True,
+ package_dir = {'':'src'},
+ namespace_packages = ['zc'],
+ install_requires = [
+ 'zope.testing',
+ 'setuptools',
+ ],
+ dependency_links = ['http://download.zope.org/distribution/'],
+ license = "ZPL 2.1",
+ )
Property changes on: zc.creditcard/trunk/setup.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: zc.creditcard/trunk/src/zc/__init__.py
===================================================================
--- zc.creditcard/trunk/src/zc/__init__.py (rev 0)
+++ zc.creditcard/trunk/src/zc/__init__.py 2007-11-14 13:55:52 UTC (rev 81834)
@@ -0,0 +1,5 @@
+try:
+ __import__('pkg_resources').declare_namespace(__name__)
+except:
+ # bootstrapping
+ pass
Property changes on: zc.creditcard/trunk/src/zc/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: zc.creditcard/trunk/src/zc/creditcard/__init__.py
===================================================================
--- zc.creditcard/trunk/src/zc/creditcard/__init__.py (rev 0)
+++ zc.creditcard/trunk/src/zc/creditcard/__init__.py 2007-11-14 13:55:52 UTC (rev 81834)
@@ -0,0 +1,85 @@
+"""Utilities for credit card processing
+
+$Id$
+"""
+
+# Constants for the supported card types
+
+AMEX = 'AMEX'
+DISCOVER = 'Discover'
+MASTERCARD = 'MasterCard'
+VISA = 'Visa'
+UNKNOWN_CARD_TYPE = 'Unknown'
+
+
+def identifyCreditCardType(card_num, card_len):
+ """ Identifies the credit card type based on information on the
+ following site(s):
+
+ http://en.wikipedia.org/wiki/Credit_card_number
+ http://www.beachnet.com/~hstiles/cardtype.html
+
+ This checks the prefix (first 4 digits) and the length of the card number to
+ identify the type of the card. This method is used because Authorize.net
+ does not provide this information. This method currently identifies only
+ the following four types:
+
+ 1. VISA
+ 2. MASTERCARD
+ 3. Discover
+ 4. AMEX
+
+ Before we test, lets create a few dummy credit-card numbers:
+
+ >>> amex_card_num = '370000000000002'
+ >>> disc_card_num = '6011000000000012'
+ >>> mc_card_num = '5424000000000015'
+ >>> visa_card_num = '4007000000027'
+ >>> unknown_card_num = '400700000002'
+
+ >>> identifyCreditCardType(amex_card_num, len(amex_card_num)) == AMEX
+ True
+
+ >>> identifyCreditCardType(disc_card_num,
+ ... len(disc_card_num)) == DISCOVER
+ True
+
+ >>> identifyCreditCardType(mc_card_num, len(mc_card_num)) == MASTERCARD
+ True
+
+ >>> identifyCreditCardType(visa_card_num, len(visa_card_num)) == VISA
+ True
+
+ >>> identifyCreditCardType(unknown_card_num,
+ ... len(unknown_card_num)) == UNKNOWN_CARD_TYPE
+ True
+
+ """
+ card_type = UNKNOWN_CARD_TYPE
+ card_1_digit = card_num[0]
+ card_2_digits = card_num[:2]
+ card_4_digits = card_num[:4]
+
+ # AMEX
+ if (card_len == 15) and card_2_digits in ('34', '37'):
+ card_type = AMEX
+
+ # MASTERCARD, DISCOVER & VISA
+ elif card_len == 16:
+ # MASTERCARD
+ if card_2_digits in ('51', '52', '53', '54', '55'):
+ card_type = MASTERCARD
+
+ # DISCOVER
+ elif (card_4_digits == '6011') or (card_2_digits == '65'):
+ card_type = DISCOVER
+
+ # VISA
+ elif (card_1_digit == '4'):
+ card_type = VISA
+
+ # VISA
+ elif (card_len == 13) and (card_1_digit == '4'):
+ card_type = VISA
+
+ return card_type
Property changes on: zc.creditcard/trunk/src/zc/creditcard/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: zc.creditcard/trunk/src/zc/creditcard/tests.py
===================================================================
--- zc.creditcard/trunk/src/zc/creditcard/tests.py (rev 0)
+++ zc.creditcard/trunk/src/zc/creditcard/tests.py 2007-11-14 13:55:52 UTC (rev 81834)
@@ -0,0 +1,13 @@
+"""Tests for zc.ssl
+
+$Id$
+"""
+import unittest
+import zope.testing.doctest
+
+def test_suite():
+ suite = unittest.TestSuite([
+ zope.testing.doctest.DocTestSuite('zc.creditcard'),
+ ])
+
+ return suite
Property changes on: zc.creditcard/trunk/src/zc/creditcard/tests.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
More information about the Checkins
mailing list