A commonly requested feature for the OpenSRS client code is a way to
generate price information for the customer at the time of an order. I
implemented a method by Michael Brody and John Burgess
(http://www.opensrs.org/archives/discuss-list/0004/0470.html and
http://www.opensrs.org/archives/discuss-list/0004/0527.html ) on the
previous code, and it worked very well.
With the release of the new version of the client code, it became necessary
to update some of the routines we had been using to generate the total
price, as we wished to have different prices for different TLDs. This is a
method based on Burgess' and Brody's techniques, which will allow you to set
different prices for the three current TLDs offered through OpenSRS. It
should be fairly straightforward to implement new TLDs through this routine.
If any master Perl programmers can suggest improvements, they would surely
be welcome!
OK, here we go:
1) In reg_system.cgi, look for the lines in the verify_order subroutine that
look like this:
my ($key,$cleaned_value,$error_msg,$domain_string,$domain,@domains);
my
(%good_domains,%bad_domains,%domains,$type,$field,$num,$fqdn,$nameservers);
my ($formCountry);
and change it to this:
my ($key,$cleaned_value,$error_msg,$domain_string,$domain,@domains);
my
(%good_domains,%bad_domains,%domains,$type,$field,$num,$fqdn,$nameservers);
my ($domain_count,$mytimeperiod,$mytotal_price,$PRICE_YEAR);
my ($formCountry);
2) Later in the same routine, you will see a loop that starts like this:
$error_msg = "";
foreach $domain (@domains) {
Change it to this:
$error_msg = "";
$domain_count = 0;
foreach $domain (@domains) {
That will start the loop that counts how many domains your customer is
ordering. At the end of that loop, you will see this:
foreach $domain (keys %good_domains) {
$domain_string .= "<input type=hidden name=domain value=\"$domain\">\n";
}
Change it to this:
foreach $domain (keys %good_domains) {
$domain_string .= "<input type=hidden name=domain value=\"$domain\">\n";
$domain_count++;
}
Now we will know the total number of domains ordered by accessing the
variable $domain_count.
3) Now for the big chunk, the part that I am to blame for. ;-) Find the
lines that look like this:
$HTML{reg_type} = $in{reg_type};
if ($in{reg_type} eq 'new') {
We're going to insert some code in between these two lines. Here it is:
#
#
# John Keegan
# john@rackshare.com
# 9/25/00
# rackshare.com
#
# pricing loop start
#
# test for Canadian ccTLD
if ( $in{domain} && $in{domain} =~ /\.ca/i ) {
# domain name is Canadian ccTLD
$PRICE_YEAR = '21.00';
$mytimeperiod = $REG_PERIODS{$in{period}};
$mytimeperiod =~ s/\W.*//;
$mytotal_price = ($PRICE_YEAR * $mytimeperiod * $domain_count);
$HTML{hosting} = $in{hosting};
$HTML{total_price} = $mytotal_price;
}
# test for UK ccTLD
else {
if ( $in{domain} && $in{domain} =~ /\.uk/i ) {
# domain name is United Kingdom ccTLD
$PRICE_YEAR = '7.50';
$mytimeperiod = $REG_PERIODS{$in{period}};
$mytimeperiod =~ s/\W.*//;
$mytotal_price = ($PRICE_YEAR * $mytimeperiod * $domain_count);
$HTML{hosting} = $in{hosting};
$HTML{total_price} = $mytotal_price;
}
# nothing found, must be gTLD
else {
# This must be a .com, .net or .org Domain Name
$PRICE_YEAR = '11.00';
$mytimeperiod = $REG_PERIODS{$in{period}};
$mytimeperiod =~ s/\W.*//;
$mytotal_price = ($PRICE_YEAR * $mytimeperiod * $domain_count);
$HTML{hosting} = $in{hosting};
$HTML{total_price} = $mytotal_price;
}
}
# pricing loop end
#
#
This loop will check the domain and see if it is a .CA domain, and if so,
set the price per year to $21, and return a total price based on the number
of domains and the length of the registration. If it is not a .CA domain, it
will look to see if it is a .UK domain, and do the calculation. If we still
don't match, we assume it's a gTLD... Make sure to change the $PRICE_YEAR
variable to reflect your own price structure. ;-)
4) In your verify.html and verify_ca.html templates, make sure you add the
new field total_price, maybe like this:
<tr>
<td align=right><b>Total Price:</b></td>
<td>US${{total_price}}</td>
</tr>
5) If you've done everything correctly, and I haven't led you astray, you
should now be able to set separate prices for TLDs and have them calculated
and shown to your customer at the time of an order.
Some notes - This modification does not require any changes to your
OpenSRS.conf . The original code did, which is why you see the $PRICE_YEAR
variable left in the code above, which could probably just be eliminated
like so:
$mytimeperiod = $REG_PERIODS{$in{period}};
$mytimeperiod =~ s/\W.*//;
$mytotal_price = (11 * $mytimeperiod * $domain_count);
$HTML{hosting} = $in{hosting};
$HTML{total_price} = $mytotal_price;
It would probably be better to use the OpenSRS.conf file to store your
$PRICE_YEAR information, and implement the loop using a different variable
for each TLD's price, like $ca_price_year or something. Then you could
change pricing without having to update your reg_system.cgi script, just
drop in the new .conf file and there you go.
There are a lot of ways this hack could be improved, especially since we can
see in the OpenSRS code that we can find the country code extension fairly
easily. Look for the $domainCountry variable in the new code and see how I
could have used this to determine the TLD (if $domainCountry = "", it's a
gTLD, else...).
Hope this helps someone out, and I will look forward to hearing how this
modification could be improved!
-- John Keegan john@RackShare.com http://RackShare.com
This archive was generated by hypermail 2.1.3 : Tue Oct 19 2004 - 23:35:58 EDT