def doCreateCustomer(): '''Perform Create Customer in the vault Input: nothing Output: CustomerId Raises: Exceptions raised by wpTransact() ''' test.random() # get a random test data set # 1. Fill in the Request Object address = Address() address.line1 = test.getAddress() address.city = test.getCity() address.state = test.getState() address.zip = test.getZip() address.country = test.getCountry() address.company = test.getCompany() address.phone = test.getPhone() udf1 = UserDefinedField() udf2 = UserDefinedField() n = datetime.now() udf1.udfName = 'udf1' udf1.value = n.strftime('%d-%b-%y') udf2.udfName = 'udf2' udf2.value = n.strftime('%I:%M %p') cr = CustomerRequest() cr.firstName = test.getFirstName() cr.lastName = test.getLastName() cr.phoneNumber = test.getPhone() cr.emailAddress = test.getEmail() cr.company = test.getCompany() cr.notes = "Joe Kleinwaechter entered this from his python app. Need to delete it." cr.attachAddress(address) cr.attachUserDefinedField(udf1) cr.attachUserDefinedField(udf2) # 2. Send the transaction on a serialized Request Object try: response = wpTransact("CreateCustomer", cr.serialize()) except: # pass the exception up. Nothing to do here at the moment raise # 3. Deserialize the result into a Response Object rp = CustomerResponseParameters(response) log.info(">>>Response>>> \n%s", pformat(rp, indent=1)) if (rp.responseCode != 1): errMsg = "doCreateCustomer failed. Result: " + str(rp.result) + " Response Code: " + str(rp.responseCode) + " Message: " + rp.message raise WpBadResponseError(errMsg) msg = "Create Customer transaction successful. CustomerId: " + str(rp.customerId) print msg log.info(msg) return rp.customerId
def doCreateCustomerAndPayment(): '''Perform Create Customer in the vault Input: nothing Output: CustomerId Raises: Exceptions raised by wpTransact() ''' test.random() # get a random test data set # 1. Fill in the Request Object address = Address() address.line1 = test.getAddress() address.city = test.getCity() address.state = test.getState() address.zip = test.getZip() address.country = test.getCountry() address.company = test.getCompany() address.phone = test.getPhone() card = Card() card.number = test.getCardPAN() card.cvv = test.getCVV() card.expirationDate = test.getExpirationDate() cr = CustomerAndPaymentRequest() cr.firstName = test.getFirstName() cr.lastName = test.getLastName() cr.phoneNumber = test.getPhone() cr.emailAddress = test.getEmail() cr.company = test.getCompany() cr.notes = "Joe Kleinwaechter entered this from his python app. Need to delete it." cr.primary = True cr.attachAddress(address) cr.attachCard(card) # 2. Send the transaction on a serialized Request Object try: response = wpTransact("CreateCustomerAndPayment", cr.serialize()) except: # pass the exception up. Nothing to do here at the moment raise # 3. Deserialize the result into a Response Object rp = CustomerAndPaymentResponseParameters(response) log.info(">>>Response>>> \n%s", pformat(rp, indent=1)) if (rp.responseCode != 1): errMsg = "doCreateCustomerAndPayment failed. Result: " + str(rp.result) + " Response Code: " + str(rp.responseCode) + " Message: " + rp.message raise WpBadResponseError(errMsg) msg = "Create Customer and Payment transaction successful. CustomerId: " + str(rp.vaultCustomer.customerId) + " PaymentId: " + str(rp.vaultCustomer.primaryPaymentMethodId) print msg log.info(msg) return rp.vaultCustomer.customerId
def doChargeWithToken(cid, token=""): '''This is a test of the charge with token functionality which seems to be broken It is assumed the payment method is 1 Input: cid = customer id token = optianl token to use instead of card Output: Raises: WpBadResponseError Exceptions passed from wpTransact() ''' pvt = PaymentVaultToken() pvt.customerId = cid if token == "": pvt.paymentMethodId = 1 pvt.paymentType = "CREDIT_CARD" else: pvt.paymentMethodId = token ar = AuthorizationRequest() ar.amount = 10.0 ar.attachPaymentVaultToken(pvt) # attach the vault object try: response = wpTransact("Charge", ar.serialize()) except: # pass the exception up. Nothing to do here at the moment raise rp = AuthResponseParameters(response) log.info(">>>Response>>> \n%s", pformat(rp, indent=1)) if (rp.responseCode != 1): # response from Worldpay indicates failure errMsg = "Charge failed. Result: , " + rp.result + " Response Code: " + str(rp.responseCode) + " Message: " + rp.message raise WpBadResponseError(errMsg) # return the transaction id and amount transactionId = rp.transaction.transactionId msg = "Charge transaction successful. TransactionId:" + str(transactionId) + "(" + test.getFirstName() + " " + test.getLastName() + " $" + str(test.getAmount()) + ")" print msg log.info(msg) return [transactionId, ar.amount]
def doManualAuthTransaction(withCapture=False, verifyOnly=False): '''This allows an auth transaction not using the random test database Input: withCapture - True if doing a Charge, False if just an Auth verifyOnly - True if this is only a verify request, False if not Output: if verify - responseCode else [transaction id, amount] Raises: WpBadResponseError Exceptions passed from wpTransact() ''' # 1. Fill in the Request Object # Create the objects being utilized ar = AuthorizationRequest() address = Address() card = Card() sd = ServiceData() ei = ExtendedInformation() address.line1 = "201 17th Street" address.city = "Atlanta" address.state = "GA" address.zip = "30000" address.country = "USA" address.company = "Wordplay" address.phone = "678.587.1836" card.trackData = "%B4444333322221111^SECURENET^20041015432112345678?;4444333322221111=20041015432112345678?" ####################################### # % - sentinel code # B - B type Track 1 data # 4444333322221111 - pan # ^SECURENET^ - name (23 chars or less) (^ are field seperators) # 2004 - expiration date YYMM # 101 - service code 1=International capable, 0=Normal Rules 1=no restructions # 5432112345678? - Discretionary data # ; - Track 2 data # 4444333322221111 - PAN # = - seperator # 2004 - expiration date # 101 - service code # 5432112345678 - discretionary data # ? - sentinal code ####################################### # card.number = "5500000000000004" # MC # card.cvv = "111" # card.expirationDate = "03/20" sd.gratuityAmount = 1.96 sd.server = "Joey" ar.amount = 10.39 # Build the object relationships log.debug("SD: %s\n", pformat(sd.serialize(), indent=1)) ei.attachServiceData(sd) log.debug("EI: %s\n", pformat(ei.serialize(), indent=1)) ar.attachExtendedInformation(ei) log.debug("Address: %s\n", pformat(address.serialize(), indent=1)) card.attachAddress(address) # attach the address object log.debug("Card: %s\n", pformat(card.serialize(), indent=1)) ar.attachCard(card) # attach the card object if withCapture: # we've overloaded this function as most of the code is the same for Charge, Auth, and verify operation = "Charge" else: if verifyOnly: operation = "Verify" else: operation = "Authorize" # 2. Send the transaction on a serialized Request Object try: response = wpTransact(operation, ar.serialize()) except: # pass the exception up. Nothing to do here at the moment raise # 3. Deserialize the result into a Response Object rp = AuthResponseParameters(response) log.info(">>>Response>>> \n%s", pformat(rp, indent=1)) if (rp.responseCode != 1): # response from Worldpay indicates failure errMsg = operation + " failed. Result: , " + rp.result + " Response Code: " + str(rp.responseCode) + " Message: " + rp.message raise WpBadResponseError(errMsg) if verifyOnly: msg = operation + " transaction successful. (" + test.getFirstName() + " " + test.getLastName() + " $" + str(test.getAmount()) + ")" print msg log.info(msg) return rp.responseCode else: # return the transaction id and amount transactionId = rp.transaction.transactionId msg = operation + " transaction successful. TransactionId:" + str(transactionId) + "(" + test.getFirstName() + " " + test.getLastName() + " $" + str(test.getAmount()) + ")" print msg log.info(msg) return [transactionId, ar.amount]
def baseAuthTransaction(withCapture=False, verifyOnly=False): '''Perform the transactions that appear like an auth transaction Input: withCapture - True if doing a Charge, False if just an Auth verifyOnly - True if this is only a verify request, False if not Output: if verify - responseCode else [transaction id, amount] Raises: WpBadResponseError Exceptions passed from wpTransact() ''' # 1. Fill in the Request Object # Fill in Address object address = Address() test.random() address.line1 = test.getAddress() address.city = test.getCity() address.state = test.getState() address.zip = test.getZip() address.country = test.getCountry() address.company = test.getCompany() address.phone = test.getPhone() # Fill in Card object card = Card() card.number = test.getCardPAN() card.cvv = test.getCVV() card.expirationDate = test.getExpirationDate() # Fill in AuthorizationRequest object ar = AuthorizationRequest() ar.amount = test.getAmount() # Build the full auth request object by attaching supporting objects card.attachAddress(address) ar.attachCard(card) if withCapture: # we've overloaded this function as most of the code is the same for Charge, Auth, and verify operation = "Charge" else: if verifyOnly: operation = "Verify" else: operation = "Authorize" # 2. Send the transaction on a serialized Request Object log.debug("Sending transaction\n") try: response = wpTransact(operation, ar.serialize()) except: # pass the exception up. Nothing to do here at the moment raise # 3. Deserialize the result into a Response Object rp = AuthResponseParameters(response) log.info(">>>Response>>> \n%s", pformat(rp, indent=1)) if (rp.responseCode != 1): # response from Worldpay indicates failure errMsg = operation + " failed. Result: , " + rp.result + " Response Code: " + str(rp.responseCode) + " Message: " + rp.message raise WpBadResponseError(errMsg) if verifyOnly: msg = operation + " transaction successful. (" + test.getFirstName() + " " + test.getLastName() + " $" + str(test.getAmount()) + ")" print msg log.info(msg) return rp.responseCode else: # return the transaction id and amount transactionId = rp.transaction.transactionId msg = operation + " transaction successful. TransactionId:" + str(transactionId) + "(" + test.getFirstName() + " " + test.getLastName() + " $" + str(test.getAmount()) + ")" print msg log.info(msg) return [transactionId, ar.amount]
def doUpdateCustomer(cid): '''Perform Create Customer in the vault Input: cid - customer id Output: nothing Raises: Exceptions raised by wpTransact() ''' # Note that for test purposes, this is just going to read back in the current test record and fill it in under the assumption that the cid passed was the last one created test.reread() # get the current test data set # 1. Fill in the Request Object address = Address() address.line1 = test.getAddress() address.city = test.getCity() address.state = test.getState() address.zip = test.getZip() address.country = test.getCountry() address.company = test.getCompany() address.phone = test.getPhone() udf1 = UserDefinedField() udf2 = UserDefinedField() n = datetime.now() udf1.udfName = 'udf1' udf1.value = n.strftime('%d-%b-%y') udf2.udfName = 'udf2' udf2.value = n.strftime('%I:%M %p') cr = CustomerRequest() cr.firstName = test.getFirstName() cr.lastName = test.getLastName() cr.phoneNumber = test.getPhone() cr.emailAddress = test.getEmail() cr.company = test.getCompany() cr.attachAddress(address) cr.attachUserDefinedField(udf1) cr.attachUserDefinedField(udf2) n = datetime.now() cr.notes = "This record updated on " + n.strftime('%d-%b-%y @%I:%M %p') # 2. Send the transaction on a serialized Request Object try: response = wpTransact("UpdateCustomer", cr.serialize(), cid) except: # pass the exception up. Nothing to do here at the moment raise # 3. Deserialize the result into a Response Object rp = CustomerResponseParameters(response) log.info(">>>Response>>> \n%s", pformat(rp, indent=1)) if (rp.responseCode != 1): errMsg = "doUpdateCustomer failed. Result: " + str(rp.result) + " Response Code: " + str(rp.responseCode) + " Message: " + rp.message raise WpBadResponseError(errMsg) msg = "Update Customer transaction successful. CustomerId: " + str(rp.customerId) print msg log.info(msg) return
def doUpdateCustomerAndPayment(cid): '''Perform Update Customer in the vault Input: cid - customer id Output: CustomerId Raises: Exceptions raised by wpTransact() ''' test.reread() # get a random test data set # 1. Fill in the Request Object address = Address() address.line1 = test.getAddress() address.city = test.getCity() address.state = test.getState() address.zip = test.getZip() address.country = test.getCountry() address.company = test.getCompany() address.phone = test.getPhone() udf1 = UserDefinedField() udf2 = UserDefinedField() n = datetime.now() udf1.udfName = 'udf1' # this is the field we will modify for this test case udf1.value = n.strftime('%d-%b-%y') udf2.udfName = 'udf2' # this is the field we will modify for this test case udf2.value = n.strftime('%I:%M %p') card = Card() card.number = test.getCardPAN() card.cvv = '999' # this is the field we will modify for this test case card.expirationDate = test.getExpirationDate() cr = CustomerAndPaymentRequest() cr.customerId = cid cr.paymentMethodId = 1 cr.firstName = test.getFirstName() cr.lastName = test.getLastName() cr.phoneNumber = test.getPhone() cr.emailAddress = test.getEmail() cr.company = test.getCompany() cr.notes = "This record had been modified using unicorn dust." cr.primary = True cr.attachAddress(address) cr.attachCard(card) cr.attachUserDefinedField(udf1) cr.attachUserDefinedField(udf2) # 2. Send the transaction on a serialized Request Object try: response = wpTransact("UpdateCustomerAndPayment", cr.serialize(), cid) except: # pass the exception up. Nothing to do here at the moment raise # 3. Deserialize the result into a Response Object rp = CustomerAndPaymentResponseParameters(response) log.info(">>>Response>>> \n%s", pformat(rp, indent=1)) if (rp.responseCode != 1): errMsg = "doUpdateCustomerAndPayment failed. Result: " + str(rp.result) + " Response Code: " + str(rp.responseCode) + " Message: " + rp.message raise WpBadResponseError(errMsg) msg = "Update Customer and Payment transaction successful. CustomerId: " + str(rp.vaultCustomer.customerId) + " PaymentId: " + str(rp.vaultCustomer.primaryPaymentMethodId) print msg log.info(msg) return rp.vaultCustomer.customerId