Ejemplo n.º 1
0
    def test_add_address_bill_to(self):
        address = self.gateway.add_address('BillTo',
                                           name= 'Severus Snape',
                                           phone='(555)555-5555',
                                           address1='1234 My Street',  #  TODO  address2 ?
                                           city='Ottowa',
                                           state='ON',
                                           country='CA',
                                           zip='K1C2N6'
                                            )
        address = xStr(address)
        self.assert_xml_text(address, '/BillTo/Name', 'Severus Snape')

        self.assert_match_xml('''<BillTo>
                                   <Name>Severus Snape</Name>
                                   <Phone>(555)555-5555</Phone>
                                   <Address>
                                     <Street>1234 My Street</Street>
                                     <City>Ottowa</City>
                                     <State>ON</State>
                                     <Country>CA</Country>
                                     <Zip>K1C2N6</Zip>
                                   </Address>
                                 </BillTo>''', address)  #  TODO  cover the email!

        self.assert_xml(address, lambda xml:
                xml.BillTo(
                       xml.Name('Severus Snape'),
                       xml.Address(
                           xml.State('ON'),
                           xml.Country('CA'),
                           xml.Zip('K1C2N6')
                       )
                    )
                )
Ejemplo n.º 2
0
 def build_reference_request(self, action, money, authorization):
     return xStr(
         XML(TRANSACTIONS[action],
             XML.PNRef(authorization),
             *self.invoice_total_amt(money)
             )
         )
 def failed_authorization_response(self):
     return xStr(XML.Response(
                   XML.QuickResp(
                     XML.ProcStatus('841'),
                     XML.StatusMsg('Error validating card/account number range'),
                     XML.CustomerBin(),
                     XML.CustomerMerchantID(),
                     XML.CustomerName(),
                     XML.CustomerRefNum(),
                     XML.CustomerProfileAction(),
                     XML.ProfileProcStatus('9576'),
                     XML.CustomerProfileMessage('Profile: Unable to Perform Profile Transaction. The Associated Transaction Failed. '),
                     XML.CustomerAddress1(),
                     XML.CustomerAddress2(),
                     XML.CustomerCity(),
                     XML.CustomerState(),
                     XML.CustomerZIP(),
                     XML.CustomerEmail(),
                     XML.CustomerPhone(),
                     XML.CustomerProfileOrderOverrideInd(),
                     XML.OrderDefaultDescription(),
                     XML.OrderDefaultAmount(),
                     XML.CustomerAccountType(),
                     XML.CCAccountNum(),
                     XML.CCExpireDate(),
                     XML.ECPAccountDDA(),
                     XML.ECPAccountType(),
                     XML.ECPAccountRT(),
                     XML.ECPBankPmtDlv(),
                     XML.SwitchSoloStartDate(),
                     XML.SwitchSoloIssueNum())))
Ejemplo n.º 4
0
    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) )
Ejemplo n.º 5
0
    def add_credit_card(self, credit_card):

        fields = [  XML.CardType(self.credit_card_type(credit_card)),  #  TODO  test all types
                    XML.CardNum(credit_card.number),
                    XML.ExpDate(self.expdate(credit_card)),
                    XML.NameOnCard(credit_card.first_name),
                    XML.CVNum(credit_card.verification_value), # TODO if credit_card.verification_value?
                    XML.ExtData(Name='LASTNAME', Value=credit_card.last_name) ]

        if self.requires_start_date_or_issue_number(credit_card):  #  TODO  TDD
            issue = format(credit_card.issue_number, two_digits=True)
            fields.append(XML.ExtData(Name='CardIssue', Value=issue)) # TODO  unless credit_card.start_month.blank? || credit_card.start_year.blank?

                #  TODO  format(credit_card.issue_number, :two_digits))

        return xStr(XML.Card(*fields))
 def failed_authorization_response(self):
     return xStr(
         XML.Response(
             XML.QuickResp(
                 XML.ProcStatus('841'),
                 XML.StatusMsg(
                     'Error validating card/account number range'),
                 XML.CustomerBin(), XML.CustomerMerchantID(),
                 XML.CustomerName(), XML.CustomerRefNum(),
                 XML.CustomerProfileAction(), XML.ProfileProcStatus('9576'),
                 XML.CustomerProfileMessage(
                     'Profile: Unable to Perform Profile Transaction. The Associated Transaction Failed. '
                 ), XML.CustomerAddress1(), XML.CustomerAddress2(),
                 XML.CustomerCity(), XML.CustomerState(), XML.CustomerZIP(),
                 XML.CustomerEmail(), XML.CustomerPhone(),
                 XML.CustomerProfileOrderOverrideInd(),
                 XML.OrderDefaultDescription(), XML.OrderDefaultAmount(),
                 XML.CustomerAccountType(), XML.CCAccountNum(),
                 XML.CCExpireDate(), XML.ECPAccountDDA(),
                 XML.ECPAccountType(), XML.ECPAccountRT(),
                 XML.ECPBankPmtDlv(), XML.SwitchSoloStartDate(),
                 XML.SwitchSoloIssueNum())))
