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 doCreateToken(cid="", saveToVault=False): '''Perform assign a customer a token Input: cid - optional - customer id to associate with this token. saveToVault - optional. Save the token in the customer's vault Output: Token Raises: Exceptions raised by wpTransact() ''' test.random() # get a random test data set # Step 1 Create an AuthorizationRequest Object and fill it in card = Card() card.number = test.getCardPAN() card.cvv = test.getCVV() card.expirationDate = test.getExpirationDate() tr = TokenRequest() tr.attachCard(card) tr.addToVault = saveToVault tr.customerId = cid # let the system assign a token # 2. Send the transaction on a serialized Request Object try: response = wpTransact("CreateToken", tr.serialize()) except: # pass the exception up. Nothing to do here at the moment raise # 3. Deserialize the result into a Response Object rp = TokenResponseParameters(response) log.info(">>>Response>>> \n%s", pformat(rp, indent=1)) if (rp.responseCode != 1): # response from Worldpay indicates failure errMsg = "CreateToken transaction failed. Result: " + rp.result + " Response Code: " + str( rp.responseCode) + " Message: " + rp.message print errMsg log.info(errMsg) return rp.responseCode token = rp.token log.info(">>>Response>>> \n%s", pformat(rp, indent=1)) # return the response code msg = "CreateToken transaction successful. Token: " + str(token) print msg log.info(msg) return token
def doCredit(): '''Perform a Credit transaction. This is a dangerous transaction in that it doesn't require a linked transaction Input: nothing Output: transaction code result Raises: Exceptions raised by wpTransact() ''' test.random() # get a random test record # 1. Fill in the Request Object card = Card() card.number = test.getCardPAN() card.cvv = test.getCVV() card.expirationDate = test.getExpirationDate() ar = AuthorizationRequest() ar.amount = test.getAmount() ar.attachCard(card) # attach the card object # 2. Send the transaction on a serialized Request Object try: response = wpTransact("Credit", 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) if (rp.responseCode != 1): # response from Worldpay indicates failure errMsg = "Credit transaction failed. Result: " + rp.result + " Response Code: " + str( rp.responseCode) + " Message: " + rp.message print errMsg log.info(errMsg) return rp.responseCode # return the response code msg = "Credit transaction successful. TransactionId: ", str( rp.transactionId) print msg log.info(msg) return rp.responseCode
def doUpdatePaymentAccount(cid, pid): '''Create a payment instrument and attach to a vault customer Input: cid - customer id pid - payment method id Output: nothing Raises: Exceptions raised by wpTransact() ''' test.reread() # reread the last record as I am assuming we are simply modifying the last account created # 1. Fill in the Request Object card = Card() card.number = test.getCardPAN() card.cvv = '999' # this is the field we will modify for this test case card.expirationDate = test.getExpirationDate() va = PaymentAccountRequest() va.customerId = cid va.primary = True va.paymnetMethodId = pid va.attachCard(card) # 2. Send the transaction on a serialized Request Object try: response = wpTransact("UpdatePaymentAccount", va.serialize(), cid, pid) except: # pass the exception up. Nothing to do here at the moment raise # 3. Deserialize the result into a Response Object rp = PaymentAccountResponseParameters(response) log.info(">>>Response>>> \n%s", pformat(rp, indent=1)) if (rp.responseCode != 1): errMsg = "doUpdatePaymentAccount failed. Result: " + str(rp.result) + " Response Code: " + str(rp.responseCode) + " Message: " + rp.message raise WpBadResponseError(errMsg) msg = "Update Payment Account transaction successful. CustomerId: " + str(rp.vaultPaymentMethod.customerId) + " PaymentId: " + str(rp.vaultPaymentMethod.paymentId) print msg log.info(msg) return
def doCreatePaymentAccount(cid): '''Create a payment instrument and attach to a vault customer Input: cid - customer id Output: pid - payment id Raises: Exceptions raised by wpTransact() ''' test.random() # get a random test data set # 1. Fill in the Request Object card = Card() card.number = test.getCardPAN() card.cvv = test.getCVV() card.expirationDate = test.getExpirationDate() va = PaymentAccountRequest() va.customerId = cid va.primary = True va.attachCard(card) # 2. Send the transaction on a serialized Request Object try: response = wpTransact("CreatePaymentAccount", va.serialize(), cid) except: # pass the exception up. Nothing to do here at the moment raise # 3. Deserialize the result into a Response Object rp = PaymentAccountResponseParameters(response) log.info(">>>Response>>> \n%s", pformat(rp, indent=1)) if (rp.responseCode != 1): errMsg = "doCreatePaymentAccount failed. Result: " + str(rp.result) + " Response Code: " + str(rp.responseCode) + " Message: " + rp.message raise WpBadResponseError(errMsg) msg = "Create Payment Account transaction successful. CustomerId: " + str(rp.vaultPaymentMethod.customerId) + " PaymentId: " + str(rp.vaultPaymentMethod.paymentId) print msg log.info(msg) return rp.vaultPaymentMethod.paymentId
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 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