Exemple #1
0
def doGetCustomer(cid):
    '''Perform Retrieve Customer in the vault
        Input:
            cid - customer id
        Output:
            nothing
        Raises:
            Exceptions raised by wpTransact()
    '''
    # 1. Fill in the Request Object - there transaction doesn't require a Request Object
    # 2. Send the transaction
    try:
        response = wpTransact("GetCustomer", "", 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 = "doGetCustomer failed. Result: " + str(rp.result) + " Response Code: " + str(rp.responseCode) + " Message: " + rp.message
        raise WpBadResponseError(errMsg)

    msg = "Get Customer transaction successful. CustomerId: " + str(rp.customerId) + " Name: " + rp.vaultCustomer.firstName + " " + rp.vaultCustomer.lastName
    print msg
    log.info(msg)

    return
def doGetTransaction(tid):
    '''Get a transaction based on transaction id
        Input:
            tid - transaction id
        Output:
            none
        Raises:
            Exceptions raised by wpTransact()
    '''

    # 1. Fill in the Request Object - none required for this operation
    # 2. Send the transaction
    try:
        response = wpTransact("GetTransaction", "", tid)
    except:  # pass the exception up. Nothing to do here at the moment
        raise

    # 3. Deserialize the result into a Response Object
    rp = TransactionReportingResponseParameters(response)
    log.info(">>>Response>>> \n%s", pformat(rp, indent=1))

    if (rp.responseCode != 1):  # response from Worldpay indicates failure
        errMsg = "GetTransaction failed. Result: , " + str(
            rp.result) + " Response Code: " + str(
                rp.responseCode) + " Message: " + rp.message
        raise WpBadResponseError(errMsg)

    cardNumber = rp.transactions[0].cardNumber
    cardType = rp.transactions[0].creditCardType
    amount = str(rp.transactions[0].transactionData.amount)
    msg = "Get Transaction successful. (" + cardType + " " + cardNumber + "  $" + amount + ")"
    print msg
    log.info(msg)

    return
Exemple #3
0
def doGetPaymentAccount(cid, pid):
    '''Perform Retrieve Payment Account from the vault
        Input:
            cid - customer id
            pid - payment id
        Output:
            nothing
        Raises:
            Exceptions raised by wpTransact()
    '''
    # 1. Fill in the Request Object - this transaction doesn't require a Request Object
    # 2. Send the transaction
    try:
        response = wpTransact("GetPaymentAccount", "", 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 = "doGetPaymentAccount failed. Result: " + str(rp.result) + " Response Code: " + str(rp.responseCode) + " Message: " + rp.message
        raise WpBadResponseError(errMsg)

    msg = "Get Payment Account transaction successful. CustomerId: " + str(rp.vaultPaymentMethod.customerId) + " Card: " + rp.vaultPaymentMethod.card.maskedNumber
    print msg
    log.info(msg)

    return
Exemple #4
0
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
Exemple #5
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
Exemple #6
0
def batchOperation(retrieve=False, bId=0):
    '''
    This function is the common logic for the three batch calls. No need to call this function directly
    Input: retrieve = True if this is a get operation
        bId = 0 if retrieveing current batch, otherwise it is the batch id
    Output:
        batchId = batchid returned
    Raises:
        WpBadResponse
        others raised from transact())
    '''
    # 1. Fill in the Request Object
    cb = BatchRequest()
    log.debug("batchOperation retrieve: %s, bid: %s Request: %s", retrieve,
              str(bId), pformat(cb.serialize(), indent=1))

    # Do the approporate transaction based on arguments
    if retrieve is False:  # close the currently open batch
        op = "CloseBatch"
    else:
        if bId:  # Retrieve a Closed Batch using its batch id
            op = "GetBatchById"
        else:  # get the currently open batch
            op = "GetBatch"

    # 2. Send the transaction on a serialized Request Object
    try:
        response = wpTransact(op, cb.serialize(), bId)
    except:
        raise  # pass upward

    # 3. Deserialize the result into a Response Object
    rp = BatchResponseParameters(response)

    if (rp.responseCode != 1):
        errMsg = op + " failed. Batch id: " + str(
            rp.batchId
        ) + "Result:  +  " + rp.result + " Response Code: " + str(
            rp.responseCode) + " Message: " + rp.message
        raise WpBadResponseError(errMsg)

    # Print out transactions in the batch specified
    msg = op + " transactions: {"
    for i in rp.transactions:
        msg += str(i.transactionId) + "  "
    msg += "}"
    print msg
    log.info(msg)

    msg = op + " transaction successful. BatchId: " + rp.batchId
    print msg
    log.info(msg)

    return rp.batchId
def doUpdateTransaction(tid):
    '''Update details on a previous transaction
        Input:
            tid - transaction id
        Output:
            none
        Raises:
            Exceptions raised by wpTransact()
    '''

    # 1. Fill in the Request Object
    # For this exercise we'll attach some level 2 data to the transaction
    '''
    l2 = LevelTwoData()
    now = datetime.datetime.now()
    l2.orderDate = now.strftime('%d/%b/%y')
    l2.purchaseOrder = "PO325425"
    l2.dutyAmount = 1.15
    l2.freightAmount = 2.30
    l2.retailLaneNumber = 69
    l2.taxAmount = 0.05
    l2.status = "EXEMPT"
    '''

    ut = UpdateTransactionRequest()
    ut.referenceTransactionId = tid
    ut.email = "*****@*****.**"
    ut.emailReceipt = True
    '''ut.attachLevelTwoData(l2)'''

    # 2. Send the transaction on a serialized Request Object
    try:
        response = wpTransact("UpdateTransaction", ut.serialize(), tid)
    except:  # pass the exception up. Nothing to do here at the moment
        raise

    # 3. Deserialize the result into a Response Object
    rp = TransactionReportingResponseParameters(response)
    log.info(">>>Response>>> \n%s", pformat(rp, indent=1))

    if (rp.responseCode != 1):  # response from Worldpay indicates failure
        errMsg = "UpdateTransaction failed. Result: , " + rp.result + " Response Code: " + str(
            rp.responseCode) + " Message: " + rp.message
        raise WpBadResponseError(errMsg)

    # return the transaction id and amount
    msg = "Update transaction successful. TransactionId = " + str(
        rp.transaction.transactionId) + " IP Address: " + str(rp.ipAddress)
    print msg
    log.info(msg)

    return
Exemple #8
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
def doSearchTransactions():
    '''Search a transaction based on supplied criteria
        Input:
            none
        Output:
            none
        Raises:
            Exceptions raised by wpTransact()
    '''

    # 1. Fill in the Request Object
    st = SearchTransactionsRequest()
    # Seach to last 30 days.
    stop = datetime.date.today()
    oneMonth = datetime.timedelta(days=30)
    start = stop - oneMonth

    st.startDate = str(start.month) + "/" + str(start.day) + "/" + str(
        start.year)
    st.endDate = str(stop.month) + "/" + str(stop.day) + "/" + str(stop.year)

    log.info("Seach range: %s - %s", st.startDate, st.endDate)

    # 2. Send the transaction on a serialized Request Object
    try:
        response = wpTransact("SearchTransactions", st.serialize())
    except:  # pass the exception up. Nothing to do here at the moment
        raise

    rp = TransactionReportingResponseParameters(response)
    log.info(">>>Response>>> \n%s", pformat(rp, indent=1))

    if (rp.responseCode != 1):  # response from Worldpay indicates failure
        errMsg = "SearchTransactions failed. Result: , " + rp.result + " Response Code: " + str(
            rp.responseCode) + " Message: " + rp.message
        raise WpBadResponseError(errMsg)

    # return the transaction id and amount
    msg = "Search tansactions successful."
    print msg
    log.info(msg)

    for record in rp.transactions:
        msg = "  (" + record.creditCardType + " " + record.cardNumber + "  $" + str(
            record.transactionData.amount)
        print msg
    return
Exemple #10
0
def chargeback(tId, refund=False):
    '''base function used by doRefund and doVoid.
        No need to call directly.
        Input:
            tId - transaction to be voided
            refund - True if refund, False if void
        Output:
            transaction code result
        Raises:
            Exceptions raised by wpTransact()
    '''

    # 1. Fill in the Request Object
    ar = AuthorizationRequest()
    ar.transactionId = tId

    if refund:
        op = "Refund"
    else:
        op = "Void"

    log.info("%s: %s", op, pformat(ar.serialize(), indent=1))

    # 2. Send the transaction on a serialized Request Object
    try:
        response = wpTransact(op, ar.serialize())
    except:  # pass the exception up. Nothing to do here at the moment
        raise

    log.info("%s Response: %s", op, pformat(response, indent=1))

    # 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 = op + " Transaction failed. Result: " + rp.result + " Response Code: " + str(
            rp.responseCode) + " Message: " + rp.message
        print errMsg
        log.info(errMsg)
        return rp.responseCode

    msg = op + " Transaction successful. TransactionId:" + str(
        rp.transaction.transactionId)
    print msg
    log.info(msg)
    return rp.responseCode
Exemple #11
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
Exemple #12
0
def doPriorAuthCapture(previousTransaction):
    '''Perform a Prior Auth Capture
        Input:
            tid - Requires a transaction id from previous auth
            amt - amount to capture (not to exceed original auth)
        Returns:
            transactionId that was captured
            amount that was authorized
        Raises:
            WpBadResponse
            WpFunctionCallError
            other WP exeptions raised from wpTransact()
    '''
    tid = previousTransaction[0]
    amt = previousTransaction[1]

    if tid == 0:  # invalid transaction id
        raise WpInvalidFunctionCallError("doPriorAuthCapture (" + str(tid) + ")")

    par = PriorAuthCaptureRequest()

    test.random()  # use this just to get a different amount each time
    par.transactionId = tid
    par.amount = amt

    # 2. Send the transaction on a serialized Request Object
    try:
        response = wpTransact("PriorAuthCapture", par.serialize())
    except:  # pass the exception up
        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):
        errMsg = "doPriorAuthCapture failed. TransactionId: " + str(par.transactionId) + " Result: " + str(rp.result) + " Response Code: " + str(rp.responseCode) + " Message: " + rp.message
        raise WpBadResponseError(errMsg)

    msg = "PriorAuthCapture transaction successful. TransactionId: " + str(rp.transaction.transactionId) + " (" + "$" + amt + ")"
    print msg
    log.info(msg)

    return [rp.transaction.transactionId, rp.transaction.authorizedAmount]
