Forum Moderators: coopster & phranque

Message Too Old, No Replies

Basic Worldpay Script

Basic Worldpay Script

         

easymedia

9:28 am on Mar 5, 2004 (gmt 0)

10+ Year Member



Hi,

I'm looking for a very simple form processor that will send a transaction to worldpay.

I'd like to produce a payment link something like this...

[mydomain.com...]

This would then either send the user to a form for their details which would be passed to worldpay - or even just send the product and price to worldpay and the customer could fill in their details at the worldpay page.

It would need to contain all the standard variables such as currency code etc.

I'm sure there are simple scripts like this floating about but I've looked at all the script sites and the ones I have seen are all too complicated or full cart systems which I dont want.

Any help would be greatly appreciated.

PCInk

9:57 am on Mar 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The help files on the WorldPay site show the parameters you need to send them for the customer to do the transaction on the WorldPay page.

easymedia

10:04 am on Mar 5, 2004 (gmt 0)

10+ Year Member



Thanks for your reply but...

As mentioned, I'm looking for a script that will process the transaction via a hyperlink.

This way I can send customers a link via email - clicking it will send them to a payment form.

roitracker

12:35 pm on Mar 5, 2004 (gmt 0)

10+ Year Member



You won't be able to link directly into WorldPay in this way.

However, you could send a link that will prepopulate a form on your site (which can include hidden variables) & then have a button that submits the form to WorldPay.

Alternatively, you could embed the order form into an HTML email & do it that way, but it won't be 100% reliable.

easymedia

1:07 pm on Mar 5, 2004 (gmt 0)

10+ Year Member



Please read the original post carefully.

As you can see in my example, the link goes to the script - not directly to worldpay.

I'm grateful for any help but if you dont really know about this stuff, please dont post a reply.

The script should contain the fields neccessary to send on the payment to worldpay - many of them, like currency code and installation ID will be already contained in the script. The variables needed are obviousley the product description and price - plus any customer details.

So the link basically "tells" the script to add this info to into the appropriate fields.

There now leaves 2 options, either send this info directly to the payment page at worldpay and have the user input their personal details - or provide a seperate form in order to take this info before the script sends on all the data to worldpay via submit button.

Its very simple and I'm sure there are many scripts out there like this - I would like someone to please recommend one - or show how it can be done.

SeanW

1:49 pm on Mar 5, 2004 (gmt 0)

10+ Year Member



Not sure of the interface to Worldpay, ie is it HTTP/HTTPS? If so, you could use WWW::Mechanize or LWP depending on how complex/simple the interaction is, and make the request from your CGI.

Sean

lexipixel

7:30 am on Mar 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If I understand your question, you want to send a hyperlink embedded in an email, ie-

<A HREF="?">Click Here to Pay Me Now</A>

Just about anything that can be sent via HTML FORM can be sent via HREF tag.

Example-


<FORM ACTION="/cgi-bin/script.pl" METHOD=POST>
<INPUT TYPE=HIDDEN NAME=var1 VALUE="abc123">
<INPUT TYPE=HIDDEN NAME=var2 VALUE="$100.00">
<INPUT TYPE=HIDDEN NAME=var3 VALUE="John Q. Public">
<INPUT TYPE=SUBMIT VALUE="PAY NOW">
</FORM>

To send the contents of this pre-populated form via email you would change-

<A HREF="?">Click Here to Pay Me Now</A>

to-

<A HREF="http://www.somesite.xyz/cgi-bin/script.pl?var1=abc123&var2=$100.00&var3=John Q. Public">Click Here to Pay Me Now</A>

The reason I italicized "just about" (above)is that some characters need to be encoded, (ie- ampersand and equal for obvious resons and spaces and possibly others depending on your application). It's pretty straightforward to encode them though.

If this was not what you were looking for, maybe it will help someone else --- and if not, maybe you can restate the problem your having.

easymedia

8:47 am on Mar 6, 2004 (gmt 0)

10+ Year Member


That is pretty much what I'm looking for yes. If I had elaborated more on my description it would have been similar to lexipixels reply.

What I'm looking for is a perl script that will contain the form and send it on to worldpay - after populating the form fields from the URL and additional customer info from an input form.

It would be very useful as it would be easy to email a payment link - or just add individual payment buttons to a page - i.e "click here to purchase this item" - or "click here to pay a one off fee of 9.99"

Its specifically for simple payments where there is no need for a shopping cart.

Perhaps what I'm asking is too simple. Having no experience of perl scripting I wouldnt know how to make the script pass the details to worldpay, either automatically - or via a button.

I could easily build the form - it would be as follows...

Obviousley many of these would not be hidden if they were to be entered by the user. This is just an example.

<form action=https://select.worldpay.com/wcc/purchase method=POST>
<input type=hidden name="instId" value="MY INST ID">
<input type=hidden name="cartId" value="Purchase from MY SITE">
<input type=hidden name="currency" value="GBP">
<input type=hidden name="desc" value="POPULATED">
<input type=hidden name="amount" value="POPULATED">
<input type=hidden name="name" value="POPULATED">
<input type=hidden name="email" value="POPULATED">
<input type=hidden name="tel" value="POPULATED">
<input type=hidden name="address" value="POPULATED">
<input type=hidden name="postcode" value="POPULATED">
<input type="image" value="pay" name="buy" src="images/logo_worldpay.gif">
</form>

The process would be as follows....

