Exemplo n.º 1
0
def check_CVC(card_no, cvc):
    card_type = utils.get_cardtype(card_no)
    cvc = (cvc and unicode(cvc)) or ''
    if card_type == 'AMEX':
        if not cvc:
            return forms.Field.default_error_messages['required']
        elif len(cvc) != 4:
            return forms.Field.default_error_messages['invalid']
    elif card_type in ('VISA', 'VISA ELECTRON', 'MASTERCARD', 'DISCOVER', 'JCB'):
        if not cvc:
            return forms.Field.default_error_messages['required']
        elif len(cvc) != 3:
            return forms.Field.default_error_messages['invalid']
Exemplo n.º 2
0
    def validate(self, value):
        if value: # we don't know if this field is required
            card_no = str(value)
            if len(card_no) < self.min_num_length or len(card_no) > self.max_num_length:
                raise forms.ValidationError(_("Card number should be %(min_len)s to %(max_len)s digits long")%{'min_len':self.min_num_length, 'max_len':self.max_num_length})

            if not utils.is_mod10(card_no):
                raise forms.ValidationError(_('Invalid card number'))

            card_type = utils.get_cardtype(card_no)
            if card_type not in self.accept_cards:
                raise forms.ValidationError(_("Sorry, we accept only %(supported_cards)s")%{'supported_cards': ', '.join(self.accept_cards)})

        super(CreditCardField, self).validate(value)
Exemplo n.º 3
0
def check_CVC(card_no, cvc):
    card_type = utils.get_cardtype(card_no)
    cvc = (cvc and unicode(cvc)) or ''
    if card_type == 'AMEX':
        if not cvc:
            return forms.Field.default_error_messages['required']
        elif len(cvc) != 4:
            return forms.Field.default_error_messages['invalid']
    elif card_type in ('VISA', 'VISA ELECTRON', 'MASTERCARD', 'DISCOVER',
                       'JCB'):
        if not cvc:
            return forms.Field.default_error_messages['required']
        elif len(cvc) != 3:
            return forms.Field.default_error_messages['invalid']
Exemplo n.º 4
0
    def validate(self, value):
        if value:  # we don't know if this field is required
            card_no = str(value)
            if len(card_no) < self.min_num_length or len(
                    card_no) > self.max_num_length:
                raise forms.ValidationError(
                    _("Card number should be %(min_len)s to %(max_len)s digits long"
                      ) % {
                          'min_len': self.min_num_length,
                          'max_len': self.max_num_length
                      })

            if not utils.is_mod10(card_no):
                raise forms.ValidationError(_('Invalid card number'))

            card_type = utils.get_cardtype(card_no)
            if card_type not in self.accept_cards:
                raise forms.ValidationError(
                    _("Sorry, we accept only %(supported_cards)s") %
                    {'supported_cards': ', '.join(self.accept_cards)})

        super(CreditCardField, self).validate(value)
Exemplo n.º 5
0
    def test_utils(self):
        self.assertTrue(utils.card_types)

        self.assertIsNone(utils.get_cardtype('42'))
        self.assertEqual('VISA', utils.get_cardtype('4444333322221111'))
        self.assertEqual('VISA', utils.get_cardtype('4111111111111111'))
        self.assertEqual('MASTERCARD', utils.get_cardtype('5555555555554444'))
        self.assertEqual('MASTERCARD', utils.get_cardtype('5454545454545454'))
        self.assertEqual('SWITCH', utils.get_cardtype('6333333333333333336'))
        self.assertEqual('AMEX', utils.get_cardtype('343434343434343'))
        self.assertEqual('DC', utils.get_cardtype('36700102000000'))
        self.assertEqual('MAESTRO', utils.get_cardtype('6304900017740292441'))
        self.assertEqual('UNIONPAY', utils.get_cardtype('6225880120625588'))
        self.assertEqual('UNIONPAY', utils.get_cardtype('6222000200116010778'))

        gateway = bursar_settings.ACTIVE_GATEWAYS[0][0]
        self.assertIsInstance(utils.get_processor(gateway)(None), base.BasePaymentProcessor)
        self.assertIsInstance(utils.get_form(gateway)(), forms.Form)
Exemplo n.º 6
0
 def storeCC(self, ccnum):
     """ Take as input a valid cc, encrypt it and store the last 4 digits in a visible form """
     self._card_no = ccnum
     self.card_type = utils.get_cardtype(ccnum)
     self.display_cc = ccnum[-4:]
Exemplo n.º 7
0
 def storeCC(self, ccnum):
     """ Take as input a valid cc, encrypt it and store the last 4 digits in a visible form """
     self._card_no  = ccnum
     self.card_type = utils.get_cardtype(ccnum)
     self.display_cc= ccnum[-4:]