1: <?php
2:
3: /**
4: * Process a refund
5: * @see https://app.syspay.com/bundles/emiuser/doc/merchant_api.html#make-a-refund
6: */
7: class Syspay_Merchant_RefundRequest extends Syspay_Merchant_Request
8: {
9: const METHOD = 'POST';
10: const PATH = '/api/v1/merchant/refund';
11:
12: /**
13: * @var integer
14: */
15: private $paymentId;
16:
17: /**
18: * @var Syspay_Merchant_Entity_Refund
19: */
20: private $refund;
21:
22: /**
23: * @var string
24: */
25: private $emsUrl;
26:
27: /**
28: * {@inheritDoc}
29: */
30: public function getMethod()
31: {
32: return self::METHOD;
33: }
34:
35: /**
36: * {@inheritDoc}
37: */
38: public function getPath()
39: {
40: return self::PATH;
41: }
42:
43: /**
44: * {@inheritDoc}
45: */
46: public function buildResponse(stdClass $response)
47: {
48: if (!isset($response->refund)) {
49: throw new Syspay_Merchant_UnexpectedResponseException(
50: 'Unable to retrieve "refund" data from response',
51: $response
52: );
53: }
54:
55: $refund = Syspay_Merchant_Entity_Refund::buildFromResponse($response->refund);
56:
57: return $refund;
58: }
59:
60: /**
61: * {@inheritDoc}
62: */
63: public function getData()
64: {
65: $data = $this->refund->toArray();
66: $data['payment_id'] = $this->paymentId;
67:
68: if (false === empty($this->emsUrl)) {
69: $data['ems_url'] = $this->emsUrl;
70: }
71:
72: return $data;
73: }
74:
75:
76: /**
77: * Gets the value of paymentId.
78: *
79: * @return integer
80: */
81: public function getPaymentId()
82: {
83: return $this->paymentId;
84: }
85:
86: /**
87: * Sets the value of paymentId.
88: *
89: * @param integer $paymentId the paymentId
90: *
91: * @return self
92: */
93: public function setPaymentId($paymentId)
94: {
95: $this->paymentId = $paymentId;
96:
97: return $this;
98: }
99:
100: /**
101: * Gets the value of refund.
102: *
103: * @return Syspay_Merchant_Entity_Refund
104: */
105: public function getRefund()
106: {
107: return $this->refund;
108: }
109:
110: /**
111: * Sets the value of refund.
112: *
113: * @param Syspay_Merchant_Entity_Refund $refund the refund
114: *
115: * @return self
116: */
117: public function setRefund(Syspay_Merchant_Entity_Refund $refund)
118: {
119: $this->refund = $refund;
120:
121: return $this;
122: }
123:
124: /**
125: * Gets the value of emsUrl.
126: *
127: * @return string
128: */
129: public function getEmsUrl()
130: {
131: return $this->emsUrl;
132: }
133:
134: /**
135: * Sets the value of emsUrl.
136: *
137: * @param string $emsUrl the emsUrl
138: *
139: * @return self
140: */
141: public function setEmsUrl($emsUrl)
142: {
143: $this->emsUrl = $emsUrl;
144:
145: return $this;
146: }
147: }
148: