-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSubscriptionDemo.php
250 lines (230 loc) · 11.3 KB
/
SubscriptionDemo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<?php
require __DIR__ . '/vendor/autoload.php';
error_reporting(E_ALL);
ini_set('display_errors', 1);
# ============================================== Subscription SERVICES =================================================
# required classes
use Pod\Subscription\Service\SubscriptionService;
use Pod\Base\Service\BaseInfo;
use Pod\Base\Service\Exception\ValidationException;
use Pod\Base\Service\Exception\PodException;
const API_TOKEN = '{PUT API TOKEN}';
const TOKEN_ISSUER = 1;
$baseInfo = new BaseInfo();
$baseInfo->setToken(API_TOKEN);
$baseInfo->setTokenIssuer(TOKEN_ISSUER);
# instantiates a SubscriptionService
$SubscriptionService = new SubscriptionService($baseInfo);
# ================================================ add Subscription Plan ===============================================
function addSubscriptionPlan()
{
global $SubscriptionService;
$param =
[
## ============================ *Required Parameters ==================================
'name' => '{put plan name}', # نام دلخواه برای طرح
'price' => '{put plan price}', # قیمت طرح
'periodTypeCode' => '{put period type code}', # بازه زمانی طرح - ماهانه روزانه یا سالانه
'periodTypeCount' => '{put period type count}', # تعداد مورد نظر از بازه زمانی
'type' => 'put plan type', # نوع طرح که یا مسدودی و یا نقدی میباشد
'guildCode' => 'put guild code', # کد صنف مورد نظر
# کد محصول ثبت شده برای این طرح *توجه مقدار entityId محصول باید فرستاده شود*
'productId' => '{put product id}',
## ============================ Optional Parameters ==================================
# 'usageCountLimit' => {put usage count limit}, # محدودیت میزان دفعات قابل استفاده
# 'usageAmountLimit' => {put usage amount limit}, # محدودیت میزان مبلغ قابل استفاده
# 'permittedGuildCode' => [{put permitted guild codes}], # لیست کد صنف های مجاز جهت استفاده
# 'permittedBusinessId' =>[{put permitted business ids}], # شناسه کسب و کارهای مجاز جهت استفاده
# 'permittedProductId' =>[{{put permitted product ids}}], # لیست شناسه محصولات مجاز جهت استفاده
// 'currencyCode' => '', # like IRR
// 'scVoucherHash' => ['{Put Service Call Voucher Hashes}'],
// 'scApiKey' => '{Put service call Api Key}',
];
try {
$result = $SubscriptionService->addSubscriptionPlan($param);
print_r($result);
}
catch (ValidationException $e) {
print_r($e->getResult());
print_r($e->getErrorsAsArray());
} catch (PodException $e) {
print_r($e->getResult());
}
}
//addSubscriptionPlan();
//die();
# ============================================== subscription Plan List ================================================
function subscriptionPlanList()
{
global $SubscriptionService;
$param =
[
## ============================ *Required Parameters =========================
'offset' => '{put page number}', # حد پایین خروجی
'size' => '{put output size}', # اندازه خروجی
## =========================== Optional Parameters ===========================
'id' => '{put plan id}', # شناسه طرح
# 'periodTypeCode' =>'put period type code', # بازه زمانی طرح - ماهانه روزانه یا سالانه
# 'fromPrice' =>{put minimum price}, # حد پایین قیمت
# 'toPrice' =>{put maximum price}, # حد بالای قیمت
# 'periodTypeCountFrom' => {put minimum count of period}, # کف تعداد مورد نظر از بازه زمانی
# 'periodTypeCountTo' => {put maximum count of period}, # سقف تعداد مورد نظر از بازه زمانی
# 'typeCode'=> 'put plan type', # نوع طرح که یا مسدودی و یا نقدی میباشد
# 'enable'=> '{true/false}', # فعال یا غیر فعال بودن طرح
# 'permittedGuildCode'=> [{put permitted Guild Codes}], # لیست کد صنف های مجاز جهت استفاده
# 'permittedBusinessId'=>[{put permitted Business Ids}], # شناسه کسب و کارهای مجاز جهت استفاده
# 'permittedProductId'=>[{put permitted Product Ids}], # لیست شناسه محصولات مجاز جهت استفاده
# 'currencyCode' => '', # کد ارز IRR
# 'scVoucherHash' => ['{Put Service Call Voucher Hashes}'],
# 'scApiKey' => '{Put service call Api Key}',
];
try {
$result = $SubscriptionService->subscriptionPlanList($param);
print_r($result);
}
catch (ValidationException $e) {
print_r($e->getResult());
print_r($e->getErrorsAsArray());
} catch (PodException $e) {
print_r($e->getResult());
}
}
//subscriptionPlanList();
//die();
# =============================================== update Subscription Plan =============================================
function updateSubscriptionPlan()
{
global $SubscriptionService;
$param =
[
## ================================= Required Parameters ===============================
'id' => '{plan id}', # شناسه طرح
## ================================ Optional Parameters ================================
'periodTypeCode' => '{put perido type code}', #کد نوع بازه زمانی (روزانه، ماهانه، سالانه)
'periodTypeCount' => '{put period type count}', #تعداد مورد نظر از بازه زمانی
'usageCountLimit' => '{put usage count limit}', #محدودیت تعداد دفعات استفاده
'usageAmountLimit' => '{put usage amount limit}', #محدودیت میزان مبلغ قابل استفاده
'name' => 'plan name', # نام طرح
'price' => '{put price}', # قیمت
'enable' => '{true/false}', #فعال/غیرفعال بودن طرح
# 'scVoucherHash' => ['{Put Service Call Voucher Hashes}'],
# 'scApiKey' => '{Put service call Api Key}',
];
try {
$result = $SubscriptionService->updateSubscriptionPlan($param);
print_r($result);
}
catch (ValidationException $e) {
print_r($e->getResult());
print_r($e->getErrorsAsArray());
} catch (PodException $e) {
print_r($e->getResult());
}
}
//updateSubscriptionPlan();
//die();
# ============================================ request Subscription ====================================================
function requestSubscription()
{
global $SubscriptionService;
$param =
[
## ============================== Required Parameters ==============================
'subscriptionPlanId' => '{put subscription plan id}', # شناسه طرح
'userId' => '{put user id}', # شناسه کاربر
## ============================== Optional Parameters ===============================
# 'scVoucherHash' => ['{Put Service Call Voucher Hashes}'],
# 'scApiKey' => '{Put service call Api Key}',
];
try {
$result = $SubscriptionService->requestSubscription($param);
print_r($result);
}
catch (ValidationException $e) {
print_r($e->getResult());
print_r($e->getErrorsAsArray());
} catch (PodException $e) {
print_r($e->getResult());
}
}
requestSubscription();
die();
# ================================================ confirm Subscription ================================================
function confirmSubscription()
{
global $SubscriptionService;
$param =
[
## ========================= Required Parameters ==================================
'subscriptionId' => '{put subscription id}', # شناسه درخواست جهت تایید
'code' => '{put code}', # کد پیامک شده
## ========================= Optional Parameters ===================================
# 'scVoucherHash' => ['{Put Service Call Voucher Hashes}'],
# 'scApiKey' => '{Put service call Api Key}',
];
try {
$result = $SubscriptionService->confirmSubscription($param);
print_r($result);
}
catch (ValidationException $e) {
print_r($e->getResult());
print_r($e->getErrorsAsArray());
} catch (PodException $e) {
print_r($e->getResult());
}
}
#confirmSubscription();
#die();
# ============================================== subscription List =====================================================
function subscriptionList()
{
global $SubscriptionService;
$param =
[
## ============================ Required Parameters ====================================
'offset' => '{put offset}',
'size' => '{put size}',
'subscriptionPlanId' => '{put subscription plan id}',
## ============================ Optional Parameters ====================================
# 'scVoucherHash' => ['{Put Service Call Voucher Hashes}'],
# 'scApiKey' => '{Put service call Api Key}',
];
try {
$result = $SubscriptionService->subscriptionList($param);
print_r($result);
}
catch (ValidationException $e) {
print_r($e->getResult());
print_r($e->getErrorsAsArray());
} catch (PodException $e) {
print_r($e->getResult());
}
}
#subscriptionList();
#die();
# ============================================= consume Subscription ===================================================
function consumeSubscription()
{
global $SubscriptionService;
$param =
[
## ============================ Required Parameters =================================
'id' => '{put plan id}', # plan id
## ============================ Optional Parameters ==================================
// 'usedAmount' => {used amount},
# 'scVoucherHash' => ['{Put Service Call Voucher Hashes}'],
# 'scApiKey' => '{Put service call Api Key}',
];
try {
$result = $SubscriptionService->consumeSubscription($param);
print_r($result);
}
catch (ValidationException $e) {
print_r($e->getResult());
print_r($e->getErrorsAsArray());
} catch (PodException $e) {
print_r($e->getResult());
}
}
#consumeSubscription();
#die();