예제 #1
0
    def __init__(self, beanstream_gateway, adjustment_type, transaction_id, amount):
        super(PreAuthorizationCompletion, self).__init__(beanstream_gateway)

        if not beanstream_gateway.HASH_VALIDATION and not beanstream_gateway.USERNAME_VALIDATION:
            raise errors.ConfigurationException('adjustments must be performed with either hash or username/password validation')

        if adjustment_type not in [self.RETURN, self.VOID, self.PREAUTH_COMPLETION, self.VOID_RETURN, self.VOID_PURCHASE]:
            raise errors.ConfigurationException('invalid adjustment_type specified: %s' % adjustment_type)

        self.params['trnType'] = adjustment_type
        self.params['adjId'] = transaction_id
        self.params['trnAmount'] = self._process_amount(amount)
예제 #2
0
    def __init__(self, **options):
        """ Initialize the gateway.

        Keyword arguments:
            hash_validation: True to enable; default disabled. Note that
                hash_validation and username_validation may not be enabled
                simultaneously.
            username_validation: True to enable; default disabled. Note that
                username_validation and hash_validation may not be enabled
                simultaneously.
            require_cvd: True to enable; default disabled.
            require_billing_address: True to enable; default disabled.
        """

        self.HASH_VALIDATION = options.get('hash_validation', False)
        self.USERNAME_VALIDATION = options.get('username_validation', False)
        self.REQUIRE_CVD = options.get('require_cvd', False)
        self.REQUIRE_BILLING_ADDRESS = options.get('require_billing_address',
                                                   False)

        if self.HASH_VALIDATION and self.USERNAME_VALIDATION:
            raise errors.ConfigurationException(
                'Only one validation method may be specified')

        self.merchant_id = None
        self.username = None
        self.password = None
        self.hashcode = None
        self.payment_profile_passcode = None
예제 #3
0
    def __init__(self, beanstream):
        super(PaymentProfileTransaction, self).__init__(beanstream)
        self.url = self.URLS['payment_profile']
        self.response_class = PaymentProfileResponse

        if not self.beanstream.payment_profile_passcode:
            raise errors.ConfigurationException('payment profile passcode must be specified to create or modify payment profiles')

        self.params['serviceVersion'] = '1.0'
        self.params['merchantId'] = self.beanstream.merchant_id
        self.params['passCode'] = self.beanstream.payment_profile_passcode
        self.params['responseFormat'] = 'QS'
예제 #4
0
    def configure(self, merchant_id, login_company, login_user, login_password,
                  **params):
        """ Configure the gateway.

        Keyword arguments:
            hashcode: required if hash validation is enabled.
            hash_algorithm: required if hash validation is enabled; one of MD5 or SHA1.
            username: required if username validation is enabled.
            password: required if username validation is enabled.
        """
        self.merchant_id = merchant_id
        self.login_company = login_company
        self.login_user = login_user
        self.login_password = login_password
        self.hashcode = params.get('hashcode', None)
        self.hash_algorithm = params.get('hash_algorithm', None)
        self.username = params.get('username', None)
        self.password = params.get('password', None)
        self.payment_profile_passcode = params.get('payment_profile_passcode',
                                                   None)
        self.recurring_billing_passcode = params.get(
            'recurring_billing_passcode', None)

        if self.HASH_VALIDATION and (not self.hashcode
                                     or not self.hash_algorithm):
            raise errors.ConfigurationException(
                'hashcode and algorithm must be specified')

        if self.USERNAME_VALIDATION and (not self.username
                                         or not self.password):
            raise errors.ConfigurationException(
                'username and password must be specified')

        if self.HASH_VALIDATION and self.hash_algorithm not in ('MD5', 'SHA1'):
            raise errors.ConfigurationException(
                'hash algorithm must be one of MD5 or SHA1')
