Launching New Transactions from Web Pals
From ContractPal
This is an application note on using ContractPal to achieve certain things. It is not intended to be a comprehensive solution.
This application note shows how to launch a new transaction from a Web Pal. Web Pals provide the ability to create marketing sites to increase sales capture rates. Web Pals also help providing familiarity for users. Users can come to sites specific to certain types of business. These sites can act as front ends for ContractPal transactions.
Let's get started. To provide a transition from a Web pal to a ContractPal transaction your Pal will need to determine if a particular user has a ContractPal account. Then, if the user doesn't have a ContractPal account, you'll need to create one and then launch the user into a transaction. If a user already has an account, you will need to permit the user to log into ContractPal in order to authenticate you transaction properly. In either case, a security key or captcha will be required in order to protect your Pal from abuse.
In our example, our Pal will consist if a simple HTML page a simple Web work flow file. Our page, ("w1") will look like the following:
And the HTML markup for our w1 page will look like:
<html xmlns:c="contractpal">
<head>
<title>Create New Transaction</title>
<style>
body {
font-family: arial, helvetica, sans-serif;
font-size: .8em;
}
</style>
</head>
<body>
<div id="cp-root">
<div style="text-align:center">
<div style="width:450px;border:1px solid #ccc;margin:100px auto;padding:15px">
<form name="login" action="loginSubmitted">
<p style="font-size:1.5em; color #333;">Please enter your information.</p>
<c:if test="${showMessage=='true'}"><p style="color:red">${messageText}</p></c:if>
<table border="0" width="400px" style="font=size:.8em;" cellpadding="1">
<tr>
<td align="right">First Name:</td>
<td align="left"><input name="firstName" size="35" type="text"/></td>
</tr>
<tr>
<td align="right">Last Name:</td>
<td align="left"><input name="lastName" size="35" type="text"/></td>
</tr>
<tr>
<td align="right">Email Address:</td>
<td align="left"><input name="emailAddress" size="35" type="text"/></td>
</tr>
<tr>
<td align="right"> </td>
<td align="left"><c:captcha/></td>
</tr>
<tr>
<td align="right">Security Key:</td>
<td align="left"><input name="captcha" size="35" type="text"/></td>
</tr>
</table>
<div style="margin-top:25px">
<input type="submit" value="Launch New Transaction"/>
</div>
</form>
</div>
<div style="text-align:left"><c:debug/></div>
</div>
</div>
</body>
</html>
Notice the form action submit page. It is "loginSubmitted". We will key off of this action in our work flow. Here is our workflow:
var c;
var page;
var href;
var request;
var firstName;
var lastName;
var emailAddress;
var captcha;
function run(controller)
{
c = controller;
page = c.getPage("w1");
'''href = c.getHref();
request = c.getRequest();'''
firstName = request.getValue("firstName");
lastName = request.getValue("lastName");
emailAddress = request.getValue("emailAddress");
'''captcha = request.getValue("captcha");'''
switch (href)
{
'''case "loginSubmitted":'''
if (!c.checkCaptcha(captcha)){
page.setValue("showMessage","true");
page.setValue("messageText","Captcha was incorrect. Please try again.")
break;
}
else {
if (!c.isRegistered(request.getValue("emailAddress"))){
c.register(firstName,lastName,emailAddress,captcha);
return c.createNewTransaction(emailAddress,"PAL-QA-1186110D87D-237EDBE4",page.getData());
}
else {
return c.createNewTransaction("PAL-QA-1186110D87D-237EDBE4",page.getData());
}
}
default:
break;
}
return page;
}
Take a look at the code that bears a bold typeface.
The first thing to notice is: href = c.getHref(); c.getHref() returns the page requested by the client. In our case, when someone submits the login form, the page requested will be "loginSubmitted". We will want to key off of this in order to determine if our user already has an account, and if they have entered the security key or captcha correctly.
The second thing to notice is: request = c.getRequest();. c.getRequest() allows us to capture the data contained in the form in our work flow.
The final thing to notice is the case statement for "loginSubmitted". First, we check to determine if the user entered the security key correctly. If the user did not, we will redisplay the page and add a message at the top indicating the security key is wrong. This is simple means of validating the security key. Of course, you could use other methods to validate data, including client-side JavaScript.
If the security key is correct, we next determine if the user already has a ContractPal account. If the user does not, we request that an account be created and then immediately launch a transaction. If a user does not already have an account, the user can immediately launch the transaction without going through some addition form of validation. While a user can immediately execute a transaction, a validation email will be sent by the ContractPal system to the email account of the user. The email will request that the user validate the email account and thus the user's authenticity for the transaction.
If the user already has an account, a new transaction can still be launched but the user will be required to log into ContractPal as part of the launching process.
We hope this application note has been helpful.
The ContractPal Team.
