1
1
# Bazaar-Api-Laravel (BazaarApi for Laravel)
2
- An API wrapper for CafeBazaar based on popular Laravel PHP Framework (Laravel 4.x)
2
+ An API wrapper for CafeBazaar based on popular Laravel PHP Framework (Laravel 4.2. x)
3
3
4
+ * Version 2.x is based on [ Bazaar-Api-PHP] ( https://github.com/nikapps/bazaar-api-php ) .*
4
5
5
6
## Installation
6
- Using composer, add this [ package] ( https://packagist.org/packages/nikapps/bazaar-api-laravel ) dependency to your Laravel's composer.json :
7
+
8
+ Simply run command:
9
+
10
+ ```
11
+ composer require nikapps/bazaar-api-laravel
12
+ ```
13
+
14
+ Or you can add this [ package] ( https://packagist.org/packages/nikapps/bazaar-api-laravel ) dependency to your Laravel's composer.json :
7
15
8
16
~~~ json
9
17
{
10
18
"require" : {
11
- "nikapps/bazaar-api-laravel" : " 1 .*"
19
+ "nikapps/bazaar-api-laravel" : " 2 .*"
12
20
}
13
21
}
14
22
~~~
@@ -19,6 +27,8 @@ Then update composer:
19
27
composer update
20
28
```
21
29
30
+ -
31
+
22
32
Add this package provider in your providers array ` [app/config/app.php] ` :
23
33
24
34
~~~ php
@@ -71,7 +81,8 @@ php artisan bazaar:refresh-token <CODE>
71
81
```
72
82
* - replace ` <CODE> ` with the copied data.*
73
83
74
- * Copy ` refresh_token ` and save in your configuration file.
84
+ * Copy ` refresh_token ` and save in your configuration file.
85
+ * (app/config/packages/nikapps/bazaar-api-laravel/config.php)*
75
86
76
87
#### Done!
77
88
@@ -84,51 +95,24 @@ php artisan bazaar:refresh-token <CODE>
84
95
If you want to get a purchase information:
85
96
86
97
~~~ php
87
- $bazaarApi = new BazaarApi( );
98
+ $purchase = BazaarApi::purchase('com.package.name', 'product_id', 'purchase_token' );
88
99
89
- //creating purchase request
90
- $purchaseStatusRequest = new PurchaseStatusRequest();
91
- $purchaseStatusRequest->setPackage('com.package.name');
92
- $purchaseStatusRequest->setProductId('product_id');
93
- $purchaseStatusRequest->setPurchaseToken('123456789123456789');
94
-
95
- //send request to cafebazaar and get purchase info
96
- $purchase = $bazaarApi->getPurchase($purchaseStatusRequest);
97
-
98
- //if response is valid and we have this purchase
99
- if($purchase->isOk()){
100
- echo "Developer Payload: " . $purchase->getDeveloperPayload();
101
- echo "PurchaseTime: " . $purchase->getPurchaseTime(); //instance of Carbon
102
- echo "Consumption State: " . $purchase->getConsumptionState();
103
- echo "Purchase State: " . $purchase->getPurchaseState();
104
- }else{
105
- echo 'Failed!';
106
- }
100
+ echo "Developer Payload: " . $purchase->getDeveloperPayload();
101
+ echo "PurchaseTime: " . $purchase->getPurchaseTime(); //instance of Carbon
102
+ echo "Consumption State: " . $purchase->getConsumptionState();
103
+ echo "Purchase State: " . $purchase->getPurchaseState();
107
104
~~~
108
105
109
106
#### Subscription
110
107
If you want to get a subscription information:
111
108
112
109
~~~ php
113
- $bazaarApi = new BazaarApi();
114
-
115
- //creating subscription request
116
- $subscriptionStatusRequest = new SubscriptionStatusRequest();
117
- $subscriptionStatusRequest->setPackage('com.package.name');
118
- $subscriptionStatusRequest->setSubscriptionId('subscription_id');
119
- $subscriptionStatusRequest->setPurchaseToken('123456789123456789');
120
-
121
- //send request to cafebazaar and get subscription info
122
- $subscription = $bazaarApi->getSubscription($subscriptionStatusRequest);
110
+ $subscription = BazaarApi::subscription('com.package.name', 'subscription_id', 'purchase_token');
123
111
124
- //if response is valid and we have this subscription
125
- if ($subscription->isOk()) {
126
- echo "Initiation Time: " . $subscription->getInitiationTime(); // instance of Carbon
127
- echo "Expiration Time: " . $subscription->getExpirationTime(); // instance of Carbon
128
- echo "Auto Renewing: " . $subscription->isAutoRenewing(); // boolean
129
- } else {
130
- echo 'Failed!';
131
- }
112
+ echo "Initiation Time: " . $subscription->getInitiationTime(); // instance of Carbon
113
+ echo "Expiration Time: " . $subscription->getExpirationTime(); // instance of Carbon
114
+ echo "Auto Renewing: " . $subscription->isAutoRenewing(); // boolean
115
+ echo "Kind: " . $subscription->getKind();
132
116
~~~
133
117
134
118
#### Cancel Subscription
0 commit comments