예제 #5
0
    def __init__(self, beanstream, account_id):
        super(ModifyRecurringBillingAccount, self).__init__(beanstream)
        self.url = self.URLS['recurring_billing']
        self.response_class = ModifyRecurringBillingAccountResponse

        if not self.beanstream.recurring_billing_passcode:
            raise errors.ConfigurationException('recurring billing passcode must be specified to modify recurring billing accounts')

        self.params['merchantId'] = self.beanstream.merchant_id
        self.params['serviceVersion'] = '1.0'
        self.params['operationType'] = 'M'
        self.params['passcode'] = self.beanstream.recurring_billing_passcode
        self.params['responseFormat'] = 'QS'

        self.params['rbAccountId'] = account_id
예제 #6
0
    def __init__(self, beanstream, customer_code):
        super(GetAllCards, self).__init__(beanstream)
        self.url = self.URLS['rest_profiles']
        self.response_class = PaymentProfileResponse

        self.restful = True
        self.request_type = 'GET'

        self.params['customerCode'] = customer_code
        
        if not self.beanstream.payment_profile_passcode:
            raise errors.ConfigurationException('payment profile passcode must be specified to create or modify payment profiles')

        self.params['merchantId'] = self.beanstream.merchant_id
        self.params['passCode'] = self.beanstream.payment_profile_passcode
예제 #7
0
    def __init__(self, beanstream, customer_code):
        super(DeletePaymentProfile, self).__init__(beanstream)
        self.url = self.URLS['rest_profiles']
        self.response_class = PaymentProfileResponse

        self.restful = True #we send RESTful requests for deleting profiles and updating a profile's cards
        self.request_type = 'DELETE'

        self.params['customerCode'] = customer_code
        
        if not self.beanstream.payment_profile_passcode:
            raise errors.ConfigurationException('payment profile passcode must be specified to create or modify payment profiles')

        self.params['merchantId'] = self.beanstream.merchant_id
        self.params['passCode'] = self.beanstream.payment_profile_passcode
    def __init__(self, beanstream_gateway, adjustment_type, transaction_id,
                 amount):
        super(Adjustment, self).__init__(beanstream_gateway, amount)

        if adjustment_type not in [
                self.RETURN, self.VOID, self.PREAUTH_COMPLETION,
                self.VOID_RETURN, self.VOID_PURCHASE
        ]:
            raise errors.ConfigurationException(
                'invalid adjustment_type specified: %s' % adjustment_type)

        #self.response_class = PurchaseResponse
        #self.url = self.URLS['process_transaction']

        self.params['trnType'] = adjustment_type
        self.params['adjId'] = transaction_id
        self.params['trnAmount'] = self._process_amount(amount)
예제 #9
0
    def commit(self):
        self.validate()

        # hashing is applicable only to requests sent to the process
        # transaction API.
        data = urllib.urlencode(self.params)
        if self.beanstream.HASH_VALIDATION and self.url == self.URLS[
                'process_transaction']:
            if self.beanstream.hash_algorithm == 'MD5':
                hashobj = hashlib.md5()
            elif self.beanstream.hash_algorithm == 'SHA1':
                hashobj = hashlib.sha1()
            else:
                log.error('Hash method %s is not MD5 or SHA1',
                          self.beanstream.hash_algorithm)
                raise errors.ConfigurationException(
                    'Hash method must be MD5 or SHA1')
            hashobj.update(data + self.beanstream.hashcode)
            hash_value = hashobj.hexdigest()
            data += '&hashValue=%s' % hash_value

        log.debug('Sending to %s: %s', self.url, data)

        res = urllib2.urlopen(self.url, data)

        if res.code != 200:
            log.error('response code not OK: %s', res.code)
            return False

        body = res.read()

        if body == 'Empty hash value':
            log.error('hash validation required')
            return False

        response = self.parse_raw_response(body)
        log.debug('Beanstream response: %s', body)
        log.debug(response)

        return self.response_class(response, *self.response_params)