1. User clicks payment link
2. They are presented with a form to enter the remaining details - the price and product description will already have populated the form from the URL and must not be editable.
3. They enter their details and click submit - this takes them and the data to worldpay.

The problem is that I have no idea how to make the script populate the form with either the "fixed" variables from the URL or the customer details from the form. As mentioned, I dont know Perl.

lexipixel

1:25 pm on Mar 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The steps are as follows-

===> 1). Potential client's email address is known.

===> 2). Potential client is sent an email with a link embedded in it, ie-

<A HREF="?">Click Here to Buy Now</A>

The link is encoded with pre-populated data for the known variables-

<A HREF="http://www.FOOSALES.xyz/cgi-bin/order.pl?customer=Name_Here&item=Num_Here&price=Price_Here">Click Here to Buy Now</A>

===> 3). a Perl script in the /cgi-bin/ directory of the www.FOOSALES.xyz website named "order.pl" is executed when the user clicks the link (which was delivered by email and partially contains the data for an order).

This perl script contains code something like the following, (note this is NOT a fully functional script, just a framework and comments you could use
to create a complete functional script).

#!/usr/local/bin/perl
#
# Parse url for CGI pairs of parameters and values
#
if ($ENV{'QUERY_STRING'}) {
$buffer = $ENV{'QUERY_STRING'};
} elsif ($ENV{'CONTENT_LENGTH'}) {
read (STDIN,$buffer,$ENV{'CONTENT_LENGTH'});
}
#
@cgiPairs = split(/&/,$buffer);
foreach $cgiPair (@cgiPairs) { ($name,$value) = split(/=/,$cgiPair);
$value =~ s/\+/ /g;
$value =~ s/%(..)/pack("c",hex($1))/ge;
if ($name eq "customer") {$cust = ("$value");}
elsif ($name eq "item") {$item = ("$value");}
elsif ($name eq "price") {$price = ("$value");}
elsif ($name eq "addr1") {$addr1 = ("$value");}
elsif ($name eq "addr2") {$addr2 = ("$value");}
elsif ($name eq "city") {$city = ("$value");}
elsif ($name eq "state") {$state = ("$value");}
elsif ($name eq "zip") {$zip = ("$value");}
#
}

#
#
# check values for $cust, $item and $price
# make sure this is not an order someone has
# faked.. it would be easy for someone to
# change the price of the item and you may
# be tricked into selling it for that price
# a simple check of item number against
# price...
#
$found = "N";
open (DAT,"inventory.db");
seek (DAT,0,0);
while ($rec = <DAT>) {
@rec = split (/\¦/,$rec);
#
# this assumes a pipe delimited text database
# split out item number and price
#
if ($rec[?] = $foovar) {
# set $found = "Y";
# see if item number and price and match
# set $match_ok = "Y" or "N"
}
}
close (DAT);
#
#
# display warning or take other action if
# if item not found, ($found="N") or if
# price doesn't match, ($match_ok = "N")
#
# Next see if you have the address, city,
# state, etc for shipping..
#
if (($addr1 eq "") ¦¦ ($addr2 eq "") ¦¦ ($city eq "") ¦¦ ($state eq "") ¦¦ ($zip eq "")) {
#
# display HTML form again, data is missing
#
&DisplayForm;
#
}

#
# ok, it's made it past here, all data is
# known, now display a "Complete Order" button
# or link which is a pre-populated and takes
# the user to "Checkout".
#

exit;

#
#
# done. One sub listed below

#==================
sub DisplayForm {
#==================
# this is an HTML form embedded in a CGI
# scripts, it could also be stored in an
# external HTML file and displayed by the
# script.
#
# first lets display the customer name
# item and price as a prompt.
#
print "$cust, please complete form to order $item (price: $price).<BR>\n";
#
# then the form would look something like-
#
print "<FORM ACTION=\"http://www.FOOSALES.xyz/cgi-bin/order.pl\" METHOD=\"POST\">\n";
print "<INPUT TYPE=hidden NAME=customer value=\"$cust\">\n";
print "<INPUT TYPE=hidden NAME=item value=\"$item\">\n";
print "<INPUT TYPE=hidden NAME=price value=\"$price\">\n";
print "Address 1: <INPUT TYPE=text NAME=addr1 SIZE=40 value=\"$addr1\"><BR>\n";
print "Address 2:<INPUT TYPE=text NAME=addr2 SIZE=40 value=\"$addr2\"><BR>\n";
print "City or Town:<INPUT TYPE=text NAME=city SIZE=40 value=\"$city\"><BR>\n";
print "State: <INPUT TYPE=text NAME=state SIZE=2 value=\"$state\"><BR>\n";
print "Zipcode: <INPUT TYPE=text NAME=zip SIZE=5 value=\"$zip\"><BR>\n";
print "<INPUT TYPE=submit VALUE=\"Order Now\">\n";
print "</FORM>\n";
#
}

#========================================
# end of code.
#========================================

The idea is the script calls itself and displays a form until it has all the data, then leads the user to the payment processing site with all data pre-populated.

easymedia

2:05 pm on Mar 8, 2004 (gmt 0)

10+ Year Member



That's exactly what I'm looking for.

Many Thanks!

lexipixel

3:46 am on Mar 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




No problem, glad to help. I snipped most of it from a perl script I wrote for an online store / shopping cart that passes order and payment info to PayPal. ...same thing, different flavor.