forked from wellnessliving/wl-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample-sdk.php
75 lines (63 loc) · 2.21 KB
/
example-sdk.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
<?php
namespace WlSdkExample;
use WellnessLiving\Core\Passport\Login\Enter\EnterModel;
use WellnessLiving\Core\Passport\Login\Enter\NotepadModel;
use WellnessLiving\Wl\Report\DataModel;
use WellnessLiving\Wl\Report\WlReportGroupSid;
use WellnessLiving\Wl\Report\WlReportSid;
use WellnessLiving\WlAssertException;
use WellnessLiving\WlRegionSid;
use WellnessLiving\WlUserException;
require_once __DIR__.'/WellnessLiving/wl-autoloader.php';
require_once __DIR__.'/example-config.php';
try
{
$o_config=ExampleConfig::create(WlRegionSid::US_EAST_1);
// Retrieve notepad (it is a separate step of user sign in process)
$o_notepad=new NotepadModel($o_config);
$o_request=$o_notepad->get();
// Approach to get debugging information.
echo $o_request->httpProtocol() . PHP_EOL . PHP_EOL;
// Sign in a user.
$o_enter=new EnterModel($o_config);
$o_enter->cookieSet($o_notepad->cookieGet()); // Keep cookies to keep session.
$o_enter->s_login='/** Put your login here */';
$o_enter->s_notepad=$o_notepad->s_notepad;
$o_enter->s_password=$o_notepad->hash('/** Put your password here */');
$o_enter->post();
// Another approach to get debugging information.
echo $o_enter->lastRequest()->httpProtocol(). PHP_EOL;
$o_report=new DataModel($o_config);
$o_report->cookieSet($o_notepad->cookieGet()); // Keep cookies to keep session.
$o_report->id_report_group=WlReportGroupSid::DAY;
$o_report->id_report=WlReportSid::PURCHASE_ITEM_ACCRUAL_CASH;
$o_report->k_business='/** Put your business ID here */'; // Put your business key here
$o_report->filterSet([
'dt_date' => '2018-08-21'
]);
$o_report->get();
$i=0;
foreach($o_report->a_data['a_row'] as $a_row)
{
$i++;
echo $i.'. '.$a_row['dt_date'].' '.$a_row['m_paid']['m_amount'].' '.$a_row['o_user']['text_name'].' '.$a_row['s_item']. PHP_EOL;
}
}
catch(WlAssertException $e)
{
echo $e;
echo PHP_EOL;
return;
}
catch(WlUserException $e)
{
echo $e->getMessage()."\n";
// Approach to get debugging information in a case of exception.
if ($e->request()) {
echo PHP_EOL . PHP_EOL . $e->request()->httpProtocol() . PHP_EOL;
}
echo PHP_EOL;
return;
}
echo PHP_EOL;
?>