|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class RefundService extends PaymentService{ |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Return money to the previously charged credit card. |
|
7
|
|
|
* @return PaymentResponse encapsulated response info |
|
8
|
|
|
*/ |
|
9
|
|
|
public function refund($data = array()) { |
|
10
|
|
|
if ($this->payment->Status !== 'Captured') { |
|
|
|
|
|
|
11
|
|
|
return null; //could be handled better? send payment response? |
|
12
|
|
|
} |
|
13
|
|
|
if (!$this->payment->isInDB()) { |
|
14
|
|
|
$this->payment->write(); |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
if(empty($data['receipt'])) { |
|
18
|
|
|
return null; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
$message = $this->createMessage('RefundRequest'); |
|
22
|
|
|
$message->write(); |
|
23
|
|
|
$request = $this->oGateway()->refund(array_merge( |
|
24
|
|
|
$data, |
|
25
|
|
|
array( |
|
26
|
|
|
'amount' => (float) $this->payment->MoneyAmount, |
|
|
|
|
|
|
27
|
|
|
'receipt' => (int) $data['receipt'], |
|
28
|
|
|
) |
|
29
|
|
|
)); |
|
30
|
|
|
$this->logToFile($request->getParameters(), 'RefundRequest_post'); |
|
31
|
|
|
$gatewayresponse = $this->createGatewayResponse(); |
|
32
|
|
|
try { |
|
33
|
|
|
$response = $this->response = $request->send(); |
|
34
|
|
|
//update payment model |
|
35
|
|
|
if ($response->isSuccessful()) { |
|
36
|
|
|
//successful payment |
|
37
|
|
|
$this->createMessage('RefundedResponse', $response); |
|
38
|
|
|
$this->payment->Status = 'Refunded'; |
|
|
|
|
|
|
39
|
|
|
$gatewayresponse->setMessage('Payment refunded'); |
|
40
|
|
|
$this->payment->extend('onRefunded', $gatewayresponse); |
|
41
|
|
View Code Duplication |
} else { |
|
|
|
|
|
|
42
|
|
|
//handle error |
|
43
|
|
|
$this->createMessage('RefundError', $response); |
|
44
|
|
|
$gatewayresponse->setMessage( |
|
45
|
|
|
"Error (".$response->getCode()."): ".$response->getMessage() |
|
46
|
|
|
); |
|
47
|
|
|
} |
|
48
|
|
|
$this->payment->write(); |
|
49
|
|
|
$gatewayresponse->setOmnipayResponse($response); |
|
50
|
|
|
} catch (Omnipay\Common\Exception\OmnipayException $e) { |
|
51
|
|
|
$this->createMessage('GatewayErrorMessage', $e); |
|
|
|
|
|
|
52
|
|
|
$gatewayresponse->setMessage($e->getMessage()); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
return $gatewayresponse; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
|
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.