<%@ LANGUAGE=jscript %> Purchase: <% var purchaseObj = Server.CreateObject("Worldpay.COMpurchase"); ///////////////////////////////////////////////////////////////////// // Normal purchase stuff // Our vars var instId; var cartId; var shopperId; var cost; var currency; var desc; var testMode; var authMode; var purchaseURL; // Contact details var name; var address; var postcode; var countryISO; var email; var telephone; var fax; // Futurepay common var useFuturePay; var startDate; var startDelayUnit; var startDelayMult; var intervalUnit; var intervalMult; var noOfPayments; var option; // Regular futurepay var initialAmount; var normalAmount; // Limited futurepay var amountLimit; var endDate; var lengthUnit; var lengthMult; // Do we have a form in the request? if (Request.Form("containsForm").Count != 1) { // Setup defaults testMode = "30"; authMode = "A"; purchaseURL = "http://dev-wcc.select.worldpay.com/wcc/purchase"; } else { // Normal purchase instId = getParamOrEmpty("instId"); cartId = getParamOrEmpty("cartId"); shopperId = getParamOrEmpty("shopperId"); cost = getParamOrEmpty("cost"); currency = getParamOrEmpty("currency"); desc = getParamOrEmpty("desc"); testMode = getParamOrEmpty("testMode"); authMode = getParamOrEmpty("authMode"); purchaseURL = getParamOrEmpty("purchaseURL"); // Contact details name = getParamOrEmpty("name"); address = getParamOrEmpty("address"); postcode = getParamOrEmpty("postcode"); countryISO = getParamOrEmpty("country"); email = getParamOrEmpty("email"); telephone = getParamOrEmpty("tel"); fax = getParamOrEmpty("fax"); // Futurepay useFuturePay = 0; if (getParamOrEmpty("regularFuturePay") == "on") useFuturePay=1; if (getParamOrEmpty("limitedFuturePay") == "on") useFuturePay+=2; // Can't specifiy both checkbox's // if (useFuturePay==3) // { // Response.Write("Cannot specify both!"); // } // Get the parameters if (useFuturePay > 0) { // Common stuff startDate = getParamOrEmpty("startDate"); startDelayUnit = getParamOrEmpty("startDelayUnit"); startDelayMult = getParamOrEmpty("startDelayMult"); intervalUnit = getParamOrEmpty("intervalUnit"); intervalMult = getParamOrEmpty("intervalMult"); noOfPayments = getParamOrEmpty("noOfPayments"); option = getParamOrEmpty("option"); // Regular if (useFuturePay == 1) { initialAmount = getParamOrEmpty("initialAmount"); normalAmount = getParamOrEmpty("normalAmount"); } // Limited if (useFuturePay == 2) { amountLimit = getParamOrEmpty("amountLimit"); endDate = getParamOrEmpty("endDate"); lengthUnit = getParamOrEmpty("lengthUnit"); lengthMult = getParamOrEmpty("lengthMult"); } } // Setup the standard purchase token purchaseObj.init(purchaseURL); purchaseObj.setInstallationId(getIntOrNeg(instId)); purchaseObj.setCartId(cartId); purchaseObj.setShopperId(shopperId); purchaseObj.setCurrencyISOCode(currency); purchaseObj.setAmount(getFloatOrZero(cost)); purchaseObj.setAuthMode(authMode); purchaseObj.setTestMode(testMode); purchaseObj.setDescription(desc); // And the contact details purchaseObj.setName(name); purchaseObj.setAddress(address); purchaseObj.setPostalCode(postcode); purchaseObj.setCountryISOCode(countryISO); purchaseObj.setEmail(email); purchaseObj.setTelephone(telephone); purchaseObj.setFax(fax); // Futurepay var futurePay = null; if (useFuturePay == 1) { futurePay = purchaseObj.useRegularFuturePay(); if (initialAmount.length > 0) futurePay.setInitialAmount(getFloatOrZero(initialAmount)); if (normalAmount.length > 0) futurePay.setNormalAmount(getFloatOrZero(normalAmount)); } if (useFuturePay == 2) { futurePay = purchaseObj.useLimitedFuturePay(); if (amountLimit.length > 0) futurePay.setAmountLimit(getFloatOrZero(amountLimit)); if (endDate.length > 0) futurePay.setEndDate(endDate); if (lengthUnit.length > 0 || lengthMult.lenght > 0) futurePay.setAgreementLength(getIntOrNeg(lengthUnit), getIntOrNeg(lengthMult)); } // Common futurepay if (futurePay != null) { if (startDate.length > 0) futurePay.setStartDate(startDate); if (startDelayUnit.length > 0 || startDelayMult.length > 0) futurePay.setStartDelay(getIntOrNeg(startDelayUnit), getIntOrNeg(startDelayMult)); if (noOfPayments.length > 0) futurePay.setNumPayments(getIntOrNeg(noOfPayments)); if (intervalUnit.length > 0 || intervalMult.length > 0) futurePay.setPaymentInterval(getIntOrNeg(intervalUnit), getIntOrNeg(intervalMult)); if (option.length > 0) futurePay.setOption(getIntOrNeg(option)); } // Ok process it purchaseObj.process(); // Check for errors if (purchaseObj.hadError()) { // Had errors Response.Write("

