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 add_address(self, _where_to, **address): if not address: return '' address = default_dict(address) return XML(_where_to, XML.Name(address['name']), XML.Phone('(555)555-5555'), XML.Address( XML.Street(address['address1']), XML.City(address['city']), XML.State(address['state']), XML.Country(address['country']), XML.Zip(address['zip']) ) )
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_authorization_request_TODO( self, money, credit_card, **options ): # where'd "NewOrder" come from? not in docs... 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 fields.update(options["billing_address"]) # TODO what about address? fields.update(options) exp_code = ("%02i" % credit_card.month) + str(credit_card.year)[-2:] # CONSIDER credit_card_format x = XML numeric = money.currency.numeric new_order = x.NewOrder( x.OrbitalConnectionUsername(fields["login"]), # TODO from configs x.OrbitalConnectionPassword(fields["password"]), # TODO ibid x.IndustryType("EC"), # 'EC'ommerce - a web buy x.MessageType("A"), # auth fwt! # TODO hallow A – Authorization request AC – Authorization and Mark for Capture FC – Force-Capture request R – Refund request x.BIN("1"), x.MerchantID("1"), x.TerminalID("1"), 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"), # TODO figure out what this is it's probably important x.CardSecValInd("1"), # CONSIDER visa & discover only - nullify for others x.CardSecVal(credit_card.verification_value), x.AVSzip(fields["zip"]), x.AVSaddress1(fields["address1"]), # TODO pull an AVSresponse? 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("840"), # CONSIDER other countries x.CustomerProfileFromOrderInd("A"), x.CustomerProfileOrderOverrideInd("NO"), x.OrderID(""), # TODO x.Amount(grandTotalAmount), ) return xStr(XML.Request(new_order))
def add_address(self, _where_to, **address): if not address: return '' address = default_dict(address) elements = list() elements.append(XML.Name(address['name'])) if address.get('phone','').strip(): #xxx-xxx-xxxx (US numbers) +xxxxxxxxxxx (international numbers) phone = strip_to_numbers(address['phone']) if len(phone) == 10 and address['country'] == 'US': phone = '%s-%s-%s' % (phone[0:3], phone[3:6], phone[6:10]) else: phone = '+'+phone elements.append(XML.Phone(phone)) elements.append(XML.Address( XML.Street(address['address1']), XML.City(address['city']), XML.State(address['state']), XML.Country(address['country']), XML.Zip(address['zip']))) return XML(_where_to, *elements)
def add_address(self, _where_to, **address): if not address: return '' address = default_dict(address) elements = list() elements.append(XML.Name(address['name'])) if address.get('phone', '').strip(): #xxx-xxx-xxxx (US numbers) +xxxxxxxxxxx (international numbers) phone = strip_to_numbers(address['phone']) if len(phone) == 10 and address['country'] == 'US': phone = '%s-%s-%s' % (phone[0:3], phone[3:6], phone[6:10]) else: phone = '+' + phone elements.append(XML.Phone(phone)) if address.get('email', '').strip(): elements.append(XML.EMail(address.get('email', '').strip())) elements.append( XML.Address(XML.Street(address['address1']), XML.City(address['city']), XML.State(address['state']), XML.Country(address['country']), XML.Zip(address['zip']))) return XML(_where_to, *elements)