Skip to content

Commit 57fe2e7

Browse files
committed
update readme.md to version 2
1 parent 82121f1 commit 57fe2e7

File tree

1 file changed

+77
-23
lines changed

1 file changed

+77
-23
lines changed

README.md

+77-23
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Or you can add this [package](https://packagist.org/packages/nikapps/bazaar-api-
1818
"require": {
1919
"nikapps/bazaar-api-laravel": "2.*"
2020
}
21+
2122
}
2223
~~~
2324

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

101+
//or you can pass an array
102+
$purchase = BazaarApi::purchase([
103+
'package' => 'com.package.name',
104+
'product_id' => 'product_id',
105+
'purchase_token' => 'purchase_token'
106+
]);
107+
100108
echo "Developer Payload: " . $purchase->getDeveloperPayload();
101109
echo "PurchaseTime: " . $purchase->getPurchaseTime(); //instance of Carbon
102110
echo "Consumption State: " . $purchase->getConsumptionState();
103111
echo "Purchase State: " . $purchase->getPurchaseState();
112+
echo "Kind: " . $purchase->getKind();
104113
~~~
105114

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

121+
//or you can pass an array
122+
$subscription = BazaarApi::subscription([
123+
'package' => 'com.package.name',
124+
'subscription_id' => 'subscription_id',
125+
'purchase_token' => 'purchase_token'
126+
]);
127+
112128
echo "Initiation Time: " . $subscription->getInitiationTime(); // instance of Carbon
113129
echo "Expiration Time: " . $subscription->getExpirationTime(); // instance of Carbon
114130
echo "Auto Renewing: " . $subscription->isAutoRenewing(); // boolean
@@ -119,36 +135,74 @@ echo "Kind: " . $subscription->getKind();
119135
If you want to cancel a subscription:
120136

121137
~~~php
122-
$bazaarApi = new BazaarApi();
123-
124-
//creating cancel subscription request
125-
$cancelSubscriptionRequest = new CancelSubscriptionRequest();
126-
$cancelSubscriptionRequest->setPackage('com.package.name');
127-
$cancelSubscriptionRequest->setSubscriptionId('subscription_id');
128-
$cancelSubscriptionRequest->setPurchaseToken('123456789123456789');
129-
130-
//send request to cafebazaar and cancel a subscription
131-
$cancelSubscription = $bazaarApi->cancelSubscription($cancelSubscriptionRequest);
132-
133-
//if response is valid and we cancelled the subscription
134-
if ($cancelSubscription->isOk()) {
135-
echo "The subscription is cancelled!";
136-
} else {
137-
echo 'Failed!';
138-
}
138+
$cancelSubscription = BazaarApi::cancelSubscription('com.package.name', 'subscription_id', 'purchase_token');
139+
140+
//or you can pass an array
141+
$cancelSubscription = BazaarApi::cancelSubscription([
142+
'package' => 'com.package.name',
143+
'subscription_id' => 'subscription_id',
144+
'purchase_token' => 'purchase_token'
145+
]);
146+
147+
echo "Cancel Subscription: " . $cancelSubscription->isCancelled(); // bool
139148
~~~
140149

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

142-
## Dependencies
154+
~~~php
155+
$token = BazaarApi::refreshToken();
143156

144-
* [GuzzleHttp 5.2.x](https://packagist.org/packages/guzzlehttp/guzzle)
157+
echo 'Access Token: ' . $token->getAccessToken();
158+
echo 'Scope: ' . $token->getScope();
159+
echo 'Expire In: ' . $token->getExpireIn();
160+
echo 'Token Type: ' . $token->getTokenType();
161+
~~~
162+
163+
#### Clear Cache
164+
This package store token in cache. If you want to clear your cache, run this command:
165+
166+
```
167+
php artisan bazaar:clear-cache
168+
```
169+
170+
## Exceptions
171+
* **BazaarApiException**
172+
173+
*Parent of other exceptions.*
145174

175+
* **ExpiredAccessTokenException**
146176

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

148-
## Todo
149-
* Custom cache driver
150-
* Improve errors and exceptions
151-
* Create standalone php library
179+
* **InvalidJsonException**
180+
181+
*When response has invalid json structure*
182+
183+
* **InvalidPackageNameException**
184+
185+
*When package name is invalid*
186+
187+
* **InvalidTokenException**
188+
189+
*When access token is invalid*
190+
191+
* **NetworkErrorException**
192+
193+
*Guzzle ClientExcpetion*
194+
195+
you can get guzzle exception by `$e->getClientException()`
196+
197+
198+
* **NotFoundException**
199+
200+
*When purchase or subscrption is not found*
201+
202+
## Dependencies
203+
204+
* [GuzzleHttp 5.2.x](https://packagist.org/packages/guzzlehttp/guzzle)
205+
* [Bazaar-Api-PHP 1.x](https://packagist.org/packages/nikapps/bazaar-api-php)
152206

153207

154208
## Contribute

0 commit comments

Comments
 (0)