CollectApi::getApiEndpoint()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 1
crap 1
1
<?php
2
3
namespace PayumTW\Collect;
4
5
use Carbon\Carbon;
6
7
class CollectApi extends CollectUnionpayApi
8
{
9
    /**
10
     * @return string
11
     */
12 1
    public function getApiEndpoint($type = 'capture')
13
    {
14
        $urls = [
15 1
            'capture' => 'https://4128888card.com.tw/cocs/client_order_append.php',
16 1
            'cancel' => 'https://4128888card.com.tw/cocs/client_order_cancel.php',
17 1
            'refund' => 'https://4128888card.com.tw/cocs/client_order_refund.php',
18 1
        ];
19
        // return $this->options['sandbox'] ? 'https://4128888card.com.tw/cocs/client_order_append.php' : 'https://4128888card.com.tw/cocs/client_order_append.php';
20
21 1
        return $urls[$type];
22
    }
23
24
    /**
25
     * cancelTransaction.
26
     *
27
     * @param array $params
28
     * @return array
29
     */
30 1
    public function cancelTransaction(array $params)
31
    {
32
        $supportedParams = [
33 1
            'link_id' => $this->options['link_id'],
34 1
            'cust_order_no' => null,
35 1
            'order_amount' => null,
36 1
            'send_time' => Carbon::now(static::TIMEZONE)->toDateTimeString(),
37
            /*
38
             * 回傳方式
39
             * redirect(直接重新導向)、
40
             * plain(純文字)、
41
             * xml(XML 格 式)、
42
             * json(JSON 格式)。
43
             */
44 1
            'return_type' => 'json',
45 1
        ];
46
47 1
        $params = array_filter(array_replace(
48 1
            $supportedParams,
49 1
            array_intersect_key($params, $supportedParams)
50 1
        ));
51
52 1
        $params['chk'] = $this->calculateHash($params, [
53 1
            'cust_order_no', 'order_amount', 'send_time',
54 1
        ]);
55
56 1
        return $this->doRequest('GET', $params, 'cancel');
57
    }
58
}
59