Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

simplifed code a bit; made amount a settings variable

  • Loading branch information...
commit a7777d82833fecfc702533354bc68386a2a80890 1 parent b62511f
@imagescape imagescape authored
Showing with 26 additions and 47 deletions.
  1. +26 −47 apps/ad/ccforms.py
View
73 apps/ad/ccforms.py
@@ -50,8 +50,10 @@
MONTH_FORMAT = getattr(settings, 'MONTH_FORMAT', '%b')
+DEFAULT_BILL_AMOUNT = getattr(settings, 'DEFAULT_BILL_AMOUNT', 0.0)
+
##########################################################
-""" EBD OF OVERRIDABLE SETTINGS SECTION """
+""" END OF OVERRIDABLE SETTINGS SECTION """
##########################################################
@@ -223,6 +225,9 @@ def clean(self, value):
### CREDIT CARD FORM
##########################################################
+CC_COUNTRIES=(
+ ('380', _('Italy')),
+)
class CreditCardForm(forms.Form):
@@ -244,15 +249,21 @@ class CreditCardForm(forms.Form):
street1 = forms.CharField(required=True, label=_("Street Address"),
error_messages={'required':_('Please enter your street address.')})
- street2 = forms.CharField(required=False, )
+ street2 = forms.CharField(label=" ", required=False, )
city = forms.CharField(required=True, label=_("City"),
error_messages={'required':_('Please enter your city.')})
zip = forms.CharField(required=False, label=_("Postal Code"))
- country = forms.CharField(required=True, label=_("Country"))
+ country = forms.ChoiceField(required=True, choices=CC_COUNTRIES, label=_("Country"), )
- def __init__(self, user=None, *args, **kwargs):
+ def __init__(self, *args, **kwargs):
super(CreditCardForm, self).__init__(*args, **kwargs)
-
+ bill_amount = kwargs.get('bill_amount', None)
+
+ if bill_amount:
+ self.bill_amount = bill_amount
+ else:
+ self.bill_amount = DEFAULT_BILL_AMOUNT
+
if DEBUG_SHORTCUTS:
self.fields['card_number'].help_text = "For testing use: 4111111111111111"
@@ -329,7 +340,7 @@ def process_transaction(self):
"""
Processes cc transaction. Must be called after form is_valid()
"""
- amount = 2.00
+ amount = self.bill_amount
if not self.cleaned_data.get('transaction_data', None):
self._errors['__all__'] = ErrorList("Not all transaction data given")
@@ -368,17 +379,10 @@ def to_pfp(self):
return self.address
def validate(self):
+ """
+ Hook for more specific validation for this class.
+ """
messages = []
- if not self.address.street:
- messages.append(_("Billing Address Street not given."))
- if not self.address.city:
- messages.append(_("Billing Address City not given."))
- #if not self.address.state:
- # messages.append(_("Billing Address State not given."))
- #if not self.zip:
- # messages.append(_("Billing Address Zipcode not given."))
- if not self.address.country:
- messages.append(_("Billing Address Country not given."))
return messages
class ccCard(object):
@@ -404,15 +408,10 @@ def _get_expiry_date(self, date):
expdate = property(_get_expiry_date)
def validate(self):
+ """
+ Hook for more specific validation for this class.
+ """
messages = []
- #if not self.ccard.card_type:
- # messages.append(_("Credit Card Type not given."))
- if not self.ccard.expdate:
- messages.append(_("Credit Card Expiration date not given."))
- if not self.ccard.acct:
- messages.append(_("Credit Card number not given."))
- if not self.ccard.cvv2:
- messages.append(_("Credit Card CVV Code not given."))
return messages
@@ -427,11 +426,10 @@ def to_pfp(self):
return self.customer
def validate(self):
+ """
+ Hook for more specific validation for this class.
+ """
messages = []
- if not self.customer.firstname:
- messages.append(_("Cardholder First Name not given."))
- if not self.customer.lastname:
- messages.append(_("Cardholder Last Name not given."))
return messages
@@ -471,25 +469,6 @@ def __init__(self,transaction_data, amount, ):
self.amount = amount
self.errors = []
self.transaction_id = None
-
-
- def is_valid(self):
- return_value = False
- messages = []
-
- amount = self.amount
- messages = messages + self.transaction_data.validate()
-
- if not amount > 0:
- messages.append(_("Amount given must be a positive number."))
-
- if messages:
- return_value = False
- self.errors.append(messages)
- else:
- return_value = True
- return return_value
-
def process(self):
transaction_id, success, messages = cc_new_process_transaction(
Please sign in to comment.
Something went wrong with that request. Please try again.