diff --git a/README.rst b/README.rst index 558cc8e8..101d452a 100644 --- a/README.rst +++ b/README.rst @@ -36,6 +36,10 @@ The package is released under the new BSD license. Changelog --------- +0.2.5 +~~~~~ +* Fix silly bug with reference transactions + 0.2.4 ~~~~~ * Fix bug with installing templates diff --git a/paypal/__init__.py b/paypal/__init__.py index d0c61da8..bcddf3af 100644 --- a/paypal/__init__.py +++ b/paypal/__init__.py @@ -1 +1 @@ -VERSION = '0.2.4' +VERSION = '0.2.5' diff --git a/paypal/payflow/facade.py b/paypal/payflow/facade.py index effc2903..a7f1b2be 100644 --- a/paypal/payflow/facade.py +++ b/paypal/payflow/facade.py @@ -131,15 +131,15 @@ def referenced_sale(order_number, pnref, amt): payment details. 2. It allows an initial authorisation to be settled in multiple parts. The - first settle should use delayed_capture but any subsequent ones should use this method. + first settle should use delayed_capture but any subsequent ones should + use this method. :order_number: Order number. :pnref: PNREF of a previous transaction to use. :amt: The amount to settle for. """ - txn = gateway.reference_transaction(order_number, - pnref, - amt) + txn = gateway.reference_transaction( + order_number, pnref, amt) if not txn.is_approved: raise exceptions.UnableToTakePayment(txn.respmsg) return txn diff --git a/paypal/payflow/gateway.py b/paypal/payflow/gateway.py index d7555dfe..e470961a 100644 --- a/paypal/payflow/gateway.py +++ b/paypal/payflow/gateway.py @@ -89,7 +89,8 @@ def reference_transaction(order_number, pnref, amt): """ params = { 'COMMENT1': order_number, - # Use SALE as we are effectively authorisating and settling a new transaction + # Use SALE as we are effectively authorising and settling a new + # transaction 'TRXTYPE': codes.SALE, 'ORIGID': pnref, 'AMT': amt, @@ -136,7 +137,7 @@ def _transaction(extra_params): # Validate constraints on parameters constraints = { codes.AUTHORIZATION: ('ACCT', 'AMT', 'EXPDATE'), - codes.SALE: ('ACCT', 'AMT', 'EXPDATE'), + codes.SALE: ('AMT',), codes.DELAYED_CAPTURE: ('ORIGID',), codes.CREDIT: ('ORIGID',), codes.VOID: ('ORIGID',), @@ -170,7 +171,8 @@ def _transaction(extra_params): # Ensure that any amounts have a currency and are formatted correctly if 'AMT' in params: if 'CURRENCY' not in params: - params['CURRENCY'] = getattr(settings, 'PAYPAL_PAYFLOW_CURRENCY', 'USD') + params['CURRENCY'] = getattr(settings, + 'PAYPAL_PAYFLOW_CURRENCY', 'USD') params['AMT'] = "%.2f" % params['AMT'] if getattr(settings, 'PAYPAL_PAYFLOW_PRODUCTION_MODE', False): @@ -183,6 +185,7 @@ def _transaction(extra_params): pairs = gateway.post(url, params) # Beware - this log information will contain the Payflow credentials + # only use it in development, not production. logger.debug("Raw request: %s", pairs['_raw_request']) logger.debug("Raw response: %s", pairs['_raw_response']) diff --git a/requirements.txt b/requirements.txt index 8f60c079..f37eec81 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,3 +5,4 @@ django-nose==1.0 nose==1.1.2 django-extensions==0.8 django-debug-toolbar==0.9.4 +pinocchio==0.3.1 diff --git a/runtests.py b/runtests.py index f6d0be32..bc06c53c 100755 --- a/runtests.py +++ b/runtests.py @@ -64,15 +64,15 @@ ), DEBUG=False, SOUTH_TESTS_MIGRATE=False, - HAYSTACK_CONNECTIONS = { + HAYSTACK_CONNECTIONS={ 'default': { 'ENGINE': 'haystack.backends.simple_backend.SimpleEngine', }, }, - TEMPLATE_DIRS = (OSCAR_MAIN_TEMPLATE_DIR,), + TEMPLATE_DIRS=(OSCAR_MAIN_TEMPLATE_DIR,), SITE_ID=1, ROOT_URLCONF='tests.urls', - NOSE_ARGS=['-s'], + NOSE_ARGS=['-s', '--with-spec'], **extra_settings ) @@ -88,7 +88,7 @@ def run_tests(*test_args): test_args = ['tests'] # Run tests - test_runner = NoseTestSuiteRunner(verbosity=2) + test_runner = NoseTestSuiteRunner(verbosity=1) c = coverage(source=['paypal'], omit=['*migrations*', '*tests*']) c.start() @@ -100,6 +100,7 @@ def run_tests(*test_args): print "Generating HTML coverage report" c.html_report() + def generate_migration(): from south.management.commands.schemamigration import Command com = Command() diff --git a/tests/unit/payflow/gateway_tests.py b/tests/unit/payflow/gateway_tests.py index f75281ba..472436ab 100644 --- a/tests/unit/payflow/gateway_tests.py +++ b/tests/unit/payflow/gateway_tests.py @@ -65,3 +65,19 @@ def test_error_handled_gracefully(self): cvv='123', expiry_date='0113', amt=D('10.8000')) + + +class TestReferenceTransaction(TestCase): + + def test_for_smoke(self): + with mock.patch('paypal.gateway.post') as mock_post: + mock_post.return_value = { + 'RESULT': '1', + 'RESPMSG': '', + '_raw_request': '', + '_raw_response': '', + '_response_time': 1000 + } + gateway.reference_transaction(order_number='12345', + pnref='111222', + amt=D('12.23'))