Invoice   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 119
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 26
c 1
b 0
f 0
dl 0
loc 119
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A verify() 0 6 1
A finalize() 0 7 1
A markAsPaid() 0 7 1
A archive() 0 8 1
A totals() 0 5 1
A notify() 0 6 1
1
<?php
2
3
namespace Digikraaft\Paystack;
4
5
class Invoice extends ApiResource
6
{
7
    const OBJECT_NAME = 'paymentrequest';
8
9
    use ApiOperations\All;
10
    use ApiOperations\Create;
11
    use ApiOperations\Fetch;
12
    use ApiOperations\Update;
13
14
    /**
15
     * @param string $invoice_code details at
16
     *
17
     * @link https://paystack.com/docs/api/#invoice-verify
18
     *
19
     * @return array|object
20
     */
21
    public static function verify(string $invoice_code)
22
    {
23
        $url = "verify/{$invoice_code}";
24
        $url = static::endPointUrl($url);
25
26
        return static::staticRequest('GET', $url);
27
    }
28
29
    /**
30
     * @param string $invoice_id details at
31
     * @param $params
32
     *
33
     * @throws Exceptions\InvalidArgumentException
34
     * @throws Exceptions\IsNullException
35
     *
36
     * @return array|object
37
     *
38
     * @link https://paystack.com/docs/api/#invoice-send-notification
39
     */
40
    public static function notify(string $invoice_id, $params)
41
    {
42
        $url = "notify/{$invoice_id}";
43
        $url = static::endPointUrl($url);
44
45
        return static::staticRequest('POST', $url, $params);
46
    }
47
48
    /**
49
     * Get invoice totals for dashboard.
50
     *
51
     * @link https://paystack.com/docs/api/#invoice-total
52
     *
53
     * @throws Exceptions\InvalidArgumentException
54
     * @throws Exceptions\IsNullException
55
     *
56
     * @return array|object
57
     */
58
    public static function totals()
59
    {
60
        $url = static::endPointUrl('totals');
61
62
        return static::staticRequest('GET', $url);
63
    }
64
65
    /**
66
     * @param string $invoice_id
67
     * @param array  $params
68
     *
69
     * @throws Exceptions\InvalidArgumentException
70
     * @throws Exceptions\IsNullException
71
     *
72
     * @return array|object
73
     *
74
     * @link https://paystack.com/docs/api/#invoice-finalize
75
     */
76
    public static function finalize($invoice_id, $params = null)
77
    {
78
        self::validateParams($params);
79
        $url = "finalize/{$invoice_id}";
80
        $url = static::endPointUrl($url);
81
82
        return static::staticRequest('POST', $url, $params);
83
    }
84
85
    /**
86
     * @param string     $invoice_id
87
     * @param null|array $params
88
     *
89
     * @throws Exceptions\InvalidArgumentException
90
     * @throws Exceptions\IsNullException
91
     *
92
     * @return array|object
93
     *
94
     * @link https://paystack.com/docs/api/#invoice-archive
95
     */
96
    public static function archive($invoice_id, $params)
97
    {
98
        self::validateParams($params);
99
100
        $url = "archive/{$invoice_id}";
101
        $url = static::endPointUrl($url);
102
103
        return static::staticRequest('POST', $url, $params);
104
    }
105
106
    /**
107
     * @param string $invoice_id
108
     * @param array  $params
109
     *
110
     * @throws Exceptions\InvalidArgumentException
111
     * @throws Exceptions\IsNullException
112
     *
113
     * @return array|object
114
     *
115
     * @link https://developers.paystack.co/reference#mark_as_paid
116
     */
117
    public static function markAsPaid($invoice_id, $params)
118
    {
119
        self::validateParams($params, true);
120
        $url = "mark_as_paid/{$invoice_id}";
121
        $url = static::endPointUrl($url);
122
123
        return static::staticRequest('POST', $url);
124
    }
125
}
126