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

refundOrder()   A

Complexity

Conditions 2
Paths 14

Size

Total Lines 28
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 23
c 1
b 0
f 0
nc 14
nop 0
dl 0
loc 28
rs 9.552
1
<?php
2
3
require_once('../vendor/autoload.php');
4
require_once ('../examples/utils/Helpers.php');
5
6
7
/**
8
 * PLEASE FILL YOUR PUBLIC KEY AND PRIVATE KEY
9
 */
10
const PUBLIC_KEY = ''; //Set your public key
11
const PRIVATE_KEY = ''; //Set your public key
12
13
14
try {
15
    call_user_func('refundOrder');
16
} catch (\Exception $e) {
17
    echo $e->getMessage();
18
    exit;
19
}
20
21
function refundOrder()
22
{
23
    $asJson = true;
24
    $withDate = true;
25
    $fileName = basename(__FILE__);
26
    $refundTotalAmount = $_POST['refundOrderAmount'];
27
    $refundOrderID = $_POST['refundOrderID'];
28
    try {
29
        writeLog('Creating Client', $fileName,$withDate);
30
        $orderApiClient = getClient();
31
        writeLog('Client Created', $fileName,$withDate);
32
        writeLog('Setting Refund', $fileName,$withDate);
33
        $refund = new \Pagantis\OrdersApiClient\Model\Order\Refund();
34
        $refund
35
            ->setPromotedAmount(0)
36
            ->setTotalAmount($refundTotalAmount);
37
        writeLog('Refund Set', $fileName,$withDate);
38
        $refundCreated = $orderApiClient->refundOrder($refundOrderID, $refund);
39
        writeLog(jsonEncoded($refundCreated), $fileName,$withDate);
40
41
        $refundedOrder = $orderApiClient->getOrder($refundOrderID, $asJson);
42
        $refundsArray = jsonToArray($refundedOrder);
43
44
        echo jsonEncoded($refundsArray['refunds']);
45
        print("<pre>" . print_r($refundsArray['refunds'], true) . "</pre>");
46
47
    } catch (\Exception $exception) {
48
        $exception->getMessage();
49
    }
50
}
51
52
53
54
/**
55
 * @return \Pagantis\OrdersApiClient\Client
56
 * @throws \Httpful\Exception\ConnectionErrorException
57
 * @throws \Pagantis\OrdersApiClient\Exception\ClientException
58
 */
59
function getClient()
60
{
61
    if (PUBLIC_KEY == '' || PRIVATE_KEY == '') {
0 ignored issues
show
introduced by
The condition PUBLIC_KEY == '' is always true.
Loading history...
62
        throw new \Exception('You need set the public and private key');
63
    }
64
    $orderClient = new \Pagantis\OrdersApiClient\Client(PUBLIC_KEY, PRIVATE_KEY);
65
    return $orderClient;
66
}
67