Posts Tagged ‘automatic price change’

Auto Update Your Payment Button

Friday, September 25th, 2009

Have you ever wondered how to change your Payment Button prices automatically? Or maybe you have done this with javascript and weren’t happy with the results…

This is where PhP comes in as a server side script. Your users can’t block it as with JavaScript. Let me show you a simple way to automatically change your prices on your payment button. The below was done with PayPal although other payment processors should work the same.

The first 5 lines are to create the dates you will need. <?php can be abreviated as <? if you wish. This simply tells the browser that it will be handled by the server.  Next come the variables which we will use. $tm is todays month, $td represents todays day, and $ty as you have guessed is the year. To use this information we concact it or “join” it all together for logical use. So, $now = mktime($tm, $td, $ty); creates a usable time stamp for php to compare with older or newer dates. mktime() is the number of seconds since the Epoch. No it’s not the “Silurean Epoch” spoken of by “Rick Wakeman” in “Journey To The Center Of The Earth”! No, no, this is the UNIX Epoch which began at midnight GMT
 January 1, 1970. I know this is probably more information than you needed, but it’s important to know how this script works!

Now that you are aware, $now stands for the time in seconds the page was  visited. The next line, $edate, is the date to change pricing. In the example below we used 9,25,2009 or September 25, 2009 in seconds which makes it easy to compare them. Next is where you payment code goes. This line, if ($now <= $edate){ simply checks to see if the date the page is visited is less than the date the payment changes. In most cases the price will increase after the $edate.

What you need to do is go to your payment processor, in this case it is PayPal, and create 2 buttons. One for the first or lesser price and the second for the higher price. Simply copy and paste your code from <form to </form> into the script. Leave the quotes ” in place. The script will not work without them. Do the same for the next form with the increased price. That’s all there is to it. The last thing is to make sure you save your page as yourpagename.php. It MUST have the .php extension in order to work. If your site does not have php enabled, don’t waster your time although most host do have php installed…

Finally, within your body paste this line where you want the payment button to appear: <? echo $pbutton; ?>

<?php
$tm = date(“m”);
$td = date(“d”);
$ty = date(“Y”);
$now = mktime($tm, $td, $ty);
$edate = mktime(9, 25, 2009);//Time for Month Day Year
if ($now <= $edate){
  $pbutton = ”
  <form action=\”https://www.paypal.com/cgi-bin/webscr\” method=\”post\”>
  <input type=\”hidden\” name=\”cmd\” value=\”_s-xclick\”>
  <input type=\”hidden\” name=\”hosted_button_id\” value=\”XXXXXXX\”>
  <input type=\”image\” src=\”http://YourButtonImageUrlHere\” border=\”0\” name=\”submit\” alt=\”PriceHere PayPal – The safer, easier way to pay online!\”>
  <img alt=\”\” border=\”0\” src=\”https://www.paypal.com/en_US/i/scr/pixel.gif\” width=\”1\” height=\”1\”>
  </form>”;
  }else{
  $pbutton = ”
  <form action=\”https://www.paypal.com/cgi-bin/webscr\” method=\”post\”>
  <input type=\”hidden\” name=\”cmd\” value=\”_s-xclick\”>
  <input type=\”hidden\” name=\”hosted_button_id\” value=\”XXXXXXX\”>
  <input type=\”image\” src=\”http://YourButtonImageUrlHere\” border=\”0\” name=\”submit\” alt=\”PriceHere PayPal – The safer, easier way to pay online!\”>
  <img alt=\”\” border=\”0\” src=\”https://www.paypal.com/en_US/i/scr/pixel.gif\” width=\”1\” height=\”1\”>
  </form>”;
}
?>

That’s all there is to it. It’s a lot easier to do than it is to explain in detail, trust me on this… Upload the entire page to your site and you have a dynamic payment button. This will change the price for you automatically after a certain date.

That’s just bare bones of what you are able to do with this. You could make it for hours since last visit by collecting the IP of the visitor and much much more. But that  requires the use of MySQL. More on that at a later date!

Please be sure to leave comments or questions on this. I will be more than happy to answer them.

PayDotCom

Recent Tweets
Follow @walleyg (128 followers)
Posts By Date
September 2010
M T W T F S S
« Dec    
 12345
6789101112
13141516171819
20212223242526
27282930  
Recommended
Polls

How Is My Site?

View Results

Loading ... Loading ...