Ejemplo n.º 7
0
    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))
                      ),
                      XML.Tender(
                          XML.Card(
                              XML.CardType(credit_card.type_name()),
                              XML.CardNum(credit_card.number),
                              XML.ExpDate('%04d%02d' % (credit_card.year, credit_card.month)),
                              XML.NameOnCard(credit_card.first_name),
                              XML.CVNum(credit_card.verification_value),
                              XML.ExtData(Name="LASTNAME", Value=credit_card.last_name )
                          ))))
        return xStr(request)
Ejemplo n.º 8
0
    def test_add_address_ship_to(self):
        address = self.gateway.add_address('ShipTo', name= 'Regulus Black',
                                           phone='(555)555-5555',
                                           address1='1234 My Street',
                                           city='Ottowa',
                                           state='ON',
                                           country='CA',
                                           zip='K1C2N6'
                                            )
        address = xStr(address)
        self.assert_xml_text(address, '/ShipTo/Name', 'Regulus Black')

        self.assert_match_xml('''<ShipTo>
                                   <Name>Regulus Black</Name>
                                   <Phone>(555)555-5555</Phone>
                                   <Address>
                                     <Street>1234 My Street</Street>
                                     <City>Ottowa</City>
                                     <State>ON</State>
                                     <Country>CA</Country>
                                     <Zip>K1C2N6</Zip>
                                   </Address>
                                 </ShipTo>''', address)  #  TODO  cover the other variables
    def successful_authorization_response(self):

        #        response = '''<?xml version="1.0" encoding="UTF-8"?> <Response> <ACResponse> <CommonDataResponse> <CommonMandatoryResponse HcsTcsInd="T" LangInd="00" MessageType="A" TzCode="705" Version="2"> <MerchantID>123456789012</MerchantID> <TerminalID>001</TerminalID> <TxRefNum>128E6C6A4FC6D4119A3700D0B706C51EE26DF570</TxRefNum> <TxRefIdx>0</TxRefIdx> <OrderNumber>1234567890123456</OrderNumber> <RespTime>10012001120003</RespTime> <ProcStatus>0</ProcStatus> <ApprovalStatus>1</ApprovalStatus> <ResponseCodes> <AuthCode>tntC09</AuthCode> <RespCode>00</RespCode> <HostRespCode>00</HostRespCode> <CVV2RespCode>M</CVV2RespCode> <HostCVV2RespCode>M</HostCVV2RespCode> <AVSRespCode>H</AVSRespCode> <HostAVSRespCode>Y</HostAVSRespCode> </ResponseCodes> </CommonMandatoryResponse> <CommonOptionalResponse> <AccountNum>4012888888881</AccountNum> <RespDate>010801</RespDate> <CardType>VI</CardType> <ExpDate>200512</ExpDate> <CurrencyCd>840</CurrencyCd> </CommonOptionalResponse> </CommonDataResponse> <AuthResponse> <AuthMandatoryResponse/> <AuthOptionalResponse> <POSEntryMode>01</POSEntryMode> <MISCData> <ActualRespCd>00 </ActualRespCd> </MISCData> <NetworkData> <AuthNetwkID>01</AuthNetwkID> </NetworkData> <VisaCard> <CPSData> <AuthCharInd>V</AuthCharInd> <ValidationCd>JU9E</ValidationCd> </CPSData> <AuthSource AuthSrc="5"/> <VisaCommCard VCC="S"/> </VisaCard> </AuthOptionalResponse> </AuthResponse> </ACResponse> </Response>'''

        #$print self.convert_xml_to_element_maker(response)

        alternate_TODO = XML.Response(
            XML.ACResponse(
                XML.CommonDataResponse(
                    XML.CommonMandatoryResponse(
                        XML.MerchantID('123456789012'),
                        XML.TerminalID('001'),
                        XML.TxRefNum(
                            '128E6C6A4FC6D4119A3700D0B706C51EE26DF570'),
                        XML.TxRefIdx('0'),
                        XML.OrderNumber('1234567890123456'),
                        XML.RespTime('10012001120003'),
                        XML.ProcStatus('0'),
                        XML.ApprovalStatus('1'),
                        XML.ResponseCodes(XML.AuthCode('tntC09'),
                                          XML.RespCode('00'),
                                          XML.HostRespCode('00'),
                                          XML.CVV2RespCode('M'),
                                          XML.HostCVV2RespCode('M'),
                                          XML.AVSRespCode('H'),
                                          XML.HostAVSRespCode('Y')),
                        HcsTcsInd='T',
                        LangInd='00',
                        MessageType='A',
                        TzCode='705',
                        Version='2'),
                    XML.CommonOptionalResponse(XML.AccountNum('4012888888881'),
                                               XML.RespDate('010801'),
                                               XML.CardType('VI'),
                                               XML.ExpDate('200512'),
                                               XML.CurrencyCd('840'))),
                XML.AuthResponse(
                    XML.AuthMandatoryResponse(),
                    XML.AuthOptionalResponse(
                        XML.POSEntryMode('01'),
                        XML.MISCData(XML.ActualRespCd('00 ')),
                        XML.NetworkData(XML.AuthNetwkID('01')),
                        XML.VisaCard(
                            XML.CPSData(XML.AuthCharInd('V'),
                                        XML.ValidationCd('JU9E')),
                            XML.AuthSource(AuthSrc='5'),
                            XML.VisaCommCard(VCC='S'))))))

        return xStr(
            XML.Response(
                XML.NewOrderResp(
                    XML.IndustryType(), XML.MessageType('AC'),
                    XML.MerchantID('000000'), XML.TerminalID('000'),
                    XML.CardBrand('MC'), XML.AccountNum('5454545454545454'),
                    XML.OrderID('1'),
                    XML.TxRefNum('4A785F5106CCDC41A936BFF628BF73036FEC5401'),
                    XML.TxRefIdx('1'), XML.ProcStatus('0'),
                    XML.ApprovalStatus('1'), XML.RespCode('00'),
                    XML.AVSRespCode('B '), XML.CVV2RespCode('M'),
                    XML.AuthCode('tst554'), XML.RecurringAdviceCd(),
                    XML.CAVVRespCode(),
                    XML.StatusMsg('Approved'), XML.RespMsg(),
                    XML.HostRespCode('100'), XML.HostAVSRespCode('I3'),
                    XML.HostCVV2RespCode('M'), XML.CustomerRefNum('2145108'),
                    XML.CustomerName('JOE SMITH'), XML.ProfileProcStatus('0'),
                    XML.CustomerProfileMessage('Profile Created'),
                    XML.RespTime('121825'))))
    def successful_authorization_response(self):

