MyFatoorahRefund   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 49
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A refund() 0 13 1
A makeRefund() 0 5 1
1
<?php
2
3
namespace MyFatoorah\Library\API;
4
5
use MyFatoorah\Library\MyFatoorah;
6
7
/**
8
 *  MyFatoorahRefund handles the refund process of MyFatoorah API endpoints
9
 *
10
 * @author    MyFatoorah <[email protected]>
11
 * @copyright MyFatoorah, All rights reserved
12
 * @license   GNU General Public License v3.0
13
 */
14
class MyFatoorahRefund extends MyFatoorah
15
{
16
    //-----------------------------------------------------------------------------------------------------------------------------------------
17
18
    /**
19
     * (deprecated function) use makeRefund instead
20
     * Refund a given PaymentId or InvoiceId
21
     *
22
     * @deprecated
23
     *
24
     * @param int|string        $keyId    payment id that will be refunded
25
     * @param double|int|string $amount   the refund amount
26
     * @param string            $currency the amount currency
27
     * @param string            $comment  reason of the refund
28
     * @param int|string        $orderId  used in log file (default value: null)
29
     * @param string            $keyType  supported keys are (InvoiceId, PaymentId)
30
     *
31
     * @return object
32
     */
33
    public function refund($keyId, $amount, $currency = null, $comment = null, $orderId = null, $keyType = 'PaymentId')
34
    {
35
        $postFields = [
36
            'Key'                     => $keyId,
37
            'KeyType'                 => $keyType,
38
            'RefundChargeOnCustomer'  => false,
39
            'ServiceChargeOnCustomer' => false,
40
            'Amount'                  => $amount,
41
            'CurrencyIso'             => $currency,
42
            'Comment'                 => $comment,
43
        ];
44
45
        return $this->makeRefund($postFields, $orderId);
46
    }
47
48
    //-----------------------------------------------------------------------------------------------------------------------------------------
49
50
    /**
51
     * Call makeRefund API (POST API)
52
     *
53
     * @param array      $curlData Refund information
54
     * @param int|string $logId    Used in log file, example you can use the orderId (default value: null)
55
     *
56
     * @return object
57
     */
58
    public function makeRefund($curlData, $logId = null)
59
    {
60
        $url  = "$this->apiURL/v2/MakeRefund";
61
        $json = $this->callAPI($url, $curlData, $logId, 'Make Refund');
62
        return $json->Data;
63
    }
64
65
    //-----------------------------------------------------------------------------------------------------------------------------------------
66
}
67