Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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
Exemplo n.º 4
0
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
Exemplo n.º 5
0
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
Exemplo n.º 6
0
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]
Exemplo n.º 7
0
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