Passed
Pull Request — master (#26)
by
unknown
01:43
created

listMethod()   A

Complexity

Conditions 2
Paths 10

Size

Total Lines 27
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 20
c 2
b 0
f 0
nc 10
nop 0
dl 0
loc 27
rs 9.6
1
<?php
2
3
require_once('../vendor/autoload.php');
4
require_once('../examples/utils/Helpers.php');
5
6
/**
7
 * PLEASE FILL YOUR PUBLIC KEY AND PRIVATE KEY
8
 */
9
const PUBLIC_KEY = ''; //Set your public key
10
const PRIVATE_KEY = ''; //Set your public key
11
12
try {
13
    call_user_func('listMethod');
14
} catch (\Exception $e) {
15
    echo $e->getMessage();
16
    exit;
17
}
18
19
/**
20
 * @throws \Httpful\Exception\ConnectionErrorException
21
 * @throws \Pagantis\OrdersApiClient\Exception\ClientException
22
 * @throws Exception
23
 */
24
function listMethod()
25
{
26
    $queryString = array(
27
        'channel' => 'ONLINE',
28
        'pageSize' => 2,
29
        'page' => 1,
30
        'status' => \Pagantis\OrdersApiClient\Model\Order::STATUS_CONFIRMED
31
    );
32
    try {
33
        $withDate = true;
34
        $fileName = basename(__FILE__);
35
        writeLog('Creating Client', $fileName,$withDate);
36
        $orderApiClient = new \Pagantis\OrdersApiClient\Client(
37
            PUBLIC_KEY,
38
            PRIVATE_KEY
39
        );
40
        writeLog('Client Created', $fileName,$withDate);
41
        writeLog('Fetching Orders', $fileName,$withDate);
42
        /** WARNING: orders must be confirmed on your back office or you will get a empty object */
43
        $orders = $orderApiClient->listOrders($queryString);
44
        writeLog('Orders Fetched', $fileName,$withDate);
45
46
        writeLog(jsonEncoded($orders), $fileName,$withDate);
47
        print("<pre>" . print_r($orders, true) . "</pre>");
48
49
    } catch (\Exception $exception) {
50
        $exception->getMessage();
51
    }
52
}
53
54
55
56
/**
57
 * @return \Pagantis\OrdersApiClient\Client
58
 * @throws \Httpful\Exception\ConnectionErrorException
59
 * @throws \Pagantis\OrdersApiClient\Exception\ClientException
60
 */
61
function getClient()
62
{
63
    if (PUBLIC_KEY == '' || PRIVATE_KEY == '') {
0 ignored issues
show
introduced by
The condition PUBLIC_KEY == '' is always true.
Loading history...
64
        throw new \Exception('You need set the public and private key');
65
    }
66
    $orderClient = new \Pagantis\OrdersApiClient\Client(PUBLIC_KEY, PRIVATE_KEY);
67
    return $orderClient;
68
}
69
70