Exemple #13
0
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]
Exemple #14
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
Exemple #15
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
Exemple #16
0
def doGetPaymentPlan(cid, pid):
    ''' Retrieve an identified payment plan
        Input:
            cid - customer id (required)
            pid - plan id
        Output:
            planId - the id of the payment plan
        Raises:
            Exceptions raised by wpTransact()
    '''

    # 1. Fill in the Request Object
    var = GetPaymentPlanRequest()

    var.customerId = cid
    var.planId = pid

    # 2. Send the transaction on a serialized Request Object
    try:
        response = wpTransact("GetPaymentPlan", var.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 = GetPaymentPlanResponseParameters(response)
    log.info(">>>Response>>> \n%s", pformat(rp, indent=1))

    if (rp.responseCode != 1):
        errMsg = "doGetPaymentPlan failed. Result: " + str(
            rp.result) + " Response Code: " + str(
                rp.responseCode) + " Message: " + rp.message
        raise WpBadResponseError(errMsg)

    msg = "Get Payment Plan transaction successful. Type: " + rp.planType + " CustomerId: " + str(
        rp.customerId) + " PlanId: " + str(rp.planId)
    print msg
    log.info(msg)

    return rp.planId
Exemple #17
0
def doDeletePaymentAccount(cid, pid):
    '''Perform Delete Account from the vault
        Input:
            cid - customer id
            pid - payment id
        Output:
            nothing
        Raises:
            Exceptions raised by wpTransact()
    '''

    # 1. Fill in the Request Object
    # Doc error??
    # va = PaymentAccountRequest()  # we will resuse this object as we only need a subset
    # va.customerId = cid
    # va.paymentMethodId = pid

    # 2. Send the transaction on a serialized Request Object
    try:
        response = wpTransact("DeletePaymentAccount", "", 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 = "doDeletePaymentAccount failed. Result: " + str(rp.result) + " Response Code: " + str(rp.responseCode) + " Message: " + rp.message
        raise WpBadResponseError(errMsg)

    msg = "Delete Payment Account transaction successful. CustomerId: " + cid
    print msg
    log.info(msg)

    return
Exemple #18
0
def doUpdateVariablePaymentPlan(cid, pid):
    '''Perform Update ta Variable Payment Plan
        Input:
            cid - customer id
            pid - payment plan id
        Output:
            planId - the id of the payment plan
        Raises:
            Exceptions raised by wpTransact()
    '''

    # 1. Fill in the Request Object
    plan = VariablePaymentPlan()

    plan.planStartDate = " 12/01/2017"
    plan.maxRetries = 4
    plan.primaryPaymentMethodId = 1
    plan.active = True
    plan.notes = "More variable plan updates."

    sched = ScheduledPayment()
    sched.amount = 200.00
    sched.paid = False
    sched.paymentDate = '12/05/2017'

    # Attach a UDF - just because we can
    udf1 = UserDefinedField()
    udf2 = UserDefinedField()
    now = datetime.datetime.now()
    udf1.udfName = 'udf1'
    udf1.value = now.strftime('%d-%b-%y')
    udf2.udfName = 'udf2'
    udf2.value = now.strftime('%I:%M %p')
    plan.attachUserDefinedField(udf1)
    plan.attachUserDefinedField(udf2)
    plan.attachScheduledPayment(sched)

    var = VariablePaymentPlanRequest()

    var.customerId = cid
    var.planId = pid
    var.attachPlan(plan)

    # 2. Send the transaction on a serialized Request Object
    try:
        response = wpTransact("UpdateVariablePaymentPlan", var.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 = VariablePaymentPlanResponseParameters(response)
    log.info(">>>Response>>> \n%s", pformat(rp, indent=1))

    if (rp.responseCode != 1):
        errMsg = "doUpdateVariablePayment failed. Result: " + str(
            rp.result) + " Response Code: " + str(
                rp.responseCode) + " Message: " + rp.message
        raise WpBadResponseError(errMsg)

    msg = "Variable Payment Plan transaction successful. CustomerId: " + str(
        rp.customerId) + " PlanId: " + str(rp.planId)
    print msg
    log.info(msg)

    return rp.planId
Exemple #19
0
def doUpdateInstallmentPaymentPlan(cid, pid):
    '''Perform Updte Installment Payment Plan
        Input:
            cid - customer id (required)
            pid - only required if doing an update to an existing plan
        Output:
            planId - the id of the payment plan
        Raises:
            Exceptions raised by wpTransact()
    '''

    # 1. Fill in the Request Object
    plan = InstallmentPaymentPlan()
    plan.cycleType = 'monthly'
    plan.dayOfTheMonth = 1
    plan.dayOfTheWeek = 1
    plan.frequency = 1
    plan.numberOfPayments = 12
    plan.installmentAmount = 276.95
    plan.remainderAmount = 12.90

    plan.balloonPaymentAddedTo = 'FIRST'
    plan.remainderPaymentAddedTo = 'LAST'
    plan.startDate = '09/01/2017'
    plan.endDate = '10/01/2020'
    plan.maxRetries = 4
    plan.primaryPaymentMethodId = 1
    plan.notes = 'This is an installment plan'
    plan.active = True

    # Attach a user defined field
    udf1 = UserDefinedField()
    udf2 = UserDefinedField()
    now = datetime.datetime.now()
    udf1.udfName = 'udf1'
    udf1.value = now.strftime('%d-%b-%y')
    udf2.udfName = 'udf2'
    udf2.value = now.strftime('%I:%M %p')
    plan.attachUserDefinedField(udf1)
    plan.attachUserDefinedField(udf2)
    plan.numberOfPayments = 15

    ins = InstallmentPaymentPlanRequest()
    ins.customerId = cid
    plan.notes = "More installment plan updates"
    ins.planId = pid
    ins.attachPlan(plan)

    # 2. Send the transaction on a serialized Request Object
    try:
        response = wpTransact("UpdateInstallmentPaymentPlan", ins.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 = InstallmentPaymentPlanResponseParameters(response)
    log.info(">>>Response>>> \n%s", pformat(rp, indent=1))

    if (rp.responseCode != 1):
        errMsg = "doUpdateInstallmentPayment failed. Result: " + str(
            rp.result) + " Response Code: " + str(
                rp.responseCode) + " Message: " + rp.message
        raise WpBadResponseError(errMsg)

    msg = "Update Installment Payment Plan transaction successful. CustomerId: " + str(
        rp.customerId) + " PlanId: " + str(rp.planId)
    print msg
    log.info(msg)

    return rp.planId
Exemple #20
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]
Exemple #21
0
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
Exemple #22
0
def doUpdateRecurringPaymentPlan(cid, pid):
    '''Perform Update Recurring Payment
        Input:
            cid - customer id
            pid - paymnet plan id
        Output:
            planId - the id of the payment plan
        Raises:
            Exceptions raised by wpTransact()
    '''

    # 1. Fill in the Request Object
    plan = RecurringPaymentPlan()
    plan.cycleType = "monthly"
    plan.dayOfTheMonth = 1
    plan.dayOfTheWeek = 1
    plan.month = 6
    plan.frequency = 10
    plan.amount = 22.95
    plan.startDate = '10/1/2017'
    plan.endDate = '10/1/2035'
    plan.maxRetries = 4
    plan.primaryPaymentMethodId = 1
    plan.active = False

    plan.notes = "More recurring plan updates"

    # Let's attach a UDF for fun
    udf1 = UserDefinedField()
    udf2 = UserDefinedField()
    now = datetime.datetime.now()
    udf1.udfName = 'udf1'
    udf1.value = now.strftime('%d-%b-%y')
    udf2.udfName = 'udf2'
    udf2.value = now.strftime('%I:%M %p')
    plan.attachUserDefinedField(udf1)
    plan.attachUserDefinedField(udf2)

    rec = RecurringPaymentPlanRequest()
    rec.customerId = cid
    rec.planId = pid
    rec.attachPlan(plan)

    # 2. Send the transaction on a serialized Request Object
    try:
        response = wpTransact("UpdateRecurringPaymentPlan", rec.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 = RecurringPaymentPlanResponseParameters(response)
    log.info(">>>Response>>> \n%s", pformat(rp, indent=1))

    if (rp.responseCode != 1):
        errMsg = "doUpdateRecurringPayment failed. Result: " + str(
            rp.result) + " Response Code: " + str(
                rp.responseCode) + " Message: " + rp.message
        raise WpBadResponseError(errMsg)

    msg = "Update Recurring Payment Plan transaction successful. CustomerId: " + str(
        rp.customerId) + " PlanId: " + str(rp.planId)
    print msg
    log.info(msg)

    return rp.planId
Exemple #23
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
Exemple #24
0
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]