#        response = '''<?xml version="1.0" encoding="UTF-8"?> <Response> <ACResponse> <CommonDataResponse> <CommonMandatoryResponse HcsTcsInd="T" LangInd="00" MessageType="A" TzCode="705" Version="2"> <MerchantID>123456789012</MerchantID> <TerminalID>001</TerminalID> <TxRefNum>128E6C6A4FC6D4119A3700D0B706C51EE26DF570</TxRefNum> <TxRefIdx>0</TxRefIdx> <OrderNumber>1234567890123456</OrderNumber> <RespTime>10012001120003</RespTime> <ProcStatus>0</ProcStatus> <ApprovalStatus>1</ApprovalStatus> <ResponseCodes> <AuthCode>tntC09</AuthCode> <RespCode>00</RespCode> <HostRespCode>00</HostRespCode> <CVV2RespCode>M</CVV2RespCode> <HostCVV2RespCode>M</HostCVV2RespCode> <AVSRespCode>H</AVSRespCode> <HostAVSRespCode>Y</HostAVSRespCode> </ResponseCodes> </CommonMandatoryResponse> <CommonOptionalResponse> <AccountNum>4012888888881</AccountNum> <RespDate>010801</RespDate> <CardType>VI</CardType> <ExpDate>200512</ExpDate> <CurrencyCd>840</CurrencyCd> </CommonOptionalResponse> </CommonDataResponse> <AuthResponse> <AuthMandatoryResponse/> <AuthOptionalResponse> <POSEntryMode>01</POSEntryMode> <MISCData> <ActualRespCd>00 </ActualRespCd> </MISCData> <NetworkData> <AuthNetwkID>01</AuthNetwkID> </NetworkData> <VisaCard> <CPSData> <AuthCharInd>V</AuthCharInd> <ValidationCd>JU9E</ValidationCd> </CPSData> <AuthSource AuthSrc="5"/> <VisaCommCard VCC="S"/> </VisaCard> </AuthOptionalResponse> </AuthResponse> </ACResponse> </Response>'''

        #$print self.convert_xml_to_element_maker(response)

        alternate_TODO = XML.Response(
          XML.ACResponse(
            XML.CommonDataResponse(
              XML.CommonMandatoryResponse(
                XML.MerchantID('123456789012'),
                XML.TerminalID('001'),
                XML.TxRefNum('128E6C6A4FC6D4119A3700D0B706C51EE26DF570'),
                XML.TxRefIdx('0'),
                XML.OrderNumber('1234567890123456'),
                XML.RespTime('10012001120003'),
                XML.ProcStatus('0'),
                XML.ApprovalStatus('1'),
                XML.ResponseCodes(
                  XML.AuthCode('tntC09'),
                  XML.RespCode('00'),
                  XML.HostRespCode('00'),
                  XML.CVV2RespCode('M'),
                  XML.HostCVV2RespCode('M'),
                  XML.AVSRespCode('H'),
                  XML.HostAVSRespCode('Y')), HcsTcsInd='T', LangInd='00', MessageType='A', TzCode='705', Version='2'),
              XML.CommonOptionalResponse(
                XML.AccountNum('4012888888881'),
                XML.RespDate('010801'),
                XML.CardType('VI'),
                XML.ExpDate('200512'),
                XML.CurrencyCd('840'))),
            XML.AuthResponse(
              XML.AuthMandatoryResponse(),
              XML.AuthOptionalResponse(
                XML.POSEntryMode('01'),
                XML.MISCData(
                  XML.ActualRespCd('00 ')),
                XML.NetworkData(
                  XML.AuthNetwkID('01')),
                XML.VisaCard(
                  XML.CPSData(
                    XML.AuthCharInd('V'),
                    XML.ValidationCd('JU9E')),
                  XML.AuthSource(AuthSrc='5'),
                  XML.VisaCommCard(VCC='S'))))))

        return xStr(XML.Response(
                      XML.NewOrderResp(
                        XML.IndustryType(),
                        XML.MessageType('AC'),
                        XML.MerchantID('000000'),
                        XML.TerminalID('000'),
                        XML.CardBrand('MC'),
                        XML.AccountNum('5454545454545454'),
                        XML.OrderID('1'),
                        XML.TxRefNum('4A785F5106CCDC41A936BFF628BF73036FEC5401'),
                        XML.TxRefIdx('1'),
                        XML.ProcStatus('0'),
                        XML.ApprovalStatus('1'),
                        XML.RespCode('00'),
                        XML.AVSRespCode('B '),
                        XML.CVV2RespCode('M'),
                        XML.AuthCode('tst554'),
                        XML.RecurringAdviceCd(),
                        XML.CAVVRespCode(),
                        XML.StatusMsg('Approved'),
                        XML.RespMsg(),
                        XML.HostRespCode('100'),
                        XML.HostAVSRespCode('I3'),
                        XML.HostCVV2RespCode('M'),
                        XML.CustomerRefNum('2145108'),
                        XML.CustomerName('JOE SMITH'),
                        XML.ProfileProcStatus('0'),
                        XML.CustomerProfileMessage('Profile Created'),
                        XML.RespTime('121825'))))