Automating Keygen / E-Mail Delivery
Jul 5th, 2007 by admin
Automating Keygen / E-Mail Delivery
Everybody hates a slow turn-around with key delivery. With traditional shareware online stores, the payment processor makes a call to the vendor’s keygen via CGI, and then sends the key to the end-user.
For some reason, TrialPay doesn’t like to do that. But they DO have a nice “notification” system, which contains all you need to send the key yourself. I just added some code to my existing PHP script, and had it working easily. To find from your TrialPay dashboard, go to Checkout, then Transaction Notifications, and turn on “Payment Confirmation - Send me a payment confirmation after each transaction”.
Working with the URL:
First, you have to understand their URL structure. That’s what took most of my time - I was over-analyzing things, assuming that I had to stuff their codes into the URL. Not so. They send everything, PLUS whatever you specify. There is no need, for example, to code the e-mail into the URL. They’ll send it. You just need to pick it up.
Here’s a sample URL:
http://www.yoursite.com/your-secret-keygen-dir/your-keygen.php
Notice that some important things, such as email, fname, lname, are missing. That’s my point - TrialPay sends them anyway! I think they tack all of their variables (%revenue%, %pid%, %oid%, %email%, %lname%, %fname%, etc., ) onto your URL. Actually, I’m sure of it, as I log the $QUERY_STRING, and this is what typically appears:
&event_type=Order&oid=ZJMG3ZA×tamp=07%2F03%2F2007+20%3A33%3A48
&hash=80611bd2ab2c8ca10ded3e4e0d8c9e1f&revenue=25.00&tid=
&offer_category=Online+Services&order_date=07%2F03%2F2007
&fname=Joe&lname=User&email=Joe.User@gmail.com
&sid=&country=US&pid=CM70&activation_key=NA
Ok, suppose you DO need to add some things, such as userid/password? Just add them to the URL, and it’ll work just fine. In my situation, I actually use the same keygen for several payment services, so I have a vendorid and password on the URL. So my real URL looks more like this:
http://www.yoursite.com/your-secret-keygen-dir/your-keygen.php?Vendorid=TRIALPAY&pwd=SECRETPASSWORD
Suppose the names of their variables don’t agree with what you already use? No problem, just assign inside. Here’s how I cope with such things:
if (($vendorid== 'TRIALPAY') and ($pwd == "PAYTOPLAY") and ($event_type="Order")) {
$productcode = $pid;
$ordernum = $oid;
$regname = trim("$fname $lname","x22 ");
$qty = "1"; // they can only order 1
}
There! Now the order is “normalized”.
Now, about the e-mail…..
$emailstatus = 0; /* no attempt */
if ($email != "") {
$emailstatus = 1; /* attempt */
$to = $email;
$subject = "My Program Registration Key - ID: $ordernum";
$headers = "Return-Path: sales@mycompany.com\r\nFrom: sales@mycompany.com\n" .
"X-Mailer: php";
/* canned text, with ##REGNAME## and ##KEY## tags */
$EmailBodyFile = "email_body.txt";
$fh = fopen($EmailBodyFile, 'r');
$body = fread($fh, filesize($EmailBodyFile));
fclose($fh);
$body = str_replace("##REGNAME##", $regname, $body);
$body = str_replace("##KEY##", $code, $body);
if (mail($to, $subject, $body, $headers)) {
$emailstatus = 2; /* Success */
} else {
$emailstatus = 99; /* Error */
}
}
I log the emailstatus in my regular log (a MySQL database, outside the scope of this discussion) so I can see if it worked. It always does.You can send some test notifications from the TrialPay page where you edit the checkout information, and it should send the e-mail. Direct it to yourself, for testing obviously.


hello,
i was just getting started with plimus. Your article was of greate help. I havent created my first keygen yet…but i hope that i will complete it soon
Your blog some nice, targeted content for shareware authors
$fh = fopen($EmailBodyFile, ‘r’);
$body = fread($fh, filesize($EmailBodyFile));
fclose($fh);
$body = str_replace(”##REGNAME##”, $regname, $body);
$body = str_replace(”##KEY##”, $code, $body);
if (mail($to, $subject, $body, $headers)) {
$emailstatus = 2; /* Success */
} else {
$emailstatus = 99; /* Error