Errors occured during purchase token creatation:

"); Response.Write(""); } else { // Didn't have errors Response.Write("
Description:" + desc); Response.Write("
Transaction Cost:" + currency + cost); Response.Write("
Test mode:" + testMode); Response.Write("
Auth mode:" + authMode); Response.Write("
"); // And the link Response.Write("

Pay for this at WorldPay

"); } Response.Write("
"); } // Get a parameter from request or empty if it does not exist function getParamOrEmpty(paramName) { var tmp = ""; if (Request.Form(paramName).Count != 0) tmp = new String(Request.Form(paramName)); return tmp; } // Gets the int or return -1 if string is empty function getIntOrNeg(param) { var tmp = -1; if (param.length!=0) tmp = parseInt(param); return tmp; } function getFloatOrZero(param) { var tmp = 0; if (param.length!=0) { tmp = parseFloat(param); if (tmp == NaN) tmp = 0; } return tmp; } // End of normal purchase stuff ///////////////////////////////////////////////////////////////////// %>

Compulsory fields are marked with *

Transaction Details

Installation ID*
Cart ID*
Shopper ID*
Cost* (not compulsory if FuturePay present)
Currency (ISO code)*
Description
Test mode
Auth mode (defaults to full auth 'A')
Purchase URL

FuturePay Agreement Common Details

Start date yyyy-mm-dd
Start delay unit Units: 1-day, 2-week, 3-month, 4-year
Start delay multiplier
Interval unit (* if Regular and No. != 1) Units: 1-day, 2-week, 3-month, 4-year
Interval multiplier (* if Regular and No. != 1)
Number of payments (acts as limit on Limited type)
Option*
Regular options: 0-amount is fixed, 1-amount adjusted occasionally, 2-amount set for each payment
Limited options: 0-amount limit is per payment, 1-no of payments limited to interval, 2-amount limit is per agreement, 3-amount limit is per interval
Regular FuturePay Specific Details

Token to contain Regular FuturePay Agreement>
Initial amount (will default to normal amount)
Normal amount (* with option 0,1)

Limited FuturePay Specific Details

Token to contain Limited FuturePay Agreement>
Amount limit
End date yyyy-mm-dd
Agreement length unit Units: 1-day, 2-week, 3-month, 4-year
Agreement length multiplier

You can fill in some of these contact details, if you like - they should then be reflected in the first new contact details form you see on the wcc.
Name
Address
Postcode
Country (ISO Code)
Email
Telephone
Fax