the code is simple no passwords are needed no saving/loading just 1 small code and 3 web scripts
everything i use here what u must enter or replace i underline it
in this case i use paypal and have 1 addon in my application (or 1 pro edition)
start making a project (windows forms)
go to the settings section in your project page
add the setting (do not change this just enter as it is here)
addon String user false
thats it start by saving your project
ok now we are gonna make 3 php scripts and i give u 1 (config.php,paypal.php,validatekey.php) and u get (paypal.class.php) from me
ok lets start make a new text file call it config.php (dont forget to remove the .txt)
enter this code and replace values with your own
PHP Code:
<?php
//setup SQL connection
$db = "database"; // database
$host = "localhost"; // most of the time localhost
$username = "root"; // your username
$pass = "root"; // your password
?>
if u use a free host as ur hosting provider if u have SQL and what the details are if you dont know yet
ok now the Biggest script the payment script call it paypal.php for ordening
its a BIG code so read it fully!
PHP Code:
<?php
$game_name = "bakkery"; // product name change this
$costs = "3.30"; // price in dollars change this
$pay_pal = "bla@bla.com"; // paypal email change this
// UNDER THIS LINE DO NOT EDIT IF U DONT KNOW WHAT UR DOING!
require_once('paypal.class.php');
$p = new paypal_class;
$p->paypal_url = 'https://www.paypal.com/cgi-bin/webscr';
//$p->paypal_url = 'https://www.paypal.com/cgi-bin/webscr';
$this_script = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
if (empty($_GET['action'])) $_GET['action'] = 'process';
switch ($_GET['action']) {
case 'process':
$p->add_field('business', $pay_pal);
$p->add_field('return', $this_script.'?action=success');
$p->add_field('cancel_return', $this_script.'?action=cancel');
$p->add_field('notify_url', $this_script.'?action=ipn');
$p->add_field('item_name', $game_name);
$p->add_field('amount', $costs);
$p->submit_paypal_post();
//$p->dump_fields();
break;
case 'success':
echo "<html><head><title>Success</title></head><body><h3>Thank you for your order.</h3>";
foreach ($_POST as $key => $value) { echo "$key: $value<br>"; }
echo "</body></html>";
break;
case 'cancel':
echo "<html><head><title>Canceled</title></head><body><h3>The order was canceled.</h3>";
echo "</body></html>";
break;
case 'ipn':
if ($p->validate_ipn()) {
include "config.php";
mysql_connect("$host", "$username", "$pass")or die("cannot connect");
mysql_select_db("$db")or die("cannot select DB");
$subject = 'Instant Payment Notification - Recieved Payment'; // we are emailing this to use with all the data
$to = '$pay_pal';
$body = "An instant payment notification was successfully recieved MCG will now transact it to your paypal accound\n";
$body .= "from ".$p->ipn_data['payer_email']." on ".date('m/d/Y');
$body .= " at ".date('g:i A')."\n\nDetails:\n";
foreach ($p->ipn_data as $key => $value) { $body .= "\n$key: $value"; }
mail($to, $subject, $body);
$test = rand(1990345, 14235622346); //we now randomly generate a key so there are never easy keys and all are different
$test2 = rand(1990345, 14235622346);
$test3 = rand(1990345, 14235622346);
$test4 = rand(1990345, 14235622346);
$test5 = rand(1990345, 14235622346);
$mega = "$test-$test2-$test3-$test4-$test5"; // we combine then to XXXXXXX-XXXXXXXXXXX-XXXXXXX-XXXXXXXXXXX
$ip = $p->ipn_data['payer_email'];
$sql2="INSERT INTO `database`.`tablename` (`key`, `email`, `uses`, `addon`) VALUES ('$mega', '$ip', '5', '^^the addon or product name^^');"; // we are inserting the data to sql database for checking replace database and table name with your own
$result2=mysql_query($sql2);
echo "your registration info <br/>"; // this is the text user gets to see after payment
echo "your Registration key : $mega <br/>";
echo "your email : $ip <br/>";
echo "you bought : $game_name <br/>";
echo "you get an email with your information within 1 hour if not please contact us with your paypal details to $pay_pal";
$subject2 = 'Instant Payment Notification - payment complete!'; // this is sended to the customer with its details
$to2 = $p->ipn_data['payer_email'];
$body2 = " we have your payment succesfully <br/>";
$body2 .= "Registration key : $mega -- your email : $ip -- you bought : ^^the addon or product name^^ <br/>";
$body2 .= "thank you for your support buying this software addon good luck <br/>";
$body2 .= "for support contact us at $pay_pal";
mail($to2, $subject2, $body2);
}
break;
}
// thats it
?>
replace the values where i put a ^^ on every end or where i put change this after
wow half way there! easy or not? i did al the word for u XD
now lets make the last script validatekey.php
PHP Code:
<?php
include "config.php";
ob_start();
// PLEASE DO NOT EDIT THE CODE JUST THE TABLE NAMES WHEN ASKED
// Connect to server and select databse.
mysql_connect("$host", "$username", "$pass")or die("cannot connect");
mysql_select_db("$db")or die("cannot select DB");
// Define the values given by VB
$myusername=$_REQUEST['mykey'];
$mypassword=$_REQUEST['email'];
$addon=$_REQUEST['addon'];
// To protect MySQL injection
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
// check if the key exists
$sql="SELECT mykey,email,uses,addon FROM `!!TABLE NAME!!` WHERE mykey='$myusername' AND email='$mypassword' AND uses='5'OR uses='4' OR uses='3' OR uses='2' OR uses='1' AND addon='$addon'"; // change the table name
if (!$result=mysql_query($sql))
{
trigger_error(mysql_error().'<br />In query: '.$sql);
}
elseif(mysql_num_rows($result) == 0)
{
echo 'keyerror'; // if not give a key error
}
else
{
$sql2="UPDATE !!tablename!! set uses=uses-1 WHERE mykey='$myusername' AND email='$mypassword'"; // if true lower the uses count and !!change the table name!!
if (!$result=mysql_query($sql2))
{
trigger_error(mysql_error().'<br />In query: '.$sql2);
}
else
{
echo"keyok"; // and if that succeeded give the ok signal
}
}
//check that u removed the !! marks around the table name otherwise u get errors
ob_end_flush();
?>
so thats ready! now i give u the last peace of code
download
put all the files together put them on 1 folder in ur site/server and go back to VB
make a button and give it the text buy now then enter this code
replace the adress to paypal.php with your site aka www.yourdomain.com/vb/paypal.php
ok now when the user clicks the button they are pointed to the payment page
ok now the heavy duty
make another form place 2 textboxes and a combobox and a button
call the button register
give the combobox the same value as u gave the addon name in the paypal script ( when there are more addons make multiple paypal scripts each with different addon names)
textbox1 = key
textbox2 = email used when the used payd
combobox1 = addon selection
ok now the code open the click button 1
and enter this code
VB.Net Code:
Dim wc As New Net.WebClient
Dim bt() As Byte 'the returned bytes
Dim html As String 'the returned HTML text
Dim email As String = TextBox1.Text
Dim mykey As String = TextBox2.Text
Dim addon As String = ComboBox1.Text
Dim fields As New Specialized.NameValueCollection
fields.Add("mykey", mykey) 'email
fields.Add("email", email) 'email
fields.Add("addon", addon) 'email
bt = wc.UploadValues("http://yourdomain.com/vb/validatekey.php", fields) 'replace the adress
html = System.Text.Encoding.ASCII.GetString(bt)
Dim returnValue As String = html
If returnValue = "keyok" And ComboBox1.Text = "extras" Then
My.Settings.addon = "true"
My.Settings.Save()
MsgBox("registration success!")
Application.Restart()
End If
If returnValue = "keyerror" Then
MsgBox("you have used your code more then 5 times or your key is invalid")
End If
ok now to see the difference go back to form1 make a label give it the text i'm not registered
open the forms code then upper dropdownbox form1.events on the right load
teh u get form1 load box now make this code
VB.Net Code:
if my.settings.addon = "true" then
label1.text = "i'm registered"
end if
thats it now try the payment system and see that your application has been upgraded!
rate me if u think this tutorial was or is helpfull