Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

suds client cache, better tests

  • Loading branch information...
commit afb2d394a45d9ddfbef6546cdb6e131c78908e4b 1 parent f04f0d8
@cpinto cpinto authored
View
21 billing/gateways/paylane_gateway.py
@@ -4,6 +4,7 @@
import datetime
from suds.client import Client
+from suds.cache import ObjectCache
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
@@ -14,7 +15,9 @@
from billing.signals import transaction_was_successful,transaction_was_unsuccessful
class PaylaneGateway(Gateway):
-
+ """
+
+ """
default_currency = "EUR"
supported_cardtypes = [Visa,MasterCard]
supported_countries = ['PT',]
@@ -22,16 +25,16 @@ class PaylaneGateway(Gateway):
display_name = 'Paylane'
def __init__(self):
- wsdl = 'https://direct.paylane.com/wsdl/production/Direct.wsdl'
-
+ wsdl = getattr(settings,'PAYLANE_WSDL','https://direct.paylane.com/wsdl/production/Direct.wsdl')
+ wsdl_cache = getattr(settings,'SUDS_CACHE_DIR','/tmp/suds')
if self.test_mode:
- username = getattr(settings, "PAYLANE_USERNAME_TEST", '')
- password = getattr(settings, "PAYLANE_PASSWORD_TEST", '')
+ username = getattr(settings, 'PAYLANE_USERNAME_TEST', '')
+ password = getattr(settings, 'PAYLANE_PASSWORD_TEST', '')
else:
username = settings.PAYLANE_USERNAME
password = settings.PAYLANE_PASSWORD
- self.client = Client(wsdl, username=username, password=password)
+ self.client = Client(wsdl, username=username, password=password,cache = ObjectCache(location=wsdl_cache,days=15))
def _validate(self,card):
if not isinstance(card,CreditCard):
@@ -128,6 +131,12 @@ def recurring(self,money,credit_card,options=None):
}
def bill_recurring(self,amount,paylane_response,description):
+ """ Debit a recurring transaction payment, eg. monthly subscription.
+
+ Use the result of recurring() as the paylane_response parameter.
+ If this transaction is successful, use it's response as input for the
+ next bill_recurring() call.
+ """
processing_date = datetime.datetime.today().strftime("%Y-%m-%d")
res = self.client.service.resale(id_sale=paylane_response.sale_authorization_id,amount=amount,currency=self.default_currency,
description=description,processing_date=processing_date)
View
3  billing/models/paylane_models.py
@@ -7,5 +7,8 @@ class PaylaneResponse(models.Model):
#this enables recurring payments
sale_authorization_id = models.BigIntegerField()
+ def __unicode__(self):
+ return 'Authorization: %s' % (self.sale_authorization_id)
+
class Meta:
app_label = __name__.split(".")[0]
View
32 billing/tests/paylane_tests.py
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
# vim:tabstop=4:expandtab:sw=4:softtabstop=4
+import time
+
from django.test import TestCase
from billing.gateway import CardNotSupported
from billing.utils.credit_card import Visa,CreditCard
@@ -34,7 +36,7 @@ def testOneShotPurchaseOK(self):
options['customer'] = self.customer
options['product'] = self.product
res = self.merchant.purchase(1.0,credit_card,options=options)
- self.assertEqual(res['status'],'SUCCESS',res)
+ self.assertEqual(res['status'],'SUCCESS',unicode(res['response']))
self.assertTrue(isinstance(res['response'],PaylaneResponse))
self.assertTrue(res['response'].sale_authorization_id > 0)
@@ -44,19 +46,39 @@ def testRecurringSetupOK(self):
options['customer'] = self.customer
options['product'] = self.product
res = self.merchant.recurring(1.0,credit_card,options=options)
- self.assertEqual(res['status'],'SUCCESS',res)
+ self.assertEqual(res['status'],'SUCCESS',unicode(res['response']))
self.assertTrue(isinstance(res['response'],PaylaneResponse))
self.assertTrue(res['response'].sale_authorization_id > 0)
def testRecurringBillingOK(self):
+ time.sleep(60)
credit_card = Visa(first_name='Celso',last_name='Pinto',month=10,year=2012,number='4111111111111111',verification_value=435)
options = {}
options['customer'] = self.customer
options['product'] = self.product
res = self.merchant.purchase(1.0,credit_card,options=options)
- self.assertEqual(res['status'],'SUCCESS',res)
+ self.assertEqual(res['status'],'SUCCESS',unicode(res['response']))
+ time.sleep(60)
pr = res['response']
res = self.merchant.bill_recurring(12.0,pr,'OK recurring')
- self.assertEqual(res['status'],'SUCCESS',res)
-
+ self.assertEqual(res['status'],'SUCCESS',unicode(res['response']))
+
+ time.sleep(60)
+ res = self.merchant.bill_recurring(12.0,pr,'OK recurring')
+ self.assertEqual(res['status'],'SUCCESS',unicode(res['response']))
+
+ def testRecurringBillingFailWithChargeback(self):
+ time.sleep(60)
+ credit_card = Visa(first_name='Celso',last_name='Pinto',month=10,year=2012,number='4111111111111111',verification_value=435)
+ options = {}
+ options['customer'] = self.customer
+ options['product'] = self.product
+ res = self.merchant.purchase(1.0,credit_card,options=options)
+ self.assertEqual(res['status'],'SUCCESS',unicode(res['response']))
+
+ time.sleep(60)
+ pr = res['response']
+ res = self.merchant.bill_recurring(float(PaylaneError.ERR_RESALE_WITH_CHARGEBACK),pr,'OK recurring')
+ self.assertEqual(res['status'],'FAILURE',unicode(res['response']))
+ self.assertEqual(res['response'].error_code,PaylaneError.ERR_RESALE_WITH_CHARGEBACK)
Please sign in to comment.
Something went wrong with that request. Please try again.