Passed
Push — main ( 4a5f0c...02f3c9 )
by MyFatoorah
06:23 queued 02:44
created

MyFatoorahRefund   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 47
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 2021 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
     * @param int|string        $keyId        payment id that will be refunded
23
     * @param double|int|string $amount       the refund amount
24
     * @param string            $currencyCode the amount currency
25
     * @param string            $comment      reason of the refund
26
     * @param int|string        $orderId      used in log file (default value: null)
27
     * @param string            $keyType      supported keys are (InvoiceId, PaymentId)
28
     *
29
     * @return object
30
     */
31
    public function refund($keyId, $amount, $currencyCode = null, $comment = null, $orderId = null, $keyType = 'PaymentId')
32
    {
33
        $postFields = [
34
            'Key'                     => $keyId,
35
            'KeyType'                 => $keyType,
36
            'RefundChargeOnCustomer'  => false,
37
            'ServiceChargeOnCustomer' => false,
38
            'Amount'                  => $amount,
39
            'CurrencyIso'             => $currencyCode,
40
            'Comment'                 => $comment,
41
        ];
42
43
        return $this->makeRefund($postFields, $orderId);
44
    }
45
46
    //-----------------------------------------------------------------------------------------------------------------------------------------
47
48
    /**
49
     * Call makeRefund API (POST API)
50
     *
51
     * @param array      $curlData Refund information
52
     * @param int|string $orderId  Used in log file (default value: null)
53
     *
54
     * @return object
55
     */
56
    public function makeRefund($curlData, $orderId = null)
57
    {
58
        $url  = "$this->apiURL/v2/MakeRefund";
59
        $json = $this->callAPI($url, $curlData, $orderId, 'Make Refund');
60
        return $json->Data;
61
    }
62
63
    //-----------------------------------------------------------------------------------------------------------------------------------------
64
}
65