Exemplo n.º 1
0
 /**
  * @inheritdoc
  */
 public function get($productId, $token)
 {
     $accessToken = $this->getAccessToken();
     if (!empty($accessToken)) {
         $Request = $this->getRequest(self::ENDPOINT_PURCHASES)->addUrlField('applications', $this->getPackage())->addUrlField('purchases', '')->addUrlField($this->getPurchasesUri(), $productId)->addUrlField('tokens', $token)->addGetField('access_token', $accessToken);
         try {
             switch ($this->typeCode) {
                 case self::TYPE_PRODUCTS:
                     return ProductResource::initializeByString($Request->send());
                 case self::TYPE_SUBSCRIPTIONS:
                     return SubscriptionResource::initializeByString($Request->send());
                 default:
                     throw new RuntimeException(sprintf('type code %s not supported now', $this->typeCode));
             }
         } catch (HttpClientErrorCodeException $Ex) {
             switch ($Ex->getCode()) {
                 case 401:
                     throw InvalidCredentialsException::initializeByString($Ex->getMessage());
                 case 404:
                     throw NotFoundException::initializeByString($Ex->getMessage());
                 default:
                     throw ErrorException::initializeByString($Ex->getMessage());
             }
         } catch (HttpServerErrorCodeException $Ex) {
             throw ErrorException::initializeByString($Ex->getMessage());
         }
     } else {
         throw new UnexpectedValueException('access token is empty');
     }
 }
Exemplo n.º 2
0
    public function testSubscriptionsResourceInitialization()
    {
        $Resource1 = SubscriptionsResource::initializeByString('{
 "kind": "androidpublisher#subscriptionPurchase",
 "startTimeMillis": "1434573608845",
 "expiryTimeMillis": "100000",
 "autoRenewing": true
}');
        $this->assertSame(100, $Resource1->getExpiryTime());
        $this->assertSame(100000, $Resource1->getExpiryTimeMillis());
        $this->assertEquals('androidpublisher#subscriptionPurchase', $Resource1->getKind());
        $this->assertSame(1434573608845, $Resource1->getStartTimeMillis());
        $this->assertTrue($Resource1->isAutoRenewing());
        $this->assertTrue($Resource1->isExpired());
        $Resource2 = SubscriptionsResource::initializeByString('{
 "kind": "androidpublisher#subscriptionPurchase",
 "startTimeMillis": "1434573608845",
 "expiryTimeMillis": "100000",
 "autoRenewing": false
}');
        $this->assertSame(100, $Resource2->getExpiryTime());
        $this->assertSame(100000, $Resource2->getExpiryTimeMillis());
        $this->assertEquals('androidpublisher#subscriptionPurchase', $Resource2->getKind());
        $this->assertSame(1434573608845, $Resource2->getStartTimeMillis());
        $this->assertFalse($Resource2->isAutoRenewing());
        $this->assertTrue($Resource2->isExpired());
        $this->assertEquals('    started at:    2015-06-17 23:40:08
    expired at:    1970-01-01 03:01:40
    kind:          androidpublisher#subscriptionPurchase
    auto-renewing: disabled', (string) $Resource2);
        $Resource3 = SubscriptionsResource::initializeByString('{
 "kind": "androidpublisher#subscriptionPurchase",
 "startTimeMillis": "1434573608845",
 "expiryTimeMillis": "4434573608845",
 "autoRenewing": true
}');
        $this->assertSame(4434573608.845, $Resource3->getExpiryTime());
        $this->assertSame(4434573608845, $Resource3->getExpiryTimeMillis());
        $this->assertEquals('androidpublisher#subscriptionPurchase', $Resource3->getKind());
        $this->assertSame(1434573608845, $Resource3->getStartTimeMillis());
        $this->assertTrue($Resource3->isAutoRenewing());
        $this->assertFalse($Resource3->isExpired());
        $this->assertEquals('    started at:    2015-06-17 23:40:08
    expired at:    2110-07-12 05:00:08
    kind:          androidpublisher#subscriptionPurchase
    auto-renewing: enabled', (string) $Resource3);
    }