how to make a Payment system in VB!-VBForums
Results 1 to 26 of 26

Thread: how to make a Payment system in VB!

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2010
    Posts
    172

    Lightbulb how to make a Payment system in VB!

    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(199034514235622346); //we now randomly generate a key so there are never easy keys and all are different
             
    $test2 rand(199034514235622346);
             
    $test3 rand(199034514235622346);
             
    $test4 rand(199034514235622346);
             
    $test5 rand(199034514235622346);
             
    $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:
    1. Dim wc As New Net.WebClient
    2. Dim bt() As Byte 'the returned bytes
    3. Dim html As String 'the returned HTML text  
    4. Dim email As String = TextBox1.Text      
    5. Dim mykey As String = TextBox2.Text    
    6. Dim addon As String = ComboBox1.Text    
    7. Dim fields As New Specialized.NameValueCollection
    8. fields.Add("mykey", mykey) 'email        
    9. fields.Add("email", email) 'email          
    10. fields.Add("addon", addon) 'email          
    11. bt = wc.UploadValues("http://yourdomain.com/vb/validatekey.php", fields) 'replace the adress          
    12. html = System.Text.Encoding.ASCII.GetString(bt)          
    13. Dim returnValue As String = html          
    14. If returnValue = "keyok" And ComboBox1.Text = "extras" Then            
    15. My.Settings.addon = "true"            
    16. My.Settings.Save()            
    17. MsgBox("registration success!")            
    18. Application.Restart()        
    19. End If     
    20. If returnValue = "keyerror" Then            
    21. MsgBox("you have used your code more then 5 times or your key is invalid")        
    22. 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:
    1. if my.settings.addon = "true" then
    2. label1.text = "i'm registered"
    3. 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
    Last edited by mmuziek; Aug 10th, 2010 at 03:00 PM. Reason: corrected Code tags

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    May 2010
    Posts
    172

    Re: how to make a Payment system in VB!

    please reply give feedback

  3. #3
    PowerPoster formlesstree4's Avatar
    Join Date
    Jun 2008
    Location
    On the Internet
    Posts
    3,249

    Re: how to make a Payment system in VB!

    This should be in the codebank, but you have a PHP class as the code you're showing us with a link to a paypal.class.rar file. I haven't dl'd it to see if it's in VB.net, or if it's compiled/source code. Either way, this should be in the codebank regardless. I shall inform a moderator if one hasn't been informed already.

    EDIT: Even the downloaded file is a PHP class. This code has hardly any relation to VB.net since you did not actually code a physical application that puts this to use. This actually belongs in our PHP Codebank.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    May 2010
    Posts
    172

    Re: how to make a Payment system in VB!

    listen up this topic is not ment for discussion about what code it is

    this is intergrating Paypal and registration system in VB 8 or 10 no matter how its made

    its the First time i share something and i only get Complains about nothing

  5. #5
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,632

    Re: how to make a Payment system in VB!

    It is good that you share your code. The example you give does not have VB.Net code, but suggests how to create the code.
    I suggest you show an example of the VB.Net code you would use to complete your example, then it would go into the codebank on something like 'Calling php Payment system from VB.Net'

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    37,202

    Re: how to make a Payment system in VB!

    I have moved this thread from the 'VB.Net' forum to the 'CodeBank VB.Net' forum - and removed several posts which discussed the move, and the language involved.

    It is debatable which CodeBank it should be in (VB.Net or PHP), but I think the VB.Net one will do for now.
    Quote Originally Posted by mmuziek View Post
    listen up this topic is not ment for discussion about
    what code it is

    this is intergrating Paypal and registration system in VB 8 or 10 no matter how its made

    its the First time i share something and i only get Complains about nothing
    In future I suggest you try to understand why people are telling you something like that, rather than simply denying it as you have done in this thread.

    People thought this was nothing to do with VB because your post did not show any VB code whatsoever (you accidentally hid it by making a mistake in the code tags). Based on the comments you were getting, you should have at least looked at your post again.

    I have fixed the tags, but I have not corrected the lack of line breaks in the code (which was also caused by your mistake), so I suggest that you go up and edit the post to fix that.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    May 2010
    Posts
    172

    Re: how to make a Payment system in VB!

    ok but how do u guys think is my tutorial?

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    May 2010
    Posts
    172

    Re: how to make a Payment system in VB!

    thanks for the support i will never post a tutorial here anymore as its definitely not appreciated

  9. #9
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,632

    Re: how to make a Payment system in VB!

    Unless someone has a need for this code, and it is quite specific, I doubt anyone would have used it in a project. Adding things to the forums are not about self-gratification, if you managed to help someone, then great, maybe you learn a few things yourself in return.

  10. #10
    PowerPoster formlesstree4's Avatar
    Join Date
    Jun 2008
    Location
    On the Internet
    Posts
    3,249

    Re: how to make a Payment system in VB!

    Quote Originally Posted by mmuziek View Post
    thanks for the support i will never post a tutorial here anymore as its definitely not appreciated
    I've posted a few things here myself and gotten little feedback. It's not that it's not wanted/supported, it's as Grimfort said: There might not be a demand for such a tutorial.

    No need to get all huffy when something you wrote/created doesn't get used by the masses here, I certainly know that all my stuff isn't used by the masses so no reason for you to get all up in arms about it.

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    May 2010
    Posts
    172

    Re: how to make a Payment system in VB!

    sorry. i'm a autist and doesnt know when to calculate it like that.
    sorry.

    when my domains nameservers works u can watch all my written tutorials on www.mtut.co.cc

  12. #12
    Junior Member
    Join Date
    Sep 2010
    Posts
    21

    Re: how to make a Payment system in VB!

    Very Good! Worked flawlessy for me.

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    May 2010
    Posts
    172

    Re: how to make a Payment system in VB!

    no problem m8

  14. #14
    Lively Member
    Join Date
    May 2008
    Posts
    113

    Re: how to make a Payment system in VB!

    Love it mmuziek, I have been looking for something similar.

    many thamks

  15. #15
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,632

    Re: how to make a Payment system in VB!

    There you go ! 2 members have used your code, gj.

  16. #16

    Thread Starter
    Addicted Member
    Join Date
    May 2010
    Posts
    172

    Re: how to make a Payment system in VB!

    wel good luck for both of them.
    its very usefull so i hope its working for them.

  17. #17
    Lively Member
    Join Date
    Mar 2010
    Posts
    64

    Re: how to make a Payment system in VB!

    I keep on getting the error, "cannot connect" in a browser, and nothing happens in the application at all.

    I think everything in my php file is correct, do I need to do anything to the database ?

    Thanks for this script, I would love to get it working though

  18. #18

    Thread Starter
    Addicted Member
    Join Date
    May 2010
    Posts
    172

    Re: how to make a Payment system in VB!

    youmust have a SQL DB
    with a table with : mykey email uses addon

    point the script to that DB and table by replacing the right information

    do not do this if you dont know how SQL DB's work

  19. #19
    New Member
    Join Date
    Nov 2007
    Posts
    4

    Re: how to make a Payment system in VB!

    Quote Originally Posted by mmuziek View Post
    youmust have a SQL DB
    with a table with : mykey email uses addon

    point the script to that DB and table by replacing the right information

    do not do this if you dont know how SQL DB's work
    Great code.

    I'm currently making a "App Store" (kinda wannabe apple appstore), but got stuck where i wanted people to buy points, so they could buy apps.

    Maybe i can modify this code ?

  20. #20
    New Member
    Join Date
    Feb 2012
    Posts
    3

    Re: how to make a Payment system in VB!

    how would you set up the SQL database for this?

  21. #21

    Thread Starter
    Addicted Member
    Join Date
    May 2010
    Posts
    172

    Re: how to make a Payment system in VB!

    sir i shal quote what i alraidy said
    Quote Originally Posted by mmuziek View Post
    youmust have a SQL DB
    with a table with : mykey email uses addon

    point the script to that DB and table by replacing the right information

    do not do this if you dont know how SQL DB's work

  22. #22
    New Member
    Join Date
    Feb 2012
    Posts
    3

    Re: how to make a Payment system in VB!

    is there away to do this with using excel spreadsheet/tables.

  23. #23

    Thread Starter
    Addicted Member
    Join Date
    May 2010
    Posts
    172

    Re: how to make a Payment system in VB!

    Quote Originally Posted by PiratePaul View Post
    is there away to do this with using excel spreadsheet/tables.
    well if u dont even know how to make the tables.
    then how are u supose to do that.
    its not easy to make that such system. atleast not for me.
    i have some engines that create excell data sheet from a SQL db. but thats way to big for such small script as this,

  24. #24
    New Member
    Join Date
    Feb 2012
    Posts
    3

    Re: how to make a Payment system in VB!

    Quote Originally Posted by mmuziek View Post
    well if u dont even know how to make the tables.
    then how are u supose to do that.
    its not easy to make that such system. atleast not for me.
    i have some engines that create excell data sheet from a SQL db. but thats way to big for such small script as this,
    I understand Excel I don't understand SQL DB

  25. #25

    Thread Starter
    Addicted Member
    Join Date
    May 2010
    Posts
    172

    Re: how to make a Payment system in VB!

    Quote Originally Posted by PiratePaul View Post
    I understand Excel I don't understand SQL DB
    well i do understand both but that does not solve the fact that u need to have the experience and know how to code it so in php that it outputs/reads from excel.

    wich is almost an impossible task for a normal dev. u need Pro devs for that.
    so i cannon help u further on ur problem.
    its Mysql. wich is almost the same. Database/sheet > table/table > data/values

  26. #26
    Addicted Member Miklogak's Avatar
    Join Date
    Jan 2013
    Posts
    193

    Re: how to make a Payment system in VB!

    +Rep Given..

    OK I think the Paypal.class.php is missing plus the database fields too. I will add them both below for you guys. And I wasnt lucky to make it work. Maybe someone else can fix it. I found out that the Paypal.php is not reacting at all, and its not writing anything into my Database.

    Below I have added the Missing MYSQL TABLES, and the Paypal.class.php:


    Mysql Tables:
    PHP Code:
    -- phpMyAdmin SQL Dump
    -- version 2.11.4
    -- http://www.phpmyadmin.net
    --
    -- 
    Hostlocalhost
    -- Generation TimeJan 102014 at 01:29 PM
    -- Server version5.1.57
    -- PHP Version5.2.17

    SET SQL_MODE
    ="NO_AUTO_VALUE_ON_ZERO";

    --
    -- 
    Database: `DATABASE-NAME`
    --

    -- --------------------------------------------------------

    --
    -- 
    Table structure for table `payment`
    --

    CREATE TABLE `payment` (
      `
    mykeyvarchar(255COLLATE latin1_general_ci DEFAULT NULL,
      `
    emailvarchar(255COLLATE latin1_general_ci DEFAULT NULL,
      `
    usesvarchar(255COLLATE latin1_general_ci DEFAULT NULL,
      `
    addonvarchar(255COLLATE latin1_general_ci DEFAULT NULL
    ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;

    --
    -- 
    Dumping data for table `payment`
    -- 
    Just add the content above in text editor save it as "table.sql" or anything ending with .sql, and simply upload it to your database. Make sure you add the DATABASE name inside where it says "DATABASE-NAME"

    Now about paypal.class.php:
    Muzziek sent me a the php.class.php which wasnt the correct one, but I have found another class that I blieve is the correct one. I have attached the paypal.class.php below in the attachments

    Thanks anyways for your hard work and the tutorial. Your work is really appereciated.
    Attached Files Attached Files
    Last edited by Miklogak; Jan 15th, 2014 at 02:54 PM.

    A huge thanks to the Great Devs on vBForums who has been helping others for YEARS, and almost everyday! They make this forum worth visiting over and over again! Special thanks to Dunfiddlin, Paul, TechnoGome, , JayInThe813, ident and those I forgot to mention!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.