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