Exemplo n.º 1
0
    def build_capture_request(self, **kwargs):
        parts = {
            'BIN': '000001',
            'MerchantID': kwargs['merchant_id'],
            'TerminalID': '001',
        }
        if 'authorization' in kwargs:
            parts.update(
                self.build_order_authorization_request(
                    kwargs['authorization']))
        if kwargs.get('credit_card'):
            parts.update(
                self.build_order_credit_card_request(kwargs['credit_card']))
        if 'address' in kwargs:
            parts.update(self.build_order_address_request(kwargs['address']))
        parts.update({'OrderID': str(kwargs.get('order_id', gencode()))})
        if 'money' in kwargs:
            parts.update(self.build_order_money_request(kwargs['money']))
        if kwargs.get('card_store_id'):
            parts.update({'CustomerRefNum': kwargs['card_store_id']})
        if kwargs.get('register_card_store', False):
            parts.update(self.build_create_card_store_request())

        entries = list()
        #XML fields need to be in a certain order
        for key in self.CAPTURE_FIELDS:
            if key in parts:
                entries.append(getattr(XML, key)(parts[key]))

        new_order = XML.MarkForCapture(*entries)
        return xStr(XML.Request(new_order))
Exemplo n.º 2
0
    def build_order_request(self, message_type, **kwargs):
        parts = {
            'IndustryType': 'EC',  #  'EC'ommerce - a web buy
            'MessageType': message_type,
            'BIN': '000001',
            'MerchantID': kwargs['merchant_id'],
            'TerminalID': '001',
        }
        if 'authorization' in kwargs:
            parts.update(
                self.build_order_authorization_request(
                    kwargs['authorization']))
        if kwargs.get('credit_card'):
            parts.update(
                self.build_order_credit_card_request(kwargs['credit_card']))
        if 'address' in kwargs:
            parts.update(self.build_order_address_request(kwargs['address']))
        if message_type in ('A',
                            'AC') or True:  #CONSIDER order_id is always needed
            parts.update({'OrderID': str(kwargs.get('order_id', gencode()))})
        if 'money' in kwargs:
            parts.update(self.build_order_money_request(kwargs['money']))
        if kwargs.get('card_store_id'):
            parts.update({'CustomerRefNum': kwargs['card_store_id']})
        if kwargs.get('register_card_store', False):
            parts.update(self.build_create_card_store_request())

        entries = list()
        #XML fields need to be in a certain order
        for key in self.NEW_ORDER_FIELDS:
            if key in parts:
                entries.append(getattr(XML, key)(parts[key]))

        new_order = XML.NewOrder(*entries)
        return xStr(XML.Request(new_order))
 def build_order_request(self, message_type, **kwargs):
     parts = {'IndustryType': 'EC',  #  'EC'ommerce - a web buy
              'MessageType': message_type,
              'BIN': '000001',
              'MerchantID': kwargs['merchant_id'],
              'TerminalID': '001',}
     if 'authorization' in kwargs:
         parts.update(self.build_order_authorization_request(kwargs['authorization']))
     if kwargs.get('credit_card'):
         parts.update(self.build_order_credit_card_request(kwargs['credit_card']))
     if 'address' in kwargs:
         parts.update(self.build_order_address_request(kwargs['address']))
     if message_type in ('A', 'AC') or True: #CONSIDER order_id is always needed
         parts.update({'OrderID': str(kwargs.get('order_id', gencode()))})
     if 'money' in kwargs:
         parts.update(self.build_order_money_request(kwargs['money']))
     if kwargs.get('card_store_id'):
         parts.update({'CustomerRefNum':kwargs['card_store_id']})
     if kwargs.get('register_card_store', False):
         parts.update(self.build_create_card_store_request())
     
     entries = list()
     #XML fields need to be in a certain order
     for key in self.NEW_ORDER_FIELDS:
         if key in parts:
             entries.append(getattr(XML, key)(parts[key]))
     
     new_order = XML.NewOrder(*entries)
     return xStr(XML.Request(new_order))
 def build_capture_request(self, **kwargs):
     parts = {'BIN': '000001',
              'MerchantID': kwargs['merchant_id'],
              'TerminalID': '001',}
     if 'authorization' in kwargs:
         parts.update(self.build_order_authorization_request(kwargs['authorization']))
     if kwargs.get('credit_card'):
         parts.update(self.build_order_credit_card_request(kwargs['credit_card']))
     if 'address' in kwargs:
         parts.update(self.build_order_address_request(kwargs['address']))
     parts.update({'OrderID': str(kwargs.get('order_id', gencode()))})
     if 'money' in kwargs:
         parts.update(self.build_order_money_request(kwargs['money']))
     if kwargs.get('card_store_id'):
         parts.update({'CustomerRefNum':kwargs['card_store_id']})
     if kwargs.get('register_card_store', False):
         parts.update(self.build_create_card_store_request())
     
     entries = list()
     #XML fields need to be in a certain order
     for key in self.CAPTURE_FIELDS:
         if key in parts:
             entries.append(getattr(XML, key)(parts[key]))
     
     new_order = XML.MarkForCapture(*entries)
     return xStr(XML.Request(new_order))
    def build_request(self, message_type, money, credit_card, **options):

        assert isinstance(money, Money), 'TODO  always pass in a Money object - no exceptions!'

        fields = default_dict(**self.options)

        grandTotalAmount = '%.2f' % money.amount  #  CONSIDER  format AMOUNT like this better, everywhere
        grandTotalAmount = grandTotalAmount.replace('.', '')  #  CONSIDER internationalize that and respect the CurrencyExponent
        if options.has_key('billing_address'):  fields.update(options['billing_address'])
        if options.has_key('address'):  fields.update(options['address'])
        fields.update(options)
        exp_code = ( '%02i' % credit_card.month) + str(credit_card.year)[-2:] #  CONSIDER  credit_card_format
        numeric = money.currency.numeric

        CardSecValInd = ''
        if credit_card._lookup_card_type() in ('visa', 'discover'):
            CardSecValInd = '1'

        # print money.currency.__dict__  #  CONSIDER  where'z the exponent?

        if 2 != len(fields['country']):
            raise ValueError('Country code must be 2 characters (%s)' % fields['country'])

        x = XML

        new_order = x.NewOrder(
                        x.IndustryType('EC'),  #  'EC'ommerce - a web buy
                        x.MessageType(message_type),
                            #  A – Authorization request
                            #  AC – Authorization and Mark for Capture
                            #  FC – Force-Capture request
                            #   R – Refund request
                        x.BIN('000001'),
                        x.MerchantID(options['merchant_id']),
                        x.TerminalID('001'),
                        # x.CardBrand(''),

# TODO SW – Switch / Solo ED – European Direct Debit EC – Electronic Check BL – Bill Me Later DP – PINLess Debit [Generic Value Used in Requests]

                        x.AccountNum(credit_card.number),
                        x.Exp(exp_code),
                        x.CurrencyCode(numeric),
                        x.CurrencyExponent('2'),  #  CONSIDER  vary this when we vary the money type
                        x.CardSecValInd(CardSecValInd),
                        x.CardSecVal(credit_card.verification_value),
                        x.AVSzip(fields['zip']),
                        x.AVSaddress1(fields['address1']),
                        x.AVSaddress2(fields['address2']),
                        x.AVScity(fields['city']),
                        x.AVSstate(fields['state']),
                        x.AVSphoneNum(fields['phone']),
                        x.AVSname(credit_card.first_name + ' ' + credit_card.last_name),
                        x.AVScountryCode(self.censor_countries(fields)), #  and ensure this is ISO-compliant or we get a DTD fault
                        #x.CustomerProfileFromOrderInd('A'), # TODO: make these optional
                        #x.CustomerProfileOrderOverrideInd('NO'),
                        x.OrderID(str(fields.get('order_id',gencode()))),
                        x.Amount(grandTotalAmount)
                        )
        return xStr(XML.Request(new_order))
