InvoicesTemplates   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 105
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 5
eloc 18
c 2
b 1
f 0
dl 0
loc 105
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A updateInvoiceTemplate() 0 9 1
A showInvoiceTemplateDetails() 0 7 1
A deleteInvoiceTemplate() 0 7 1
A listInvoiceTemplates() 0 7 1
A createInvoiceTemplate() 0 9 1
1
<?php
2
3
namespace Srmklive\PayPal\Traits\PayPalAPI;
4
5
trait InvoicesTemplates
6
{
7
    /**
8
     * Get list of invoice templates.
9
     *
10
     * @param string $fields
11
     *
12
     * @throws \Throwable
13
     *
14
     * @return array|\Psr\Http\Message\StreamInterface|string
15
     *
16
     * @see https://developer.paypal.com/docs/api/invoicing/v2/#templates_list
17
     */
18
    public function listInvoiceTemplates(string $fields = 'all')
19
    {
20
        $this->apiEndPoint = "v2/invoicing/templates?page={$this->current_page}&page_size={$this->page_size}&fields={$fields}";
21
22
        $this->verb = 'get';
23
24
        return $this->doPayPalRequest();
25
    }
26
27
    /**
28
     * Create a new invoice template.
29
     *
30
     * @param array $data
31
     *
32
     * @throws \Throwable
33
     *
34
     * @return array|\Psr\Http\Message\StreamInterface|string
35
     *
36
     * @see https://developer.paypal.com/docs/api/invoicing/v2/#templates_create
37
     */
38
    public function createInvoiceTemplate(array $data)
39
    {
40
        $this->apiEndPoint = 'v2/invoicing/templates';
41
42
        $this->options['json'] = $data;
43
44
        $this->verb = 'post';
45
46
        return $this->doPayPalRequest();
47
    }
48
49
    /**
50
     * Show details for an existing invoice.
51
     *
52
     * @param string $template_id
53
     *
54
     * @throws \Throwable
55
     *
56
     * @return array|\Psr\Http\Message\StreamInterface|string
57
     *
58
     * @see https://developer.paypal.com/docs/api/invoicing/v2/#templates_get
59
     */
60
    public function showInvoiceTemplateDetails(string $template_id)
61
    {
62
        $this->apiEndPoint = "v2/invoicing/templates/{$template_id}";
63
64
        $this->verb = 'get';
65
66
        return $this->doPayPalRequest();
67
    }
68
69
    /**
70
     * Update an existing invoice template.
71
     *
72
     * @param string $template_id
73
     * @param array  $data
74
     *
75
     * @throws \Throwable
76
     *
77
     * @return array|\Psr\Http\Message\StreamInterface|string
78
     *
79
     * @see https://developer.paypal.com/docs/api/invoicing/v2/#templates_update
80
     */
81
    public function updateInvoiceTemplate(string $template_id, array $data)
82
    {
83
        $this->apiEndPoint = "v2/invoicing/templates/{$template_id}";
84
85
        $this->options['json'] = $data;
86
87
        $this->verb = 'put';
88
89
        return $this->doPayPalRequest();
90
    }
91
92
    /**
93
     * Delete an invoice template.
94
     *
95
     * @param string $template_id
96
     *
97
     * @throws \Throwable
98
     *
99
     * @return array|\Psr\Http\Message\StreamInterface|string
100
     *
101
     * @see https://developer.paypal.com/docs/api/invoicing/v2/#templates_delete
102
     */
103
    public function deleteInvoiceTemplate(string $template_id)
104
    {
105
        $this->apiEndPoint = "v2/invoicing/templates/{$template_id}";
106
107
        $this->verb = 'delete';
108
109
        return $this->doPayPalRequest(false);
110
    }
111
}
112