1 | <?php |
||
2 | |||
3 | namespace Srmklive\PayPal\Traits\PayPalAPI; |
||
4 | |||
5 | use GuzzleHttp\Psr7; |
||
6 | use Srmklive\PayPal\Services\VerifyDocuments; |
||
7 | |||
8 | trait DisputesActions |
||
9 | { |
||
10 | /** |
||
11 | * Acknowledge item has been returned. |
||
12 | * |
||
13 | * @param string $dispute_id |
||
14 | * @param string $dispute_note |
||
15 | * @param string $acknowledgement_type |
||
16 | * |
||
17 | * @throws \Throwable |
||
18 | * |
||
19 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
20 | * |
||
21 | * @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes-actions_acknowledge-return-item |
||
22 | */ |
||
23 | public function acknowledgeItemReturned(string $dispute_id, string $dispute_note, string $acknowledgement_type) |
||
24 | { |
||
25 | $this->apiEndPoint = "v1/customer/disputes/{$dispute_id}/acknowledge-return-item"; |
||
26 | |||
27 | $this->options['json'] = [ |
||
28 | 'note' => $dispute_note, |
||
29 | 'acknowledgement_type' => $acknowledgement_type, |
||
30 | ]; |
||
31 | |||
32 | $this->verb = 'post'; |
||
33 | |||
34 | return $this->doPayPalRequest(); |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * Providence evidence in support of a dispute. |
||
39 | * |
||
40 | * @param string $dispute_id |
||
41 | * @param array $file_path |
||
42 | * |
||
43 | * @throws \Throwable |
||
44 | * |
||
45 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
46 | * |
||
47 | * https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_provide-evidence |
||
48 | */ |
||
49 | public function provideDisputeEvidence(string $dispute_id, array $files) |
||
50 | { |
||
51 | if (VerifyDocuments::isValidEvidenceFile($files) === false) { |
||
52 | $this->throwInvalidEvidenceFileException(); |
||
53 | } |
||
54 | |||
55 | $this->apiEndPoint = "/v1/customer/disputes/{$dispute_id}/provide-evidence"; |
||
56 | |||
57 | $this->setRequestHeader('Content-Type', 'multipart/form-data'); |
||
58 | |||
59 | $this->options['multipart'] = []; |
||
60 | |||
61 | foreach ($files as $file) { |
||
62 | $this->options['multipart'][] = [ |
||
63 | 'name' => basename($file), |
||
64 | 'contents' => Psr7\Utils::tryFopen($file, 'r'), |
||
65 | ]; |
||
66 | } |
||
67 | |||
68 | $this->verb = 'post'; |
||
69 | |||
70 | return $this->doPayPalRequest(); |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * Make offer to resolve dispute claim. |
||
75 | * |
||
76 | * @param string $dispute_id |
||
77 | * @param string $dispute_note |
||
78 | * @param float $amount |
||
79 | * @param string $refund_type |
||
80 | * |
||
81 | * @throws \Throwable |
||
82 | * |
||
83 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
84 | * |
||
85 | * @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_make-offer |
||
86 | */ |
||
87 | public function makeOfferToResolveDispute(string $dispute_id, string $dispute_note, float $amount, string $refund_type) |
||
88 | { |
||
89 | $this->apiEndPoint = "v1/customer/disputes/{$dispute_id}/make-offer"; |
||
90 | |||
91 | $data['note'] = $dispute_note; |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||
92 | $data['offer_type'] = $refund_type; |
||
93 | $data['offer_amount'] = [ |
||
94 | 'currency_code' => $this->getCurrency(), |
||
95 | 'value' => $amount, |
||
96 | ]; |
||
97 | |||
98 | $this->options['json'] = $data; |
||
99 | |||
100 | $this->verb = 'post'; |
||
101 | |||
102 | return $this->doPayPalRequest(); |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * Escalate dispute to claim. |
||
107 | * |
||
108 | * @param string $dispute_id |
||
109 | * @param string $dispute_note |
||
110 | * |
||
111 | * @throws \Throwable |
||
112 | * |
||
113 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
114 | * |
||
115 | * @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_escalate |
||
116 | */ |
||
117 | public function escalateDisputeToClaim(string $dispute_id, string $dispute_note) |
||
118 | { |
||
119 | $this->apiEndPoint = "v1/customer/disputes/{$dispute_id}/escalate"; |
||
120 | |||
121 | $data['note'] = $dispute_note; |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
122 | |||
123 | $this->options['json'] = $data; |
||
124 | |||
125 | $this->verb = 'post'; |
||
126 | |||
127 | return $this->doPayPalRequest(); |
||
128 | } |
||
129 | |||
130 | /** |
||
131 | * Accept offer to resolve dispute. |
||
132 | * |
||
133 | * @param string $dispute_id |
||
134 | * @param string $dispute_note |
||
135 | * |
||
136 | * @throws \Throwable |
||
137 | * |
||
138 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
139 | * |
||
140 | * @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_accept-offer |
||
141 | */ |
||
142 | public function acceptDisputeOfferResolution(string $dispute_id, string $dispute_note) |
||
143 | { |
||
144 | $this->apiEndPoint = "v1/customer/disputes/{$dispute_id}/accept-offer"; |
||
145 | |||
146 | $this->options['json'] = [ |
||
147 | 'note' => $dispute_note, |
||
148 | ]; |
||
149 | |||
150 | $this->verb = 'post'; |
||
151 | |||
152 | return $this->doPayPalRequest(); |
||
153 | } |
||
154 | |||
155 | /** |
||
156 | * Accept customer dispute claim. |
||
157 | * |
||
158 | * @param string $dispute_id |
||
159 | * @param string $dispute_note |
||
160 | * @param array $data |
||
161 | * |
||
162 | * @throws \Throwable |
||
163 | * |
||
164 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
165 | * |
||
166 | * @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_accept-claim |
||
167 | */ |
||
168 | public function acceptDisputeClaim(string $dispute_id, string $dispute_note, array $data = []) |
||
169 | { |
||
170 | $this->apiEndPoint = "v1/customer/disputes/{$dispute_id}/accept-claim"; |
||
171 | |||
172 | $data['note'] = $dispute_note; |
||
173 | $data['accept_claim_type'] = 'REFUND'; |
||
174 | |||
175 | $this->options['json'] = $data; |
||
176 | |||
177 | $this->verb = 'post'; |
||
178 | |||
179 | return $this->doPayPalRequest(); |
||
180 | } |
||
181 | |||
182 | /** |
||
183 | * Update dispute status. |
||
184 | * |
||
185 | * @param string $dispute_id |
||
186 | * @param bool $merchant |
||
187 | * |
||
188 | * @throws \Throwable |
||
189 | * |
||
190 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
191 | * |
||
192 | * @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_require-evidence |
||
193 | */ |
||
194 | public function updateDisputeStatus(string $dispute_id, bool $merchant = true) |
||
195 | { |
||
196 | $this->apiEndPoint = "v1/customer/disputes/{$dispute_id}/require-evidence"; |
||
197 | |||
198 | $data['action'] = ($merchant === true) ? 'SELLER_EVIDENCE' : 'BUYER_EVIDENCE'; |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
199 | |||
200 | $this->options['json'] = $data; |
||
201 | |||
202 | $this->verb = 'post'; |
||
203 | |||
204 | return $this->doPayPalRequest(); |
||
205 | } |
||
206 | |||
207 | /** |
||
208 | * Settle dispute. |
||
209 | * |
||
210 | * @param string $dispute_id |
||
211 | * @param bool $merchant |
||
212 | * |
||
213 | * @throws \Throwable |
||
214 | * |
||
215 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
216 | * |
||
217 | * @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_adjudicate |
||
218 | */ |
||
219 | public function settleDispute(string $dispute_id, bool $merchant = true) |
||
220 | { |
||
221 | $this->apiEndPoint = "v1/customer/disputes/{$dispute_id}/adjudicate"; |
||
222 | |||
223 | $data['adjudication_outcome'] = ($merchant === true) ? 'SELLER_FAVOR' : 'BUYER_FAVOR'; |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
224 | |||
225 | $this->options['json'] = $data; |
||
226 | |||
227 | $this->verb = 'post'; |
||
228 | |||
229 | return $this->doPayPalRequest(); |
||
230 | } |
||
231 | |||
232 | /** |
||
233 | * Decline offer to resolve dispute. |
||
234 | * |
||
235 | * @param string $dispute_id |
||
236 | * @param string $dispute_note |
||
237 | * |
||
238 | * @throws \Throwable |
||
239 | * |
||
240 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
241 | * |
||
242 | * @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_deny-offer |
||
243 | */ |
||
244 | public function declineDisputeOfferResolution(string $dispute_id, string $dispute_note) |
||
245 | { |
||
246 | $this->apiEndPoint = "v1/customer/disputes/{$dispute_id}/deny-offer"; |
||
247 | |||
248 | $this->options['json'] = [ |
||
249 | 'note' => $dispute_note, |
||
250 | ]; |
||
251 | |||
252 | $this->verb = 'post'; |
||
253 | |||
254 | return $this->doPayPalRequest(); |
||
255 | } |
||
256 | } |
||
257 |