Skip to main content

Inapp Purchase Server side validation for Android as well as IOS using Laravel

Hi friends,

                I'm very happy to share today experience In-app purchase server-side validation you.

This link is very use full for me to implement this server side validation. Please refer this link,

https://github.com/aporat/store-receipt-validator

I have faced some problems with Android server side validation. I will share problematic experience with you..........

  1. https://developers.google.com/android-publisher/authorization  -> go through this URL and flow this steps
  2. If you follow the steps, you will get a client id and client secret. While doing this process it will ask you for redirect URI, you just any of your project URL for testing purpose to get the token
    http://localhost/project/public/refresh-token

    I Just gave a refresh token function as return URL. In this function, $request->code you can retrieve the refresh token
  3. Using this token you can do this process 
Exchange this code for an access and refresh token pair by sending a POST request to https://accounts.google.com/o/oauth2/token with the following fields set:
grant_type=authorization_code
code=<the code from the previous step>
client_id=<the client ID token created in the APIs Console>
client_secret=<the client secret corresponding to the client ID>
redirect_uri=<the URI registered with the client ID>

In this step you will get access_token
 
    4. Important thing to mind, while doing this process
  • Very important things to do, save this refresh token for further use to generate the access token
  • First time only you can able to get this refresh, again you will not get
  • If you missed this token you need to revoke by the sense, remove and do the client_id and client_secret generation process, by using this link
    https://security.google.com/settings/security/permissions 
    5.Each access token is only valid for a short time. Once the current access token expires, the server
will need to use the refresh token to get a new one. To do this, send a POST request to https://accounts.google.com/o/oauth2/token with the following fields set:

grant_type=refresh_token
client_id=<the client ID token created in the APIs Console>
client_secret=<the client secret corresponding to the client ID>
refresh_token=<the refresh token from the previous step>

use ReceiptValidator\GooglePlay\Validator as PlayValidator;
$validator = new PlayValidator([
    'client_id' => '...',
    'client_secret' => '...',
    'refresh_token' => 'You Just give your refresh token'
]);

try {
  $response = $validator->setPackageName('PACKAGE_NAME')
    ->setProductId('PRODUCT_ID')
    ->setPurchaseToken('PURCHASE_TOKEN')
    ->validate();
} catch (Exception $e){
  var_dump($e->getMessage());
  // example message: Error calling GET ....: (404) Product not found for this application.
}
// success
  • If you done this process, you will get this response
  • The purchase state of the order. Possible values are 0 (purchased), 1 (canceled), or 2 (refunded).
https://developer.android.com/google/play/billing/billing_reference.html

Google_Service_AndroidPublisher_ProductPurchase Object
(
    [internal_gapi_mappings:protected] => Array
        (
        )

    [consumptionState] => 0
    [developerPayload] => 
    [kind] => androidpublisher#productPurchase
    [purchaseState] => 0
    [purchaseTimeMillis] => 1479873380495
    [modelData:protected] => Array
        (
        )

    [processed:protected] => Array
        (
        )

)

Comments

  1. Such a very useful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. After reading your article I was amazed. I know that you explain it very well.
    And I hope that other readers will also experience how I feel after reading your article

    web designing training in chennai

    web designing training in tambaram

    digital marketing training in chennai

    digital marketing training in tambaram

    rpa training in chennai

    rpa training in tambaram

    tally training in chennai

    tally training in tambaram

    ReplyDelete

Post a Comment

Popular posts from this blog

The requested URL /phpmyadmin was not found on this server. Apache/2.4.18 (Ubuntu) Server at localhost Port 80

Hi dudes, I'm getting Not Found error, when i hit a  http://localhost/phpmyadmin/ url, but i my system php, mysql & apache2 is already installed still i'm getting this error When i do this following step, the error get fixed. Do the following steps & Enjoy😃😄😅😄😄😃 You need to configure your apache2.conf to make phpMyAdmin work. For more detail Please read  this section  in Ubuntu wiki. open a termianl and run gksu gedit /etc/apache2/apache2.conf Then add the following line to the end of the file. Include /etc/phpmyadmin/apache.conf Then restart apache /etc/init.d/apache2 restart

Install a node & npm specific versions using nvm (Node Version Manager)

Hi buddies, When i tried to install a node & npm in my system, i will be facing some problem with the version. I want to install a recent LTS (Long Term Support) Don't Do (If you want to install a specific version):  I don't know, how its gonna installed, but its not a recent Node LTS version sudo apt-get install nodejs-legacy sudo apt-get install npm Do (Using a NVM- Node Version Manager to install a specific version): Use the following command to install a NVM into your system $ curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash Reload the system environment using this command $ source ~/.profile $ source ~/.bashrc List all the nodejs version using this command $ nvm ls-remote Install a nodejs version, what ever you want (If you want to install multiple node version you can install using this command) $ nvm install 6.11.1 $ nvm install 8.2.1 List a node version using this command

PHP 7 with Laravel 5.3 installation problem ( Your requirements could not be resolved to an installable set of packages )

I'm Facing this problem, while installation using laravel 5.3 with PHP 7 Your requirements could not be resolved to an installable set of packages.   Problem 1     - phpunit/phpunit 5.5.5 requires ext-dom * -> the requested PHP extension dom is missing from your system.     - phpunit/phpunit 5.5.4 requires ext-dom * -> the requested PHP extension dom is missing from your system.     - phpunit/phpunit 5.5.3 requires ext-dom * -> the requested PHP extension dom is missing from your system.     - phpunit/phpunit 5.5.2 requires ext-dom * -> the requested PHP extension dom is missing from your system.     - phpunit/phpunit 5.5.1 requires ext-dom * -> the requested PHP extension dom is missing from your system.     - phpunit/phpunit 5.5.0 requires ext-dom * -> the requested PHP extension dom is missing from your system.     - phpunit/phpunit 5.4.8 requires ext-dom * -> the requested PHP extension dom is missing from your system.     - phpunit/phpunit 5.4.7 requir