1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Omnipay\PaypalRest\Message; |
4
|
|
|
|
5
|
|
|
use Omnipay\Common\Exception\InvalidRequestException; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @author Ivan Kerin <[email protected]> |
9
|
|
|
* @copyright 2014, Clippings Ltd. |
10
|
|
|
* @license http://spdx.org/licenses/BSD-3-Clause |
11
|
|
|
*/ |
12
|
|
|
class RefundRequest extends AbstractPaypalRequest |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @return string |
16
|
|
|
*/ |
17
|
|
|
public function getEndpoint() |
18
|
|
|
{ |
19
|
|
|
$this->validate('transactionReference', 'type'); |
20
|
|
|
|
21
|
|
|
if (false === in_array($this->getType(), array('sale', 'authorization', 'capture'))) { |
22
|
|
|
throw new InvalidRequestException('Type can only be "sale", "authorization" or "capture"'); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
return "/payments/{$this->getType()}/{$this->getTransactionReference()}/refund"; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function getHttpMethod() |
29
|
|
|
{ |
30
|
|
|
return 'POST'; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @return string |
35
|
|
|
*/ |
36
|
|
|
public function getType() |
37
|
|
|
{ |
38
|
|
|
return $this->getParameter('type'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param string $value |
43
|
|
|
*/ |
44
|
|
|
public function setType($value) |
45
|
|
|
{ |
46
|
|
|
return $this->setParameter('type', $value); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param mixed $data |
51
|
|
|
* @return RefundResponse |
52
|
|
|
*/ |
53
|
|
|
public function sendData($data) |
54
|
|
|
{ |
55
|
|
|
$httpResponse = $this->sendHttpRequest($data); |
56
|
|
|
|
57
|
|
|
return $this->response = new RefundResponse( |
58
|
|
|
$this, |
59
|
|
|
$httpResponse->json(), |
60
|
|
|
$httpResponse->getStatusCode() |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return array |
66
|
|
|
*/ |
67
|
|
|
public function getData() |
68
|
|
|
{ |
69
|
|
|
if ($this->getAmount()) { |
|
|
|
|
70
|
|
|
$this->validate('currency'); |
71
|
|
|
|
72
|
|
|
return array( |
73
|
|
|
'amount' => array( |
74
|
|
|
'total' => $this->getAmount(), |
75
|
|
|
'currency' => $this->getCurrency(), |
76
|
|
|
) |
77
|
|
|
); |
78
|
|
|
} else { |
79
|
|
|
return array(); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: