Ejemplo n.º 1
0
 public function test()
 {
     $Client1 = new Client();
     $this->assertEmpty($Client1->getPackage());
     $Client1->setPackage('com.example.example');
     $this->assertEquals('com.example.example', $Client1->getPackage());
     try {
         $Client1->get('', '');
         $this->fail();
     } catch (UnexpectedValueException $Ex) {
     }
     $Client2 = new Client(-1);
     $Client2->setPackage('com.example.example')->setAccessToken('ACCEss_token');
     try {
         $Client2->get('', '');
         $this->fail();
     } catch (RuntimeException $Ex) {
     }
 }
Ejemplo n.º 2
0
<?php

/**
 * Copyright 2015 Alexey Maslov <*****@*****.**>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Purchases products example
 * @author alxmsl
 * @date 5/28/13
 */
include '../vendor/autoload.php';
use alxmsl\Google\AndroidPublisher\Purchases\Client;
use alxmsl\Google\AndroidPublisher\Purchases\Products\Resource as ProductsResource;
const PACKAGE_NAME = 'com.example.package', ACCESS_TOKEN = '4CcE5s_T0keN', PRODUCT_ID = 'com.example.package.product.1', PURCHASE_TOKEN = 'puRCH45e_tokEN';
$Client = new Client();
$Client->setPackage(PACKAGE_NAME)->setAccessToken(ACCESS_TOKEN);
/** @var ProductsResource $Resource */
$Resource = $Client->get(PRODUCT_ID, PURCHASE_TOKEN);
var_dump($Resource->isPurchased() && !$Resource->isCancelled());
Ejemplo n.º 3
0
 public function __construct()
 {
     parent::__construct(self::TYPE_SUBSCRIPTIONS);
 }
Ejemplo n.º 4
0
use alxmsl\Cli\CommandPosix;
use alxmsl\Cli\Exception\RequiredOptionException;
use alxmsl\Cli\Option;
use alxmsl\Google\AndroidPublisher\Purchases\Client;
$accessToken = '';
$packageName = '';
$productId = '';
$token = '';
$Command = new CommandPosix();
$Command->appendHelpParameter('show help');
$Command->appendParameter(new Option('access', 'a', 'access token', Option::TYPE_STRING, true), function ($name, $value) use(&$accessToken) {
    $accessToken = $value;
});
$Command->appendParameter(new Option('package', 'p', 'package name', Option::TYPE_STRING), function ($name, $value) use(&$packageName) {
    $packageName = $value;
});
$Command->appendParameter(new Option('product', 'r', 'product id', Option::TYPE_STRING, true), function ($name, $value) use(&$productId) {
    $productId = $value;
});
$Command->appendParameter(new Option('token', 't', 'purchase token', Option::TYPE_STRING, true), function ($name, $value) use(&$token) {
    $token = $value;
});
try {
    $Command->parse(true);
    $Client = new Client();
    $Client->setPackage($packageName)->setAccessToken($accessToken);
    $Resource = $Client->get($productId, $token);
    printf("%s\n", (string) $Resource);
} catch (RequiredOptionException $Ex) {
    $Command->displayHelp();
}