def test_numAccountUpdates(self, mock__get_file_str_from_sftp):
        transaction = fields.authorization()
        transaction.reportGroup = 'Planets'
        transaction.orderId = '12344'
        transaction.amount = 106
        transaction.orderSource = 'ecommerce'
        transaction.id = 'thisisid'

        card = fields.cardType()
        card.number = '4100000000000000'
        card.expDate = '1210'
        card.type = 'VI'

        mock__get_file_str_from_sftp.return_value = """<cnpResponse version='12.10' response='0' message='Valid Format' xmlns='http://www.vantivcnp.com/schema'>
                        <batchResponse cnpBatchId='12344' merchantId='56789' numAccountUpdates='3' xmlns='http://www.vantivcnp.com/schema'>
                            <saleResponse>
                                <cnpTxnId>123</cnpTxnId>
                                <accountUpdater>
                                    <accountUpdateSource>N</accountUpdateSource>
                                </accountUpdater>
                                </saleResponse>
                            </batchResponse>
                       </cnpResponse>
                       """

        response = batch.retrieve('retrieve_file', conf)
        self.assertEquals(
            response['batchResponse']['saleResponse']['cnpTxnId'], '123')
        self.assertEquals(response['batchResponse']['@numAccountUpdates'], '3')
Esempio n. 2
0
    def test_table_2_5_ECPreNoteSale(self):
        txn_dict = {
            'echeckPreNoteSale': [{
                'orderId': 'ECPreNoteSale',
                'orderSource': 'ecommerce',
                'id': 'thisisid',
                'billToAddress': {
                    'name': 'PreNote Sale Corp',
                },
                'echeck': {
                    'accType': 'Corporate',
                    'accNum': '1092969901',
                    'routingNum': '011075150',
                }
            }],
        }

        filename = 'test_table_2_5_ECPreNoteSale_%s' % datetime.datetime.now(
        ).strftime("%Y%m%d%H%M%S%f")

        # submit to Vaitiv eCommerce and get filename as response
        response_filename = batch.submit(txn_dict, conf, filename)
        self.assertEquals('%s.xml.asc' % filename, response_filename)

        retry = True
        tried = 0
        while retry:
            tried += 1
            try:
                response = batch.retrieve(response_filename, conf)
                self.assertEquals(
                    '000', response['batchResponse']
                    ['echeckPreNoteSaleResponse']['response'])
                self.assertEquals(
                    'Approved', response['batchResponse']
                    ['echeckPreNoteSaleResponse']['message'])
                retry = False
            except:
                # sleep 1 minute waiting for batch get processed
                print("sleep 30 seconds waiting for batch get processed")
                time.sleep(30)
            if tried > 20:
                self.fail("Timeout for retrieve batch response")
                break
    def test_batch_mix_transaction_recurringtransaction(self):
        txn_dict = {
            'sameDayFunding':
            0,
            'authorization': [{
                'reportGroup': 'Planets',
                'orderId': '12344',
                'amount': '100',
                'orderSource': 'ecommerce',
                'id': 'thisisid',
                'card': {
                    'expDate': '1210',
                    'number': '4100000000000000',
                    'type': 'VI',
                }
            }, {
                'reportGroup': 'Planets',
                'orderId': '12345',
                'amount': '200',
                'orderSource': 'ecommerce',
                'id': 'thisisid',
                'card': {
                    'expDate': '1210',
                    'number': '4100000000000000',
                    'type': 'VI',
                }
            }, {
                'reportGroup': 'Planets',
                'orderId': '12346',
                'amount': '300',
                'orderSource': 'ecommerce',
                'id': 'thisisid',
                'card': {
                    'expDate': '1210',
                    'number': '4100000000000000',
                    'type': 'VI',
                }
            }],
            'sale': {
                'reportGroup': 'Planets',
                'orderId': '12344',
                'amount': '106',
                'orderSource': 'ecommerce',
                'id': 'thisisid',
                'card': {
                    'expDate': '1210',
                    'number': '4100000000000000',
                    'type': 'VI',
                }
            },
            'createPlan': {
                'amount': '106',
                'planCode': '1',
                'name': 'plan name',
                'description': 'plan description',
                'intervalType': 'ANNUAL'
            }
        }

        filename = 'batch_test_%s' % datetime.datetime.now().strftime(
            "%Y%m%d%H%M%S%f")

        # stream to Vaitiv eCommerce and get object as response
        response_filename = batch.submit(txn_dict, conf, filename)
        self.assertEquals('%s.xml.asc' % filename, response_filename)

        response = {}

        # Example for RFRRequest
        RFRRequest = fields.RFRRequest()

        retry = True
        tried = 0
        while retry:
            tried += 1
            try:
                response = batch.retrieve(response_filename, conf)
                retry = False
                RFRRequest.cnpSessionId = response['@cnpSessionId']
            except:
                # sleep 1 minute waiting for batch get processed
                print("sleep 30 seconds waiting for batch get processed")
                time.sleep(30)
            if tried > 20:
                self.fail("Timeout for retrieve batch response")
                break

        transactions = batch.Transactions()
        transactions.sameDayFunding = True
        transactions.add(RFRRequest)

        # submit batch request
        response_rfr_filename = batch.submit(transactions, conf)

        retry = True
        tried = 0
        while retry:
            tried += 1
            try:
                # retrieve rfr batch request
                response_rfr = batch.retrieve(response_rfr_filename, conf)
                retry = False
                self.assertIn('batchResponse', response_rfr)
                self.assertEquals(
                    response_rfr['batchResponse'][0]['authorizationResponse']
                    [0]['cnpTxnId'], response['batchResponse'][0]
                    ['authorizationResponse'][0]['cnpTxnId'])
                self.assertEquals(
                    response_rfr['batchResponse'][1]['createPlanResponse']
                    ['cnpTxnId'], response['batchResponse'][1]
                    ['createPlanResponse']['cnpTxnId'])
            except:
                # sleep 1 minute waiting for batch get processed
                print("sleep 30 seconds waiting for rfr batch get processed")
                time.sleep(30)
            if tried > 20:
                self.fail("Timeout for retrieve rfr batch response")
                break
    def test_batch_dict(self):
        txn_dict = {
            'authorization': [{
                'reportGroup': 'Planets',
                'orderId': '12344',
                'amount': '100',
                'orderSource': 'ecommerce',
                'id': 'thisisid',
                'card': {
                    'expDate': '1210',
                    'number': '4457010000000009',
                    'type': 'VI',
                }
            }, {
                'reportGroup': 'Planets',
                'orderId': '12345',
                'amount': '200',
                'orderSource': 'ecommerce',
                'id': 'thisisid',
                'card': {
                    'expDate': '1210',
                    'number': '4457010000000009',
                    'type': 'VI',
                }
            }, {
                'reportGroup': 'Planets',
                'orderId': '12346',
                'amount': '300',
                'orderSource': 'ecommerce',
                'id': 'thisisid',
                'card': {
                    'expDate': '1210',
                    'number': '4457010000000009',
                    'type': 'VI',
                }
            }, {
                'reportGroup': 'Planets',
                'orderId': '12347',
                'amount': '300',
                'orderSource': 'ecommerce',
                'id': 'thisisid',
                'card': {
                    'expDate': '1210',
                    'number': '4457010000000009',
                    'type': 'VI',
                },
                'lodgingInfo': {
                    'roomRate': '1001',
                    'roomTax': '1',
                    'lodgingCharge': [{
                        'name': 'OTHER'
                    }],
                }
            }],
            'sale': [
                {
                    'reportGroup': 'Planets',
                    'orderId': '12344',
                    'amount': '106',
                    'orderSource': 'ecommerce',
                    'id': 'thisisid',
                    'card': {
                        'expDate': '1210',
                        'number': '4457010000000009',
                        'type': 'VI',
                    }
                },
                {
                    'reportGroup': 'Planets',
                    'orderId': '12354',
                    'amount': '106',
                    'orderSource': 'ecommerce',
                    'id': 'thisisid',
                    'card': {
                        'expDate': '1210',
                        'number': '4457010000000009',
                        'type': 'VI',
                    },
                    # 'pinlessDebitRequest': {
                    #     'routingPreference': 'regular',
                    #     'preferredDebitNetworks': {'debitNetworkName': ['visa']}
                    # }
                }
            ],
            'translateToLowValueTokenRequest': {
                'reportGroup': 'Planets',
                'orderId': '12344',
                'id': 'thisisid',
                'token': 'g45a684fw54f'
            }
        }

        filename = 'batch_test_%s' % datetime.datetime.now().strftime(
            "%Y%m%d%H%M%S%f")

        # stream to Vaitiv eCommerce and get object as response
        response_filename = batch.submit(txn_dict, conf, filename)
        self.assertEquals('%s.xml.asc' % filename, response_filename)

        response = {}

        # Example for RFRRequest
        RFRRequest = fields.RFRRequest()

        retry = True
        tried = 0
        while retry:
            tried += 1
            try:
                response = batch.retrieve(response_filename, conf)
                print("batch.retrieve() ok")
                retry = False
                RFRRequest.cnpSessionId = response['@cnpSessionId']
            except utils.VantivException as ex:
                # sleep 1 minute waiting for batch get processed
                print(ex)
                print("sleep 30 seconds waiting for batch get processed")
                time.sleep(30)
            if tried > 20:
                self.fail("Timeout for retrieve batch response")
                break

        transactions = batch.Transactions()
        transactions.add(RFRRequest)

        # submit batch request
        response_rfr_filename = batch.submit(transactions, conf)

        retry = True
        tried = 0
        while retry:
            tried += 1
            try:
                # retrieve rfr batch request
                response_rfr = batch.retrieve(response_rfr_filename, conf)
                retry = False
                self.assertIn('batchResponse', response_rfr)
                self.assertEquals(
                    response_rfr['batchResponse']['authorizationResponse'][0]
                    ['cnpTxnId'], response['batchResponse']
                    ['authorizationResponse'][0]['cnpTxnId'])
            except:
                # sleep 1 minute waiting for batch get processed
                print("sleep 30 seconds waiting for rfr batch get processed")
                time.sleep(30)
            if tried > 20:
                self.fail("Timeout for retrieve rfr batch response")
                break
    def test_batch_rfr(self):
        # Initial Transactions container
        transactions = batch.Transactions()
        transactions.sameDayFunding = True

        # Card
        card = fields.cardType()
        card.number = '4457010000000009'
        card.expDate = '0121'
        card.cardValidationNum = '349'
        card.type = 'VI'

        # eCheck
        # echeck = fields.echeck()
        # echeck.accType = 'Checking'
        # echeck.accNum = '4099999992'
        # echeck.routingNum = '011075150'

        # billtoaddress
        billtoaddress = fields.contact()
        billtoaddress.firstName = 'Mike'
        billtoaddress.middleInitial = 'J'
        billtoaddress.lastName = 'Hammer'
        billtoaddress.phone = '999-999-9999'

        # Initial authorization
        authorization = fields.authorization()
        authorization.orderId = '1'
        authorization.amount = 10010
        authorization.reportGroup = u'русский中文'
        authorization.orderSource = 'ecommerce'
        authorization.card = card
        authorization.billtoaddress = billtoaddress
        authorization.id = 'thisisid'
        # Add transaction to container
        transactions.add(authorization)

        # Initial authorization
        authorization2 = fields.authorization()
        authorization2.orderId = '2'
        authorization2.amount = 1001
        authorization2.reportGroup = 'Planets'
        authorization2.orderSource = 'ecommerce'
        authorization2.card = card
        authorization2.billtoaddress = billtoaddress
        authorization2.id = 'thisisid'
        # Add transaction to container
        transactions.add(authorization2)

        # Initial authorization
        sale = fields.sale()
        sale.orderId = '1'
        sale.amount = 10010
        sale.reportGroup = 'Planets'
        sale.orderSource = 'ecommerce'
        sale.card = card
        sale.billtoaddress = billtoaddress
        sale.id = 'thisisid'
        # Add transaction to container
        transactions.add(sale)

        filename = 'batch_test_%s' % datetime.datetime.now().strftime(
            "%Y%m%d%H%M%S%f")

        # stream to Vaitiv eCommerce and get object as response
        response_filename = batch.submit(transactions, conf, filename)
        self.assertEquals('%s.xml.asc' % filename, response_filename)

        response = {}

        # Example for RFRRequest
        RFRRequest = fields.RFRRequest()

        retry = True
        tried = 0
        while retry:
            tried += 1
            try:
                response = batch.retrieve(response_filename, conf)
                retry = False
                RFRRequest.cnpSessionId = response['@cnpSessionId']
            except:
                # sleep 1 minute waiting for batch get processed
                print("sleep 30 seconds waiting for batch get processed")
                time.sleep(30)
            if tried > 20:
                self.fail("Timeout for retrieve batch response")
                break

        transactions = batch.Transactions()
        transactions.add(RFRRequest)

        # submit batch request
        response_rfr_filename = batch.submit(transactions, conf)

        retry = True
        tried = 0
        while retry:
            tried += 1
            try:
                # retrieve rfr batch request
                response_rfr = batch.retrieve(response_rfr_filename, conf)
                retry = False
                self.assertIn('batchResponse', response_rfr)
                self.assertEquals(
                    response_rfr['batchResponse']['authorizationResponse'][0]
                    ['cnpTxnId'], response['batchResponse']
                    ['authorizationResponse'][0]['cnpTxnId'])
            except:
                # sleep 1 minute waiting for batch get processed
                print("sleep 30 seconds waiting for rfr batch get processed")
                time.sleep(30)
            if tried > 20:
                self.fail("Timeout for retrieve rfr batch response")
                break
    def test_batch_ctx(self):
        conf = utils.Configuration()
        conf.user = conf.payfacUsername_v12_7
        conf.password = conf.payfacPassword_v12_7
        conf.sftp_username = conf.payfacSftpUsername_v12_7
        conf.sftp_password = conf.payfacSftpPassword_v12_7
        conf.merchantId = conf.payfacMerchantId_v12_7

        transactions = batch.Transactions()

        fundsTransferIdString = str(int(time.time()))

        echeck = fields.echeckTypeCtx()
        echeck.accNum = "1092969901"
        echeck.accType = "Checking"
        ctxPaymentInformation = fields.ctxPaymentInformationType()
        ctxPaymentInformation.ctxPaymentDetail = ["ctx payment detail"]
        echeck.ctxPaymentInformation = ctxPaymentInformation
        echeck.checkNum = "123455"
        echeck.routingNum = "011075150"

        # vendorCreditCtx
        vendorCreditCtx = fields.vendorCreditCtx()
        vendorCreditCtx.id = 'ThisIsID'
        vendorCreditCtx.amount = 123
        vendorCreditCtx.accountInfo = echeck
        vendorCreditCtx.fundingSubmerchantId = "submerchantId"
        vendorCreditCtx.vendorName = "submerchantName"
        vendorCreditCtx.fundsTransferId = fundsTransferIdString
        transactions.add(vendorCreditCtx)

        # vendorDebitCtx
        vendorDebitCtx = fields.vendorDebitCtx()
        vendorDebitCtx.id = 'ThisIsID'
        vendorDebitCtx.amount = 123
        vendorDebitCtx.accountInfo = echeck
        vendorDebitCtx.fundingSubmerchantId = "submerchantId"
        vendorDebitCtx.vendorName = "submerchantName"
        vendorDebitCtx.fundsTransferId = fundsTransferIdString
        transactions.add(vendorDebitCtx)

        # submerchantDebitCtx
        submerchantDebitCtx = fields.submerchantDebitCtx()
        submerchantDebitCtx.id = 'ThisIsID'
        submerchantDebitCtx.amount = 123
        submerchantDebitCtx.accountInfo = echeck
        submerchantDebitCtx.fundingSubmerchantId = "submerchantId"
        submerchantDebitCtx.submerchantName = "submerchantName"
        submerchantDebitCtx.fundsTransferId = fundsTransferIdString
        transactions.add(submerchantDebitCtx)

        # submerchantCreditCtx
        submerchantCreditCtx = fields.submerchantCreditCtx()
        submerchantCreditCtx.id = 'ThisIsID'
        submerchantCreditCtx.amount = 123
        submerchantCreditCtx.accountInfo = echeck
        submerchantCreditCtx.fundingSubmerchantId = "submerchantId"
        submerchantCreditCtx.submerchantName = "submerchantName"
        submerchantCreditCtx.fundsTransferId = fundsTransferIdString
        transactions.add(submerchantCreditCtx)

        filename = 'batch_test_%s' % datetime.datetime.now().strftime(
            "%Y%m%d%H%M%S%f")
        # stream to Vaitiv eCommerce and get object as response
        response = batch.submit(transactions, conf, filename)

        if conf.useEncryption:
            # Using encryption.
            retry = True
            tried = 0
            withEncryptionReponseFilepath = ''
            while retry:
                tried += 1
                try:
                    withEncryptionReponseFilepath = batch._get_file_from_sftp(
                        response, conf, False, 60)
                    retry = False
                except:
                    # sleep 1 minute waiting for batch get processed
                    print("sleep 30 seconds waiting for batch get processed")
                    time.sleep(30)
                if tried > 20:
                    self.fail("Timeout for retrieve batch response")
                    break

            call(["cat", withEncryptionReponseFilepath])
            ### <<< WITH ENCRYPTION

            with open(withEncryptionReponseFilepath, 'r') as xml_file:
                obj = fields.CreateFromDocument(xml_file.read())
                self.assertEquals("Valid Format", obj.message)

        else:
            with open(
                    os.path.join(conf.batch_requests_path,
                                 '%s.xml' % filename), 'r') as xml_file:
                obj = fields.CreateFromDocument(xml_file.read())
                self.assertEquals(1, obj.numBatchRequests)
                self.assertEquals(0, obj.batchRequest[0].authAmount)

            self.assertEquals('%s.xml.asc' % filename, response)

        retry = True
        tried = 0
        while retry:
            tried += 1
            try:
                # retrieve batch request

                responseObj = batch.retrieve(response, conf)
                retry = False

            except Exception as ex:

                if 'Cannot find file' in ex.args[0]:
                    # sleep 1 minute waiting for batch get processed
                    print(
                        "sleep 30 seconds waiting for batch to get processed")
                    time.sleep(30)
                else:
                    #retry = False
                    self.fail(ex.args[0])

            if tried > 20:
                self.fail("Timeout for retrieving batch response")
        self.assertIn(u'batchResponse', responseObj)