Esempio n. 1
0
    def __init__(self, name, number, exp_month, exp_year, cvd=''):
        """ Initialize a credit card struct and perform some basic validation.

        Arguments:
            name: the owner of the credit card, as displayed on the card itself
            number: the number of the credit card
            exp_month: the month of expiry, as a number, 1-indexed
            exp_year: the year of expiry, as a number
            cvd: the CVD of the credit card (optional)
        """
        if not name:
            raise errors.ValidationException('Name must be specified in credit card')
        self.name = name

        if not number:
            raise errors.ValidationException('Number must be specified in credit card')
        self.number = str(number)

        if not exp_month:
            raise errors.ValidationException('Expiry month must be specified in credit card')
        if not exp_year:
            raise errors.ValidationException('Expiry year must be specified in credit card')

        # Parse out the month & year as expected by Beanstream (numeric month,
        # 1-indexed, & last two digits of the year).
        year = int(exp_year)
        month = int(exp_month)
        expiry_date = date(year, month, calendar.monthrange(year, month)[1])
        self.exp_month = expiry_date.strftime('%m')
        self.exp_year = expiry_date.strftime('%y')

        self.cvd = str(cvd)
Esempio n. 2
0
    def validate(self):
        if (self.has_billing_address or self.has_credit_card) and self.has_customer_code:
            log.error('billing address or credit card specified with customer code')
            raise errors.ValidationException('cannot specify both customer code and billing address/credit card')

        if not self.has_customer_code and self.beanstream.REQUIRE_BILLING_ADDRESS and not self.has_billing_address:
            log.error('billing address required')
            raise errors.ValidationException('billing address required')
Esempio n. 3
0
    def set_refs(self, refs):
        if len(refs) > 5:
            raise errors.ValidationException('too many ref fields')

        for ref_idx, ref in enumerate(refs, start=1):
            if ref:
                self.params['ref%s' % ref_idx] = ref
Esempio n. 4
0
    def set_card(self, card):
        if self.beanstream.REQUIRE_CVD and not card.has_cvd():
            log.error('CVD required')
            raise errors.ValidationException('CVD required')

        self.params.update(card.params())
        self.has_credit_card = True
 def set_language(self, language):
     language = language.upper()
     if language not in ('ENG', 'FRE'):
         raise errors.ValidationException(
             'invalid language option specified: %s (must be one of FRE, ENG)'
             % language)
     self.params['trnLanguage'] = language
Esempio n. 6
0
    def set_status(self, status):
        status = status.lower()

        if status not in STATUS_DESCRIPTORS:
            raise errors.ValidationException('invalid status option specified: %s' % status)

        self.params['status'] = STATUS_DESCRIPTORS[status]
Esempio n. 7
0
    def parse_raw_response(self, body):
        fields = self.response_class._fields()

        lines = body.split('\r\n')

        report = []
        pattern = re.compile(r'\t'.join([r'([^\t]*)'] * len(fields)))
        for line in lines[1:]:
            m = pattern.match(line)
            if not line.strip():
                continue

            if m:
                report_item = {}
                for idx, field in enumerate(fields):
                    if not m.groups()[idx] or m.groups()[idx] == '\x00':
                        report_item[field] = None
                    else:
                        report_item[field] = m.groups()[idx]
                report.append(report_item)

            else:
                raise errors.ValidationException(
                    'unexpected format received: %s' % line)

        return report
Esempio n. 8
0
    def __init__(self, name, email, phone=None, address1=None, address2=None,
            city=None, province=None, postal_code=None, country=None):
        """ Initialize an address struct.
        """
        if not name:
            raise errors.ValidationException('Name must be specified in address')
        self.name = name

        if not email:
            raise errors.ValidationException('Email must be specified in address')
        self.email = email

        self.phone = None
        if phone:
            self.phone = str(phone)

        self.address1 = address1
        self.address2 = address2
        self.city = city
        self.province = province
        self.postal_code = postal_code
        self.country = country
Esempio n. 9
0
    def parse_raw_response(self, body):
        pattern = re.compile(r'^<\?xml version="1\.0".*>\s*<response>\s*<accountId>([^<]+)</accountId>\s*<code>(\d+)</code>\s*<message>(.*)</message>\s*</response>\s*$')

        m = pattern.match(body)
        if m:
            account_id, response_code, message = m.groups()

            return {
                'accountId': [account_id],
                'code': [response_code],
                'message': [message]
            }

        else:
            raise errors.ValidationException('unexpected message format received: %s' % body)
Esempio n. 10
0
 def toStr(self):
     if self.value == '=':
         return '%3D'
     elif self.value == '<':
         return '%3C'
     elif self.value == '>':
         return '%3E'
     elif self.value == '<=':
         return '%3C%3D'
     elif self.value == '>=':
         return '%3E%3D'
     elif self.value == 'START WITH':
         return 'START%20WITH'
     else:
         return errors.ValidationException(
             "Unrecognized Operator parameter for report query: " + value)
Esempio n. 11
0
    def __init__(self, beanstream, amount, frequency_period,
            frequency_increment):
        """ Create a new recurring billing account creation transaction.

        Arguments:
            beanstream: gateway object
            amount: the amount to charge on a recurring basis
            frequency_period: one of DWMY; used in combination with
                frequency_increment to set billing frequency
            frequency_increment: numeric; used in combination with
                frequency_period to set billing frequency
        """

        super(CreateRecurringBillingAccount, self).__init__(beanstream, amount)
        self.response_class = CreateRecurringBillingAccountResponse

        self.params['trnRecurring'] = '1'

        frequency_period = frequency_period.upper()
        if frequency_period not in 'DWMY':
            raise errors.ValidationException('invalid frequency period specified: %s (must be one of DWMY)' % frequency_period)
        self.params['rbBillingPeriod'] = frequency_period

        self.params['rbBillingIncrement'] = frequency_increment
Esempio n. 12
0
    def set_frequency_period(self, frequency_period):
        frequency_period = frequency_period.upper()
        if frequency_period not in 'DWMY':
            raise errors.ValidationException('invalid frequency period specified: %s (must be one of DMWY)' % frequency_period)

        self.params['rbBillingPeriod'] = frequency_period
Esempio n. 13
0
    def set_billing_state(self, billing_state):
        billing_state = billing_state.lower()
        if billing_state not in STATUS_DESCRIPTORS:
            raise errors.ValidationException('invalid billing state option specified: %s' % billing_state)

        self.params['rbBillingState'] = STATUS_DESCRIPTORS[billing_state]
Esempio n. 14
0
 def validate(self):
     if 'rptTransId' not in self.params and 'rptCcNumber' not in self.params:
         raise errors.ValidationException(
             'CreditCardLookupReport must specify one of transaction id or credit card number'
         )