PHP code example of simpleclick / google-play-billing

1. Go to this page and download the library: Download simpleclick/google-play-billing library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

simpleclick / google-play-billing example snippets


$path = 'path/to/google-app-credentials.json';
putenv(sprintf("GOOGLE_APPLICATION_CREDENTIALS=%s", $path));

use Simpleclick\GooglePlay\ClientFactory;
use Simpleclick\GooglePlay\Products\Product;

$client = ClientFactory::create([ClientFactory::SCOPE_ANDROID_PUBLISHER]);
$product = new Product($client, 'com.example.package.name', 'productId', 'Purchase_Token');
$product->acknowledge();

use Simpleclick\GooglePlay\ClientFactory;
use Simpleclick\GooglePlay\Products\Product;

$client = ClientFactory::create([ClientFactory::SCOPE_ANDROID_PUBLISHER]);
$product = new Product($client, 'com.example.package.name', 'productId', 'Purchase_Token');
$resource = $product->get();

use Simpleclick\GooglePlay\ClientFactory;
use Simpleclick\GooglePlay\Subscriptions\Subscription;

$client = ClientFactory::create([ClientFactory::SCOPE_ANDROID_PUBLISHER]);
$subscription = new Subscription($client, 'com.example.package.name', 'subscriptionId', 'Purchase_Token');
$subscription->acknowledge();
$resource = $subscription->get(); // Imdhemy\GooglePlay\Subscriptions\SubscriptionPurchase

use Simpleclick\GooglePlay\DeveloperNotifications\DeveloperNotification;
$data = 'the_received_base_64_encoded_string';
$developerNotification = DeveloperNotification::parse($data); // Imdhemy\GooglePlay\DeveloperNotifications\DeveloperNotification
$subscriptionNotification = $developerNotification->getSubscriptionNotification(); // Imdhemy\GooglePlay\DeveloperNotifications\SubscriptionNotification