1: <?php
2:
3: /**
4: * Create an eterminal instance
5: *
6: * @see https://app.syspay.com/bundles/emiuser/doc/merchant_eterminal.html
7: */
8: class Syspay_Merchant_EterminalRequest extends Syspay_Merchant_Request
9: {
10: const METHOD = 'POST';
11: const PATH = '/api/v1/merchant/eterminal';
12:
13: const TYPE_ONESHOT = 'ONESHOT';
14: const TYPE_SUBSCRIPTION = 'SUBSCRIPTION';
15: const TYPE_PAYMENT_PLAN = 'PAYMENT_PLAN';
16: const TYPE_PAYMENT_MANDATE = 'PAYMENT_MANDATE';
17:
18: /**
19: * @var integer
20: */
21: protected $website;
22:
23: /**
24: * @var boolean
25: */
26: protected $locked;
27:
28: /**
29: * @var string
30: */
31: protected $emsUrl;
32:
33: /**
34: * @var string
35: */
36: protected $paymentRedirectUrl;
37:
38: /**
39: * @var string
40: */
41: protected $eterminalRedirectUrl;
42:
43: /**
44: * @var string
45: */
46: protected $type;
47:
48: /**
49: * @var string
50: */
51: protected $description;
52:
53: /**
54: * @var string
55: */
56: protected $reference;
57:
58: /**
59: * @var array
60: */
61: protected $customer;
62:
63: /**
64: * @var array
65: */
66: protected $oneshot;
67:
68: /**
69: * @var array
70: */
71: protected $subscription;
72:
73: /**
74: * @var array
75: */
76: protected $paymentPlan;
77:
78: /**
79: * @var array
80: */
81: protected $paymentMandate;
82:
83: /**
84: * @var integer
85: */
86: protected $allowedRetries;
87:
88:
89: /**
90: * {@inheritDoc}
91: */
92: public function getMethod()
93: {
94: return self::METHOD;
95: }
96:
97: /**
98: * {@inheritDoc}
99: */
100: public function getPath()
101: {
102: return sprintf(self::PATH);
103: }
104:
105: /**
106: * {@inheritDoc}
107: */
108: public function buildResponse(stdClass $response)
109: {
110: if (!isset($response->eterminal)) {
111: throw new Syspay_Merchant_UnexpectedResponseException(
112: 'Unable to retrieve "eterminal" data from response',
113: $response
114: );
115: }
116:
117: $eterminal = Syspay_Merchant_Entity_Eterminal::buildFromResponse($response->eterminal);
118:
119: return $eterminal;
120: }
121:
122: /**
123: * Gets the value of website.
124: *
125: * @return integer
126: */
127: public function getWebsite()
128: {
129: return $this->website;
130: }
131:
132: /**
133: * Sets the value of website.
134: *
135: * @param integer $website the website id
136: *
137: * @return self
138: */
139: public function setWebsite($website)
140: {
141: $this->website = $website;
142:
143: return $this;
144: }
145:
146:
147: /**
148: * Gets the value of allowedRetries.
149: *
150: * @return integer
151: */
152: public function getAllowedRetries()
153: {
154: return $this->allowedRetries;
155: }
156:
157: /**
158: * Sets the value of allowedRetries.
159: *
160: * @param integer $allowedRetries
161: *
162: * @return self
163: */
164: public function setAllowedRetries($allowedRetries)
165: {
166: $this->allowedRetries = $allowedRetries;
167:
168: return $this;
169: }
170:
171:
172:
173: /**
174: * Gets the value of locked.
175: *
176: * @return boolean
177: */
178: public function getLocked()
179: {
180: return $this->locked;
181: }
182:
183: /**
184: * Sets the value of locked.
185: *
186: * @param boolean $locked the locked
187: *
188: * @return self
189: */
190: public function setLocked($locked)
191: {
192: $this->locked = $locked;
193:
194: return $this;
195: }
196:
197: /**
198: * Gets the value of emsUrl.
199: *
200: * @return string
201: */
202: public function getEmsUrl()
203: {
204: return $this->emsUrl;
205: }
206:
207: /**
208: * Sets the value of emsUrl.
209: *
210: * @param string $emsUrl the emsUrl
211: *
212: * @return self
213: */
214: public function setEmsUrl($emsUrl)
215: {
216: $this->emsUrl = $emsUrl;
217:
218: return $this;
219: }
220:
221: /**
222: * Gets the value of paymentRedirectUrl.
223: *
224: * @return string
225: */
226: public function getPaymentRedirectUrl()
227: {
228: return $this->paymentRedirectUrl;
229: }
230:
231: /**
232: * Sets the value of paymentRedirectUrl.
233: *
234: * @param string $paymentRedirectUrl the paymentRedirectUrl
235: *
236: * @return self
237: */
238: public function setPaymentRedirectUrl($paymentRedirectUrl)
239: {
240: $this->paymentRedirectUrl = $paymentRedirectUrl;
241:
242: return $this;
243: }
244:
245: /**
246: * Gets the value of PostProcessRedirectUrl.
247: *
248: * @return string
249: */
250: public function getEterminalRedirectUrl()
251: {
252: return $this->eterminalRedirectUrl;
253: }
254:
255: /**
256: * Sets the value of postProcessRedirectUrl.
257: *
258: * @param string $postProcessRedirectUrl the postProcessRedirectUrl
259: *
260: * @return self
261: */
262: public function setEterminalRedirectUrl($eterminalRedirectUrl)
263: {
264: $this->eterminalRedirectUrl = $eterminalRedirectUrl;
265:
266: return $this;
267: }
268:
269: /**
270: * Gets the value of type.
271: *
272: * @return string
273: */
274: public function getType()
275: {
276: return $this->type;
277: }
278:
279: /**
280: * Sets the value of type.
281: *
282: * @param string $type the type
283: *
284: * @return self
285: */
286: public function setType($type)
287: {
288: $this->type = $type;
289:
290: return $this;
291: }
292:
293:
294: /**
295: * Gets the value of description.
296: *
297: * @return string
298: */
299: public function getDescription()
300: {
301: return $this->description;
302: }
303:
304: /**
305: * Sets the value of description.
306: *
307: * @param string $description the description
308: *
309: * @return self
310: */
311: public function setDescription($description)
312: {
313: $this->description = $description;
314:
315: return $this;
316: }
317:
318: /**
319: * Gets the value of reference.
320: *
321: * @return string
322: */
323: public function getReference()
324: {
325: return $this->reference;
326: }
327:
328: /**
329: * Sets the value of reference.
330: *
331: * @param string $reference the reference
332: *
333: * @return self
334: */
335: public function setReference($reference)
336: {
337: $this->reference = $reference;
338:
339: return $this;
340: }
341:
342: /**
343: * Gets the value of customer.
344: *
345: * @return array
346: */
347: public function getCustomer()
348: {
349: return $this->customer;
350: }
351:
352: /**
353: * Sets the value of customer.
354: *
355: * @param array $customer the customer
356: *
357: * @return self
358: */
359: public function setCustomer(array $customer)
360: {
361: $this->customer = $customer;
362:
363: return $this;
364: }
365:
366: /**
367: * Gets the value of oneshot.
368: *
369: * @return array
370: */
371: public function getOneshot()
372: {
373: return $this->oneshot;
374: }
375:
376: /**
377: * Sets the value of oneshot.
378: *
379: * @param array $oneshot the oneshot
380: *
381: * @return self
382: */
383: public function setOneshot(array $oneshot)
384: {
385: $this->oneshot = $oneshot;
386:
387: return $this;
388: }
389:
390: /**
391: * Gets the value of subscription.
392: *
393: * @return array
394: */
395: public function getSubscription()
396: {
397: return $this->subscription;
398: }
399:
400: /**
401: * Sets the value of subscription.
402: *
403: * @param array $subscription the subscription
404: *
405: * @return self
406: */
407: public function setSubscription(array $subscription)
408: {
409: $this->subscription = $subscription;
410:
411: return $this;
412: }
413:
414: /**
415: * Gets the value of paymentPlan.
416: *
417: * @return array
418: */
419: public function getPaymentPlan()
420: {
421: return $this->paymentPlan;
422: }
423:
424: /**
425: * Sets the value of paymentPlan.
426: *
427: * @param array $paymentPlan the paymentPlan
428: *
429: * @return self
430: */
431: public function setPaymentPlan(array $paymentPlan)
432: {
433: $this->paymentPlan = $paymentPlan;
434:
435: return $this;
436: }
437:
438: /**
439: * Gets the value of paymentMandate.
440: *
441: * @return array
442: */
443: public function getPaymentMandate()
444: {
445: return $this->paymentMandate;
446: }
447:
448: /**
449: * Sets the value of paymentMandate.
450: *
451: * @param array $paymentMandate the paymentMandate
452: *
453: * @return self
454: */
455: public function setPaymentMandate(array $paymentMandate)
456: {
457: $this->paymentMandate = $paymentMandate;
458:
459: return $this;
460: }
461:
462:
463: /**
464: * Get the data to send to the API for the request
465: * @return array An array of data that will be json-encoded by the Syspay_Merchant_Client
466: */
467: public function getData()
468: {
469: $data = array();
470: $data['locked'] = true == $this->locked ? true : false;
471: $data['type'] = $this->type;
472:
473: if (false === empty($this->website)) {
474: $data['website'] = intval($this->website);
475: }
476:
477: if (false === empty($this->emsUrl)) {
478: $data['ems_url'] = $this->emsUrl;
479: }
480:
481: if (false == empty($this->paymentRedirectUrl)) {
482: $data['payment_page_redirect_url'] = $this->paymentRedirectUrl;
483: }
484:
485: if (false == empty($this->eterminalRedirectUrl)) {
486: $data['eterminal_redirect_url'] = $this->eterminalRedirectUrl;
487: }
488:
489: if (false === empty($this->description)) {
490: $data['description'] = $this->description;
491: }
492:
493: if (false === empty($this->reference)) {
494: $data['reference'] = $this->reference;
495: }
496:
497: if (false === empty($this->customer)) {
498: $data['customer'] = $this->customer;
499: }
500:
501: if (false === empty($this->oneshot)) {
502: $data['oneshot'] = $this->oneshot;
503: }
504:
505: if (false === empty($this->subscription)) {
506: $data['subscription'] = $this->subscription;
507: }
508:
509: if (false === empty($this->paymentPlan)) {
510: $data['payment_plan'] = $this->paymentPlan;
511: }
512:
513: if (false === empty($this->paymentMandate)) {
514: $data['payment_mandate'] = $this->paymentMandate;
515: }
516:
517: if (false === empty($this->allowedRetries)) {
518: $data['allowed_retries'] = $this->allowedRetries;
519: }
520:
521: return $data;
522: }
523:
524: }
525: