def test_batch_txn_reversal(self): txnBatch = batch.Transactions() txnRev = fields.transactionReversal() txnRev.reportGroup = 'Planets' txnRev.customerId = '987654321' txnRev.cnpTxnId = '12345678000' txnRev.amount = 106 txnRev.orderSource = 'ecommerce' txnRev.id = 'thisisid' txnRev.pin = '123456' txnBatch.add(txnRev) 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(txnBatch, 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( 106, obj.batchRequest[0].transactionReversalAmount) self.assertEquals('%s.xml.asc' % filename, response)
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_submit(self, mock__put_file_to_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' transaction.card = card txns = batch.Transactions() txns.add(transaction) # first arg is not instance of batch.Transactions self.assertRaises(utils.VantivException, batch.submit, transaction, conf) # first arg is an new instance of utils.Configuration self.assertRaises(utils.VantivException, batch.submit, batch.Transactions(), conf) # second arg is not instance of utils.Configuration self.assertRaises(utils.VantivException, batch.submit, txns, 1) # Third arg is not sring self.assertRaises(utils.VantivException, batch.submit, txns, conf, txns) # Fourth arg is not positive int self.assertRaises(utils.VantivException, batch.submit, txns, conf, 'aaa', -1) mock__put_file_to_sftp.return_value = 'filename' self.assertEquals('filename', batch.submit(txns, conf))
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_submit(self): # Initial Transactions container transactions = batch.Transactions() # Transactions presented by dict txn_dict = { 'authorization': { 'reportGroup': 'Planets', 'orderId': '12344', 'amount': '106', 'orderSource': 'ecommerce', 'id': 'thisisid', 'card': { 'expDate': '1210', 'number': '4100000000000000', 'type': 'VI', } } } transactions.add(txn_dict) # 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 = 'Planets' 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) # Inital authorization with lodging info authorization3 = fields.authorization() authorization3.orderId = '2' authorization3.amount = 0 authorization3.reportGroup = 'Planets' authorization3.orderSource = 'ecommerce' authorization3.card = card authorization3.billtoaddress = billtoaddress authorization3.id = 'thisisid' lodging_info = fields.lodgingInfo() lodging_info.roomRate = 1001 lodging_info.roomTax = 1 lodging_charge = fields.lodgingCharge() lodging_charge.name = "RESTAURANT" lodging_info.lodgingCharge = [lodging_charge] authorization3.lodgingInfo = lodging_info # Add transaction to container transactions.add(authorization3) # 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 pinless debit request pinless_debit = fields.pinlessDebitRequestType() preferred_network = fields.preferredDebitNetworksType() preferred_network.debitNetworkName = ['Visa', 'MasterCard'] pinless_debit.preferredDebitNetworks = preferred_network pinless_debit.routingPreference = 'regular' sale.pinlessDebitRequest = pinless_debit # Add transaction to container transactions.add(sale) # Initial translate to low value token request translateToLow = fields.translateToLowValueTokenRequest() translateToLow.orderId = '1' translateToLow.token = 'gf5a4f564g6a' translateToLow.reportGroup = 'Planets' translateToLow.id = 'thisisid' # Add transaction to container transactions.add(translateToLow) 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(11117, obj.batchRequest[0].authAmount) self.assertEquals('%s.xml.asc' % filename, response)
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)