Skip to content

faurecia-aptoide/appning-api-php-client

 
 

Repository files navigation

Appning API Client Library for PHP

License
Apache 2.0

The Appning API Library enables you to work with Appning APIs on your server. This documentation and the included examples focus on the Android Publisher API.

This library is an unofficial fork of Google’s google-api-php-client library and is maintained independently by Appning. It is not an official Google product and is provided under the same Apache License 2.0 terms as the upstream project.

Requirements

Developer Documentation

The docs folder provides detailed guides for using this library.

Installation

Composer

The preferred method is via composer. Follow the installation instructions if you do not already have composer installed.

Once composer is installed, execute the following command in your project root to install this library:

composer require appning/apiclient

If you're facing a timeout error then either increase the timeout for composer by adding the env flag as COMPOSER_PROCESS_TIMEOUT=600 composer install or you can put this in the config section of the composer schema:

{
    "config": {
        "process-timeout": 600
    }
}

Finally, be sure to include the autoloader:

require_once '/path/to/your-project/vendor/autoload.php';

This library relies on google/apiclient-services. That library provides up-to-date API wrappers for a large number of Google APIs. In order that users may make use of the latest API clients, this library does not pin to a specific version of google/apiclient-services. In order to prevent the accidental installation of API wrappers with breaking changes, it is highly recommended that you pin to the latest version yourself prior to using this library in production.

Authentication with JWT Bearer (Appning)

Appning services use JWT Bearer authentication. To authenticate, you need to obtain credentials through the developer portal. The credentials will be provided as a JSON file - serviceAccount.json - containing kid and privateKeyPem fields.

Service Account File Format

Use the credentials obtained through the developer portal. The serviceAccount.json file should have the following structure:

{
  "kid": "the-key-id",
  "privateKeyPem": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n",
  "clientId": "the-client-id"
}

Basic Usage Example

See examples/androidpublisher-batch-update.php for a complete working example.

require_once __DIR__ . '/vendor/autoload.php';

use Appning\Client;
use Google\Service\AndroidPublisher\AndroidPublisher;
use Appning\Exception as AppningException;

// Check if serviceAccount.json exists
$serviceAccountFile = __DIR__ . '/serviceAccount.json';
if (!file_exists($serviceAccountFile)) {
    echo "Error: serviceAccount.json not found.\n";
    echo "Please obtain credentials through the developer portal.\n";
    exit(1);
}

try {
    // 1. Load client from serviceAccount.json
    $client = new Client();
    $client->fromServiceAccountFile($serviceAccountFile);

    // 2. Create the AndroidPublisher service
    $service = new AndroidPublisher($client);

    // 3. Build the request body for batch update
    $packageName = "com.example.app";
    
    $batchRequestBody = [
        "oneTimeProduct" => [
            "packageName" => $packageName,
            "productId" => "coin_pack_etc_" . time(),
            "listings" => [
                [
                    "languageCode" => "pt-BR",
                    "title" => "300 Moedas",
                    "description" => "Receba 300 moedas instantaneamente"
                ],
                [
                    "languageCode" => "en-US",
                    "title" => "300 Coins",
                    "description" => "Receive 300 coins instantly"
                ]
            ],
            "purchaseOptions" => [
                [
                    "purchaseOptionId" => "default",
                    "buyOption" => [
                        "legacyCompatible" => true,
                        "multiQuantityEnabled" => false
                    ],
                    "regionalPricingAndAvailabilityConfigs" => [
                        [
                            "regionCode" => "US",
                            "price" => [
                                "currencyCode" => "USD",
                                "units" => "1",
                                "nanos" => 880000000
                            ],
                            "availability" => "AVAILABLE"
                        ]
                    ]
                ]
            ],
            "regionsVersion" => [
                "version" => "2025/03"
            ]
        ],
        "updateMask" => "listings,purchaseOptions",
        "allowMissing" => true,
        "latencyTolerance" => "PRODUCT_UPDATE_LATENCY_TOLERANCE_LATENCY_TOLERANT",
        "regionsVersion" => [
            "version" => "2025/03"
        ]
    ];

    // 4. Call batchUpdate
    echo "Calling batchUpdate for package: {$packageName}\n";
    $response = $service->monetization_onetimeproducts->batchUpdate(
        $packageName,
        ['requests'=>$batchRequestBody]
    );

    // Success: HTTP status code is in 2XX range
    echo "✅ Success\n";
} catch (AppningException $e) {
    // Error: HTTP status code is not in 2XX range
    echo "❌ Error (HTTP {$e->getCode()}): {$e->getMessage()}\n";
    if ($e->getErrors()) {
        echo "Errors:\n";
        print_r($e->getErrors());
    }
} catch (Exception $e) {
    echo "❌ Unexpected error: {$e->getMessage()}\n";
    exit(1);
}

Examples

See the examples/ directory for examples of the key client features. The main example is:

Code Quality

Run the PHPUnit tests with PHPUnit.

php vendor/bin/phpunit tests

Frequently Asked Questions

What do I do if something isn't working?

For support with the library the best place to ask is via email appsmarket.pay@forvia.com.

If there is a specific bug with the library, please file an issue in the GitHub issues tracker, including an example of the failing code and any specific errors retrieved. Feature requests can also be filed, as long as they are core library requests, and not-API specific: for those, refer to the documentation for the individual APIs for the best place to file requests. Please try to provide a clear statement of the problem that the feature would address.

About

A PHP client library for accessing Appning APIs

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • PHP 100.0%