Exemplo n.º 6
0
 def build_headers(self, content_length):
     return {
         "Content-Type": "text/xml",
         "Content-Length": str(content_length),
         "X-VPS-Client-Timeout": '30',  #  TODO  bfd?!
         "X-VPS-VIT-Integration-Product": "TODO what's my name",
         "X-VPS-VIT-Runtime-Version": '4.2',  #  TODO  what's my version?
         "X-VPS-Request-ID": gencode(),
     }
Exemplo n.º 7
0
 def build_headers(self, content_length):  #  TODO doesn't an HTTP library take care of this for us?
     return {
       "Content-Type" : "text/xml",
       "Content-Length" : str(content_length),
       "X-VPS-Client-Timeout" : '30',  #  TODO  bfd?!
       "X-VPS-VIT-Integration-Product" : "TODO what's my name",
       "X-VPS-VIT-Runtime-Version" : '4.2',  #  TODO  what's my version?
       "X-VPS-Request-ID" : gencode(),
     }
 def build_reversal_request(self, **kwargs):
     parts = {'BIN': '000001',
              'MerchantID': kwargs['merchant_id'],
              'TerminalID': '001',}
     parts.update(self.build_order_authorization_request(kwargs['authorization']))
     parts.update({'OrderID': str(kwargs.get('order_id', gencode()))})
     
     entries = list()
     #XML fields need to be in a certain order
     for key in self.REVERSAL_FIELDS:
         if key in parts:
             entries.append(getattr(XML, key)(parts[key]))
     
     new_order = XML.Reversal(*entries)
     return xStr(XML.Request(new_order))
Exemplo n.º 9
0
    def build_reversal_request(self, **kwargs):
        parts = {
            'BIN': '000001',
            'MerchantID': kwargs['merchant_id'],
            'TerminalID': '001',
        }
        parts.update(
            self.build_order_authorization_request(kwargs['authorization']))
        parts.update({'OrderID': str(kwargs.get('order_id', gencode()))})

        entries = list()
        #XML fields need to be in a certain order
        for key in self.REVERSAL_FIELDS:
            if key in parts:
                entries.append(getattr(XML, key)(parts[key]))

        new_order = XML.Reversal(*entries)
        return xStr(XML.Request(new_order))