Skip to content

Commit

Permalink
update readme.md to version 2
Browse files Browse the repository at this point in the history
  • Loading branch information
alibo committed Mar 18, 2015
1 parent 82121f1 commit 57fe2e7
Showing 1 changed file with 77 additions and 23 deletions.
100 changes: 77 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Or you can add this [package](https://packagist.org/packages/nikapps/bazaar-api-
"require": {
"nikapps/bazaar-api-laravel": "2.*"
}

}
~~~

Expand Down Expand Up @@ -97,10 +98,18 @@ If you want to get a purchase information:
~~~php
$purchase = BazaarApi::purchase('com.package.name', 'product_id', 'purchase_token');

//or you can pass an array
$purchase = BazaarApi::purchase([
'package' => 'com.package.name',
'product_id' => 'product_id',
'purchase_token' => 'purchase_token'
]);

echo "Developer Payload: " . $purchase->getDeveloperPayload();
echo "PurchaseTime: " . $purchase->getPurchaseTime(); //instance of Carbon
echo "Consumption State: " . $purchase->getConsumptionState();
echo "Purchase State: " . $purchase->getPurchaseState();
echo "Kind: " . $purchase->getKind();
~~~

#### Subscription
Expand All @@ -109,6 +118,13 @@ If you want to get a subscription information:
~~~php
$subscription = BazaarApi::subscription('com.package.name', 'subscription_id', 'purchase_token');

//or you can pass an array
$subscription = BazaarApi::subscription([
'package' => 'com.package.name',
'subscription_id' => 'subscription_id',
'purchase_token' => 'purchase_token'
]);

echo "Initiation Time: " . $subscription->getInitiationTime(); // instance of Carbon
echo "Expiration Time: " . $subscription->getExpirationTime(); // instance of Carbon
echo "Auto Renewing: " . $subscription->isAutoRenewing(); // boolean
Expand All @@ -119,36 +135,74 @@ echo "Kind: " . $subscription->getKind();
If you want to cancel a subscription:

~~~php
$bazaarApi = new BazaarApi();

//creating cancel subscription request
$cancelSubscriptionRequest = new CancelSubscriptionRequest();
$cancelSubscriptionRequest->setPackage('com.package.name');
$cancelSubscriptionRequest->setSubscriptionId('subscription_id');
$cancelSubscriptionRequest->setPurchaseToken('123456789123456789');

//send request to cafebazaar and cancel a subscription
$cancelSubscription = $bazaarApi->cancelSubscription($cancelSubscriptionRequest);

//if response is valid and we cancelled the subscription
if ($cancelSubscription->isOk()) {
echo "The subscription is cancelled!";
} else {
echo 'Failed!';
}
$cancelSubscription = BazaarApi::cancelSubscription('com.package.name', 'subscription_id', 'purchase_token');

//or you can pass an array
$cancelSubscription = BazaarApi::cancelSubscription([
'package' => 'com.package.name',
'subscription_id' => 'subscription_id',
'purchase_token' => 'purchase_token'
]);

echo "Cancel Subscription: " . $cancelSubscription->isCancelled(); // bool
~~~

#### Refresh Token (Manually)
By default, this package refresh access token if token is expired.
If you want to refresh access token manually:

## Dependencies
~~~php
$token = BazaarApi::refreshToken();

* [GuzzleHttp 5.2.x](https://packagist.org/packages/guzzlehttp/guzzle)
echo 'Access Token: ' . $token->getAccessToken();
echo 'Scope: ' . $token->getScope();
echo 'Expire In: ' . $token->getExpireIn();
echo 'Token Type: ' . $token->getTokenType();
~~~

#### Clear Cache
This package store token in cache. If you want to clear your cache, run this command:

```
php artisan bazaar:clear-cache
```

## Exceptions
* **BazaarApiException**

*Parent of other exceptions.*

* **ExpiredAccessTokenException**

*When token is expired (only when auto-refresh-token is disabled in config file)*

## Todo
* Custom cache driver
* Improve errors and exceptions
* Create standalone php library
* **InvalidJsonException**

*When response has invalid json structure*

* **InvalidPackageNameException**

*When package name is invalid*

* **InvalidTokenException**

*When access token is invalid*

* **NetworkErrorException**

*Guzzle ClientExcpetion*

you can get guzzle exception by `$e->getClientException()`


* **NotFoundException**

*When purchase or subscrption is not found*

## Dependencies

* [GuzzleHttp 5.2.x](https://packagist.org/packages/guzzlehttp/guzzle)
* [Bazaar-Api-PHP 1.x](https://packagist.org/packages/nikapps/bazaar-api-php)


## Contribute
Expand Down

0 comments on commit 57fe2e7

Please sign in to comment.