1: <?php
2:
3: /**
4: * Process a payment
5: *
6: * @see https://app.syspay.com/bundles/emiuser/doc/merchant_api.html#hosted-payment-request
7: * @see https://app.syspay.com/bundles/emiuser/doc/merchant_api.html#server-to-server-credit-card-payment
8: */
9: class Syspay_Merchant_BillingAgreementRequest extends Syspay_Merchant_Request
10: {
11: const FLOW_API = 'API';
12: const FLOW_BUYER = 'BUYER';
13: const FLOW_SELLER = 'SELLER';
14:
15: const MODE_BOTH = 'BOTH';
16: const MODE_ONLINE = 'ONLINE';
17: const MODE_TERMINAL = 'TERMINAL';
18:
19: const METHOD_ASTROPAY_BANKTRANSFER = 'ASTROPAY_BANKTRANSFER';
20: const METHOD_ASTROPAY_BOLETOBANCARIO = 'ASTROPAY_BOLETOBANCARIO';
21: const METHOD_ASTROPAY_DEBITCARD = 'ASTROPAY_DEBITCARD';
22: const METHOD_CLICKANDBUY = 'CLICKANDBUY';
23: const METHOD_CREDITCARD = 'CREDITCARD';
24: const METHOD_IDEAL = 'IDEAL';
25: const METHOD_PAYSAFECARD = 'PAYSAFECARD';
26: const METHOD_POSTFINANCE = 'POSTFINANCE';
27:
28: const METHOD = 'POST';
29: const PATH = '/api/v1/merchant/billing-agreement';
30:
31: /**
32: * @var string
33: */
34: private $flow;
35: /**
36: * @var string
37: */
38: private $mode;
39:
40: /**
41: * @var string
42: */
43: private $paymentMethod;
44:
45:
46: /**
47: * @var string
48: */
49: private $threatMetrixSessionId;
50:
51: /**
52: * @var boolean
53: */
54: private $billingAgreement = false;
55:
56: /**
57: * @var string
58: */
59: private $emsUrl;
60:
61: /**
62: * @var string
63: */
64: private $redirectUrl;
65:
66: /**
67: * @var string
68: */
69: private $website;
70:
71: /**
72: * @var string
73: */
74: private $agent;
75:
76: /**
77: * @var integer
78: */
79: private $allowedRetries;
80:
81: /**
82: * @var Syspay_Merchant_Entity_Payment
83: */
84: private $payment;
85:
86: /**
87: * @var Syspay_Merchant_Entity_Customer
88: */
89: private $customer;
90:
91: /**
92: * @var Syspay_Merchant_Entity_Creditcard
93: */
94: private $creditcard;
95:
96: /**
97: * @var string
98: */
99: private $bankCode;
100:
101: /**
102: * @var String
103: */
104: private $reference;
105:
106: /**
107: * @var String
108: */
109: private $currency;
110:
111: /**
112: * @var string
113: */
114: protected $description;
115:
116: /**
117: * @var string
118: */
119: protected $extra;
120:
121: /**
122: * Consructor
123: *
124: * @param String $flow
125: */
126: public function __construct($flow)
127: {
128: if (!in_array($flow, array(self::FLOW_API, self::FLOW_BUYER, self::FLOW_SELLER))) {
129: throw new InvalidArgumentException('Invalid flow: ' . $flow);
130: }
131:
132: $this->flow = $flow;
133: }
134:
135: /**
136: * {@inheritDoc}
137: */
138: public function getMethod()
139: {
140: return self::METHOD;
141: }
142:
143: /**
144: * {@inheritDoc}
145: */
146: public function getPath()
147: {
148: return self::PATH;
149: }
150:
151: /**
152: * {@inheritDoc}
153: */
154: public function buildResponse(stdClass $response)
155: {
156: if (!isset($response->billing_agreement)) {
157: throw new Syspay_Merchant_UnexpectedResponseException(
158: 'Unable to retrieve "billing_agreement" data from response',
159: $response
160: );
161: }
162:
163: if ($response->billing_agreement) {
164: $billingAgreement = Syspay_Merchant_Entity_BillingAgreement::buildFromResponse($response->billing_agreement);
165: } else {
166: $billingAgreement = new Syspay_Merchant_Entity_BillingAgreement();
167: }
168:
169: if (isset($response->redirect) && !empty($response->redirect)) {
170: $billingAgreement->setRedirect($response->redirect);
171: }
172:
173: return $billingAgreement;
174: }
175:
176: /**
177: * {@inheritDoc}
178: */
179: public function getData()
180: {
181: $data = array();
182: $data['flow'] = $this->flow;
183:
184: if (false === empty($this->billingAgreement)) {
185: $data['billing_agreement'] = $this->billingAgreement?1:0;
186: }
187:
188: if (false === empty($this->mode)) {
189: $data['mode'] = $this->mode;
190: }
191:
192: if (false == empty($this->threatMetrixSessionId)) {
193: $data['threatmetrix_session_id'] = $this->threatMetrixSessionId;
194: }
195:
196: if (false === empty($this->paymentMethod)) {
197: $data['method'] = $this->paymentMethod;
198: }
199:
200: if (false === empty($this->website)) {
201: $data['website'] = $this->website;
202: }
203:
204: if (false === empty($this->agent)) {
205: $data['agent'] = $this->agent;
206: }
207:
208: if (false === empty($this->redirectUrl)) {
209: $data['redirect_url'] = $this->redirectUrl;
210: }
211:
212: if (false === empty($this->emsUrl)) {
213: $data['ems_url'] = $this->emsUrl;
214: }
215:
216: if (false === empty($this->creditcard)) {
217: $data['creditcard'] = $this->creditcard->toArray();
218: }
219:
220: if (false === empty($this->customer)) {
221: $data['customer'] = (array) $this->customer->toArray();
222: }
223:
224: if (false === empty($this->bankCode)) {
225: $data['bank_code'] = $this->bankCode;
226: }
227:
228: if (false === empty($this->reference)) {
229: $data['reference'] = $this->reference;
230: }
231:
232: if (false === empty($this->currency)) {
233: $data['currency'] = $this->currency;
234: }
235:
236: if (false === empty($this->description)) {
237: $data['description'] = $this->description;
238: }
239:
240: if (false === empty($this->allowedRetries)) {
241: $data['allowed_retries'] = $this->allowedRetries;
242: }
243:
244: if (false === empty($this->extra)) {
245: $data['extra'] = $this->extra;
246: }
247:
248: return $data;
249: }
250:
251: /**
252: * Gets the value of flow.
253: *
254: * @return string
255: */
256: public function getFlow()
257: {
258: return $this->flow;
259: }
260:
261: /**
262: * Sets the value of flow.
263: *
264: * @param string $flow the flow
265: *
266: * @return self
267: */
268: public function setFlow($flow)
269: {
270: $this->flow = $flow;
271:
272: return $this;
273: }
274:
275: /**
276: * Get the value of mode
277: *
278: * @return string
279: */
280: public function getMode()
281: {
282: return $this->mode;
283: }
284: /**
285: * Sets the value of mode
286: *
287: * @param string $mode
288: *
289: * @return self
290: */
291: public function setMode($mode)
292: {
293: $this->mode = $mode;
294:
295: return $this;
296: }
297:
298: /**
299: * Sets the value of threatMetrixSessionId
300: *
301: * @param string $threatMetrixSessionId
302: *
303: * @return self
304: */
305: public function setThreatMetrixSessionId($threatMetrixSessionId)
306: {
307: $this->threatMetrixSessionId = $threatMetrixSessionId;
308:
309: return $this;
310: }
311:
312: /**
313: * Get the value of threatMetrixSessionId
314: *
315: * @return string
316: */
317: public function getThreatMetrixSessionId()
318: {
319: return $this->threatMetrixSessionId;
320: }
321:
322:
323: /**
324: * Gets the value of billingAgreement.
325: *
326: * @return boolean
327: */
328: public function getBillingAgreement()
329: {
330: return $this->billingAgreement;
331: }
332:
333: /**
334: * Sets the value of billingAgreement.
335: *
336: * @param boolean $billingAgreement the billingAgreement
337: *
338: * @return self
339: */
340: public function setBillingAgreement($billingAgreement)
341: {
342: $this->billingAgreement = $billingAgreement;
343:
344: return $this;
345: }
346:
347: /**
348: * Gets the value of emsUrl.
349: *
350: * @return string
351: */
352: public function getEmsUrl()
353: {
354: return $this->emsUrl;
355: }
356:
357: /**
358: * Sets the value of emsUrl.
359: *
360: * @param string $emsUrl the emsUrl
361: *
362: * @return self
363: */
364: public function setEmsUrl($emsUrl)
365: {
366: $this->emsUrl = $emsUrl;
367:
368: return $this;
369: }
370:
371: /**
372: * Gets the value of redirectUrl.
373: *
374: * @return string
375: */
376: public function getRedirectUrl()
377: {
378: return $this->redirectUrl;
379: }
380:
381: /**
382: * Sets the value of redirectUrl.
383: *
384: * @param string $redirectUrl the redirectUrl
385: *
386: * @return self
387: */
388: public function setRedirectUrl($redirectUrl)
389: {
390: $this->redirectUrl = $redirectUrl;
391:
392: return $this;
393: }
394:
395: /**
396: * Gets the value of customer.
397: *
398: * @return Syspay_Merchant_Entity_Customer
399: */
400: public function getCustomer()
401: {
402: return $this->customer;
403: }
404:
405: /**
406: * Sets the value of customer.
407: *
408: * @param Syspay_Merchant_Entity_Customer $customer the customer
409: *
410: * @return self
411: */
412: public function setCustomer(Syspay_Merchant_Entity_Customer $customer)
413: {
414: $this->customer = $customer;
415:
416: return $this;
417: }
418:
419: /**
420: * Gets the value of creditcard.
421: *
422: * @return Syspay_Merchant_Entity_Creditcard
423: */
424: public function getCreditcard()
425: {
426: return $this->creditcard;
427: }
428:
429: /**
430: * Sets the value of creditcard.
431: *
432: * @param Syspay_Merchant_Entity_Creditcard $creditcard the creditcard
433: *
434: * @return self
435: */
436: public function setCreditcard(Syspay_Merchant_Entity_Creditcard $creditcard)
437: {
438: $this->creditcard = $creditcard;
439:
440: return $this;
441: }
442:
443: /**
444: * Gets the value of paymentMethod.
445: *
446: * @return string
447: */
448: public function getPaymentMethod()
449: {
450: return $this->paymentMethod;
451: }
452:
453: /**
454: * Sets the value of paymentMethod.
455: *
456: * @param string $paymentMethod the paymentMethod
457: *
458: * @return self
459: */
460: public function setPaymentMethod($paymentMethod)
461: {
462: $this->paymentMethod = $paymentMethod;
463:
464: return $this;
465: }
466:
467: /**
468: * Gets the value of website.
469: *
470: * @return string
471: */
472: public function getWebsite()
473: {
474: return $this->website;
475: }
476:
477: /**
478: * Sets the value of website.
479: *
480: * @param string $website the website
481: *
482: * @return self
483: */
484: public function setWebsite($website)
485: {
486: $this->website = $website;
487:
488: return $this;
489: }
490:
491: /**
492: * Gets the agent
493: * @return string
494: */
495: public function getAgent()
496: {
497: return $this->agent;
498: }
499:
500: /**
501: * Sets the value of agent.
502: *
503: * @param string $agent the agent id
504: *
505: * @return self
506: */
507: public function setAgent($agent)
508: {
509: $this->agent = $agent;
510:
511: return $this;
512: }
513:
514: /**
515: * Gets the value of allowedRetries.
516: *
517: * @return integer
518: */
519: public function getAllowedRetries()
520: {
521: return $this->allowedRetries;
522: }
523:
524: /**
525: * Sets the value of allowedRetries.
526: *
527: * @param integer $allowedRetries the allowed retries
528: *
529: * @return self
530: */
531: public function setAllowedRetries($allowedRetries)
532: {
533: $this->allowedRetries = $allowedRetries;
534:
535: return $this;
536: }
537:
538: /**
539: * Gets the value of bankCode.
540: *
541: * @return string
542: */
543: public function getBankCode()
544: {
545: return $this->bankCode;
546: }
547:
548: /**
549: * Sets the value of bankCode.
550: *
551: * @param string $bankCode the bank code
552: *
553: * @return self
554: */
555: public function setBankCode($bankCode)
556: {
557: $this->bankCode = $bankCode;
558:
559: return $this;
560: }
561:
562: /**
563: * Gets the value of reference.
564: *
565: * @return String
566: */
567: public function getReference()
568: {
569: return $this->reference;
570: }
571:
572: /**
573: * Sets the value of reference.
574: * @param String $reference the reference
575: *
576: * @return self
577: */
578: public function setReference($reference)
579: {
580: $this->reference = $reference;
581: }
582:
583: /**
584: * Gets the value of currency.
585: * @return String
586: */
587: public function getCurrency()
588: {
589: return $this->currency;
590: }
591:
592: /**
593: * Sets the value of currency.
594: * @param String $currency the currency
595: *
596: * @return self
597: */
598: public function setCurrency($currency)
599: {
600: $this->currency = $currency;
601: }
602:
603: /**
604: * Gets the value of description.
605: *
606: * @return string
607: */
608: public function getDescription()
609: {
610: return $this->description;
611: }
612:
613: /**
614: * Sets the value of description.
615: *
616: * @param string $description the description
617: *
618: * @return self
619: */
620: public function setDescription($description)
621: {
622: $this->description = $description;
623:
624: return $this;
625: }
626:
627: /**
628: * Gets the value of extra.
629: *
630: * @return string
631: */
632: public function getExtra()
633: {
634: return $this->extra;
635: }
636:
637: /**
638: * Sets the value of extra.
639: *
640: * @param string $extra the extra
641: *
642: * @return self
643: */
644: public function setExtra($extra)
645: {
646: $this->extra = $extra;
647:
648: return $this;
649: }
650: }
651: