def build_reference_request(self, action, money, authorization): return xStr( XML(TRANSACTIONS[action], XML.PNRef(authorization), *self.invoice_total_amt(money) ) )
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_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_credit_card_request(self, action, money, credit_card, **options): transaction_type = TRANSACTIONS[action] # amount=self.options['amount'] ) # TODO all options in options - no exceptions formatted_amount = '%.2f' % money.amount # TODO rename to money; merge with grandTotalAmount system invoice = list() ip_address = options.get('ip_address', None) if ip_address: invoice.append(XML.CustIP(ip_address)) bill_to_address = options.get('address', None) if bill_to_address: invoice.append(self.add_address('BillTo', **bill_to_address)) ship_to_address = options.get('ship_address', None) if ship_to_address: invoice.append(self.add_address('ShipTo', **ship_to_address)) invoice.append( XML.TotalAmt(formatted_amount, Currency=str(money.currency.code))) request = XML( transaction_type, XML.PayData(XML.Invoice(*invoice), XML.Tender(self.add_credit_card(credit_card)))) return xStr(request)
def build_credit_card_request(self, action, money, credit_card, **options): transaction_type = TRANSACTIONS[action] # amount=self.options['amount'] ) # TODO all options in options - no exceptions formatted_amount = '%.2f' % money.amount # TODO rename to money; merge with grandTotalAmount system invoice = list() ip_address = options.get('ip_address', None) if ip_address: invoice.append(XML.CustIP(ip_address)) bill_to_address = options.get('address', None) if bill_to_address: invoice.append(self.add_address('BillTo', **bill_to_address)) ship_to_address = options.get('ship_address', None) if ship_to_address: invoice.append(self.add_address('ShipTo', **ship_to_address)) invoice.append(XML.TotalAmt(formatted_amount, Currency=str(money.currency.code))) request = XML(transaction_type, XML.PayData( XML.Invoice(*invoice), XML.Tender( self.add_credit_card(credit_card) ))) return xStr(request)
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))
def build_authorization_request(self, money, credit_card, **options): assert isinstance(money, Money), 'TODO always pass in a Money object - no exceptions!' template_p = ''' <ccAuthService run="true"/> <businessRules> </businessRules>''' # TODO use or lose this fields = default_dict( first_name=credit_card.first_name, last_name=credit_card.last_name, country='USA', # TODO vet this default ) #name='', # TODO merge more _where_to=_where_to ) grandTotalAmount = str(money.amount) # TODO pass the currency thru fields.update(options.get('billing_address', {})) fields.update(options) # TODO options should override credit card - everywhere, and doc that! # TODO fields.update(address).update(options) # TODO for the love of god SELF.credit_card!! return ( xStr(XML.billTo( XML.firstName(credit_card.first_name), XML.lastName(credit_card.last_name), XML.street1(fields['address1']), XML.street2(fields['address2']), XML.city(fields['city']), XML.state(fields['state']), XML.postalCode(fields['zip']), XML.country(fields['country']), XML.email(fields['email']) )) + xStr(XML.purchaseTotals( XML.currency(str(money.currency)), XML.grandTotalAmount(grandTotalAmount) )) + xStr(XML.card( XML.accountNumber(credit_card.number), XML.expirationMonth(str(credit_card.month)), XML.expirationYear(str(credit_card.year)), XML.cvNumber('123'), # TODO XML.cardType('001') # TODO )) + (template_p % fields) )
def build_reference_sale_or_authorization_request( self, action, money, reference, **options): #TODO tdd this transaction_type = TRANSACTIONS[action] formatted_amount = '%.2f' % money.amount # TODO rename to money; merge with grandTotalAmount system return xStr( XML( transaction_type, XML.PayData( XML.Invoice( XML.TotalAmt(formatted_amount, Currency=str(money.currency.code))), XML.Tender( XML.Card(XML.ExtData(Name='ORIGID', Value=reference))))))
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))
def build_credit_card_request(self, action, money, credit_card, **options): transaction_type = TRANSACTIONS[action] # amount=self.options['amount'] ) # TODO all options in options - no exceptions formatted_amount = '%.2f' % money.amount # TODO rename to money; merge with grandTotalAmount system bill_to_address = options.get('address', {}) # TODO billing_address etc??? request = XML(transaction_type, XML.PayData( XML.Invoice( self.add_address('BillTo', **bill_to_address), XML.TotalAmt(formatted_amount, Currency=str(money.currency.code)) ), XML.Tender( self.add_credit_card(credit_card) ))) return xStr(request)
def build_reference_sale_or_authorization_request(self, action, money, reference, **options): #TODO tdd this transaction_type = TRANSACTIONS[action] formatted_amount = '%.2f' % money.amount # TODO rename to money; merge with grandTotalAmount system return xStr( XML(transaction_type, XML.PayData( XML.Invoice( XML.TotalAmt(formatted_amount, Currency=str(money.currency.code)) ), XML.Tender( XML.Card( XML.ExtData(Name='ORIGID', Value=reference) ) ) ) ) )
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))
def build_profile_request(self, message_type, **kwargs): parts = {'CustomerProfileAction': message_type, #CRUD 'CustomerBin': '000001', 'CustomerMerchantID': kwargs['merchant_id'],} if kwargs.get('credit_card'): parts.update(self.build_profile_credit_card_request(kwargs['credit_card'])) if 'address' in kwargs: parts.update(self.build_profile_address_request(kwargs['address'])) if message_type == 'C': parts.update(self.build_create_card_store_request()) if kwargs.get('card_store_id'): parts.update({'CustomerRefNum':kwargs['card_store_id']}) entries = list() #XML fields need to be in a certain order for key in self.PROFILE_FIELDS: if key in parts: entries.append(getattr(XML, key)(parts[key])) profile = XML.Profile(*entries) return xStr(XML.Request(profile))
def build_profile_request(self, message_type, **kwargs): parts = { 'CustomerProfileAction': message_type, #CRUD 'CustomerBin': '000001', 'CustomerMerchantID': kwargs['merchant_id'], } if kwargs.get('credit_card'): parts.update( self.build_profile_credit_card_request(kwargs['credit_card'])) if 'address' in kwargs: parts.update(self.build_profile_address_request(kwargs['address'])) if message_type == 'C': parts.update(self.build_create_card_store_request()) if kwargs.get('card_store_id'): parts.update({'CustomerRefNum': kwargs['card_store_id']}) entries = list() #XML fields need to be in a certain order for key in self.PROFILE_FIELDS: if key in parts: entries.append(getattr(XML, key)(parts[key])) profile = XML.Profile(*entries) return xStr(XML.Request(profile))
def build_reference_request(self, action, money, authorization): return xStr( XML(TRANSACTIONS[action], XML.PNRef(authorization), *self.invoice_total_amt(money)))