BASIC

Author Topic: In-App purchases on Win/Mac/Lnx?  (Read 1302 times)

Offline ampos

  • Prof. Inline
  • *****
  • Posts: 1594
    • View Profile
    • AMpostata Website
In-App purchases on Win/Mac/Lnx?
« on: 2011-Mar-29 »
I need to implement In-App purchases in my upcoming project. On iPhone it is there, but I need a solution for desktop machines.

Any clue?

Thx.

Really it is 2 problems:

1.- how to implement an in-app purchase

2.- How to implement "to know if a content as been purchased"
check my web and/or my blog :D
http://diniplay.blogspot.com (devblog)
http://www.ampostata.org
http://ampostata.blogspot.com
I own PC-Win, MacBook 13", iPhone 3G/3GS/4G and iPAC-WinCE

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10697
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: In-App purchases on Win/Mac/Lnx?
« Reply #1 on: 2011-Mar-30 »
I do that with a server and paypal.

It would be interesting to port that to GLBasic directly. :D

Here's part of the code:

Code: GLBasic [Select]
        // PayPal
        if(isset($_POST['txn_id']) )
        {
                $debuginfo.= "Paypal checkout\n";
                $sandbox = 0; // toggle sandbox use
       
                // read the post from PayPal system and add 'cmd'
                $req = 'cmd=_notify-validate';
                foreach ($_POST as $key => $value) {
                        $value = urlencode(stripslashes($value));
                        $req .= "&$key=$value";
                }

                // post back to PayPal system to validate
                $header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
                 
                // If testing on Sandbox use:
                if($sandbox)
                        $header .= "Host: www.sandbox.paypal.com:443\r\n";
                else
                        $header .= "Host: www.paypal.com:443\r\n";
                $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
                $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";

                // assign posted variables to local variables
                $item_name = $_POST['item_name'];
               
                if($item_name == "your product info") ...
               
                $item_number = $_POST['item_number'];
                $payment_status = $_POST['payment_status'];
                $payment_amount = $_POST['mc_gross'];
                $payment_currency = $_POST['mc_currency'];
                $txn_id = $_POST['txn_id'];
                $receiver_email = $_POST['receiver_email'];
                $payer_email = $_POST['payer_email'];
               

                // If testing on Sandbox use:
                if($sandbox)
                        $fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
                else
                        $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);

                if (!$fp) {
                        $debuginfo.= "HTTP ERROR\n";
                        // HTTP ERROR
                }
                else
                {
                        fputs ($fp, $header . $req);
                        while (!feof($fp))
                        {
                                $res = fgets ($fp, 1024);
                                if (strcmp ($res, "VERIFIED") == 0)
                                {
                                        $valid_money_transfer = true;
                                        $_POST['program'] = $item_name;
                                        $_POST['email'] = $payer_email; // recipent and license email
                                }
                                else if (strcmp ($res, "INVALID") == 0)
                                {
                                        $debuginfo.= "->INVALID CHECKOUT!\n";
                                }
                        }
                        fclose ($fp);
                }

 

Any volunteers?

[edit]
Oh, that uses SSL :/

Offline ampos

  • Prof. Inline
  • *****
  • Posts: 1594
    • View Profile
    • AMpostata Website
Re: In-App purchases on Win/Mac/Lnx?
« Reply #2 on: 2011-Aug-19 »
I have found a way to implement a payment using PAYPAL and GLBasic.

First, in Paypal website, you have to create a button (sold on your web -> create "buy now" button.

Here, you set your button options.

Once created, the HTML code is shown, but we have to choose the tab "email".

You will get a code like this:

Code: GLBasic [Select]
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=KYU26B8XLMVAN
 

Just add this to GLBasic

Code: GLBasic [Select]
NETWEBEND "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=KYU26B8XLMVAN"
 

If you want to sent something into the Paypal email, you can add this:

Code: GLBasic [Select]
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=KYU26B8XLMVAN&custom=your_text_here

This custom text will be sent to you in the paypal income receipt.

I am using

Code: GLBasic [Select]
NETWEBEND "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=KYU26B8XLMVAN&custom="+PLATFORMINFO$("ID")

so I can use this code to track purchases. At least, in "manual" mode...  =D I got this code, encrypt it and upload to my site, and the app can check online if it has been purchased...

Not a very nice solution, but it works (at least, to me).

More codes to be added to the button link can be found here:

https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_Appx_websitestandard_htmlvariables
check my web and/or my blog :D
http://diniplay.blogspot.com (devblog)
http://www.ampostata.org
http://ampostata.blogspot.com
I own PC-Win, MacBook 13", iPhone 3G/3GS/4G and iPAC-WinCE

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10697
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: In-App purchases on Win/Mac/Lnx?
« Reply #3 on: 2011-Aug-19 »
Now we only need a way to check if the item was bought properly. I think you need php for this.

Offline ampos

  • Prof. Inline
  • *****
  • Posts: 1594
    • View Profile
    • AMpostata Website
Re: In-App purchases on Win/Mac/Lnx?
« Reply #4 on: 2011-Aug-19 »
It has to be someone else... I have no idea of php. I am going to do something similar to this:

If platforminfo(ID) is, "ABCD", I will upload a file called ABCD.key, that contains the ABCD text encoded ("1234509876").

Then, the app will try to download/netwebget the file ABCD.key, and check if his own platforminfo-ID encoded is the same as the one inside. If so, full=true :)

My projects are so tiny to implicate someone else...
check my web and/or my blog :D
http://diniplay.blogspot.com (devblog)
http://www.ampostata.org
http://ampostata.blogspot.com
I own PC-Win, MacBook 13", iPhone 3G/3GS/4G and iPAC-WinCE