1: <?php
2:
3: /**
4: * A payment object
5: */
6: class Syspay_Merchant_Entity_Payment extends Syspay_Merchant_Entity implements
7: Syspay_Merchant_Entity_ReturnedEntityInterface
8: {
9: const TYPE = 'payment';
10:
11: /**
12: * The card has been flagged as lost or stolen
13: * @see getFailureCategory()
14: */
15: const FAILURE_CARD_FLAGGED = 'card_flagged';
16:
17: /**
18: * The transaction has been declined by the acquirer
19: * @see getFailureCategory()
20: */
21: const FAILURE_DECLINED = 'declined';
22:
23: /**
24: * Two transactions with the same information have been attempted in a too short period
25: * @see getFailureCategory()
26: */
27: const FAILURE_DUPLICATED = 'duplicated';
28:
29: /**
30: * The card has expired
31: * @see getFailureCategory()
32: */
33: const FAILURE_EXPIRED = 'expired';
34:
35: /**
36: * The transaction has been refused for suspicion of fraud
37: * @see getFailureCategory()
38: */
39: const FAILURE_FRAUD = 'fraud_suspicious';
40:
41: /**
42: * There wasn't enough money available to complete the transaction
43: * @see getFailureCategory()
44: */
45: const FAILURE_INSUFFICIENT_FUNDS = 'insufficient_funds';
46:
47: /**
48: * The card number is not valid
49: * @see getFailureCategory()
50: */
51: const FAILURE_INVALID_CARD = 'invalid_card';
52:
53: /**
54: * The CV2 is not valid
55: * @see getFailureCategory()
56: */
57: const FAILURE_INVALID_CV2 = 'invalid_cv2';
58:
59: /**
60: * The card information are not valid
61: * @see getFailureCategory()
62: */
63: const FAILURE_INVALID_DETAILS = 'invalid_details';
64:
65: /**
66: * The transaction was refused by the acquirer but the reason could not be precisely determined
67: * @see getFailureCategory()
68: */
69: const FAILURE_OTHER = 'other';
70:
71: /**
72: * A technical error occured while attempting to process the transaction
73: * @see getFailureCategory()
74: */
75: const FAILURE_TECHNICAL_ERROR = 'technical_error';
76:
77: /**
78: * The card scheme is not supported
79: * @see getFailureCategory()
80: */
81: const FAILURE_UNSUPPORTED = 'unsupported';
82:
83: /**
84: * @var integer
85: */
86: private $id;
87:
88: /**
89: * @var string
90: */
91: private $status;
92:
93: /**
94: * @var string
95: */
96: private $chipAndPinStatus;
97:
98: /**
99: * @var string
100: */
101: private $failureCategory;
102:
103: /**
104: * @var string
105: */
106: protected $reference;
107:
108: /**
109: * @var integer
110: */
111: protected $amount;
112:
113: /**
114: * @var string
115: */
116: protected $currency;
117:
118: /**
119: * @var string
120: */
121: protected $description;
122:
123: /**
124: * @var string
125: */
126: protected $extra;
127:
128: /**
129: * @var boolean
130: */
131: protected $preauth;
132:
133: /**
134: * @var integer
135: */
136: private $website;
137:
138: /**
139: * @var Syspay_Merchant_Entity_BillingAgreement
140: */
141: private $billing_agreement;
142:
143: /**
144: * @var Syspay_Merchant_Entity_Subscription
145: */
146: private $subscription;
147:
148: /**
149: * @var string
150: */
151: private $redirect;
152:
153: /**
154: * @var DateTime
155: */
156: private $processingTime;
157:
158: /**
159: * @var array
160: */
161: protected $recipient_map;
162:
163: /**
164: * @var string
165: */
166: private $paymentType;
167:
168: /**
169: * @var string
170: */
171: private $websiteUrl;
172:
173: /**
174: * @var string
175: */
176: private $contract;
177:
178: /**
179: * @var string
180: */
181: private $descriptor;
182:
183: /**
184: * @var integer
185: */
186: private $accountId;
187:
188: /**
189: * @var string
190: */
191: private $merchantLogin;
192:
193: /**
194: * @var integer
195: */
196: private $merchantId;
197:
198: /**
199: * @var DateTime
200: */
201: private $settlementDate;
202:
203: /**
204: * @var Syspay_Merchant_Entity_PaymentMethod
205: */
206: private $payment_method;
207:
208: /**
209: * @var integer
210: */
211: private $subscription_counter;
212:
213: /**
214: * @var integer
215: */
216: private $subscription_counter_type;
217:
218: /**
219: * @var integer
220: */
221: private $subscription_attempt;
222:
223: /**
224: * @var DateTime
225: */
226: private $capture_date;
227:
228: /**
229: * Gets the value of reference.
230: *
231: * @return string
232: */
233: public function getReference()
234: {
235: return $this->reference;
236: }
237:
238: /**
239: * Sets the value of reference.
240: *
241: * @param string $reference the reference
242: *
243: * @return self
244: */
245: public function setReference($reference)
246: {
247: $this->reference = $reference;
248:
249: return $this;
250: }
251:
252: /**
253: * Gets the value of amount.
254: *
255: * @return integer
256: */
257: public function getAmount()
258: {
259: return $this->amount;
260: }
261:
262: /**
263: * Sets the value of amount.
264: *
265: * @param integer $amount the amount
266: *
267: * @return self
268: */
269: public function setAmount($amount)
270: {
271: $this->amount = $amount;
272:
273: return $this;
274: }
275:
276: /**
277: * Gets the value of currency.
278: *
279: * @return string
280: */
281: public function getCurrency()
282: {
283: return $this->currency;
284: }
285:
286: /**
287: * Sets the value of currency.
288: *
289: * @param string $currency the currency
290: *
291: * @return self
292: */
293: public function setCurrency($currency)
294: {
295: $this->currency = $currency;
296:
297: return $this;
298: }
299:
300: /**
301: * Gets the value of description.
302: *
303: * @return string
304: */
305: public function getDescription()
306: {
307: return $this->description;
308: }
309:
310: /**
311: * Sets the value of description.
312: *
313: * @param string $description the description
314: *
315: * @return self
316: */
317: public function setDescription($description)
318: {
319: $this->description = $description;
320:
321: return $this;
322: }
323:
324: /**
325: * Gets the value of extra.
326: *
327: * @return string
328: */
329: public function getExtra()
330: {
331: return $this->extra;
332: }
333:
334: /**
335: * Sets the value of extra.
336: *
337: * @param string $extra the extra
338: *
339: * @return self
340: */
341: public function setExtra($extra)
342: {
343: $this->extra = $extra;
344:
345: return $this;
346: }
347:
348: /**
349: * Gets the value of id.
350: *
351: * @return integer
352: */
353: public function getId()
354: {
355: return $this->id;
356: }
357:
358: /**
359: * Sets the value of id.
360: *
361: * @param integer $id the id
362: *
363: * @return self
364: */
365: public function setId($id)
366: {
367: $this->id = $id;
368:
369: return $this;
370: }
371:
372: /**
373: * Gets the value of status.
374: *
375: * @return string
376: */
377: public function getStatus()
378: {
379: return $this->status;
380: }
381:
382: /**
383: * Sets the value of status.
384: *
385: * @param string $status the status
386: *
387: * @return self
388: */
389: public function setStatus($status)
390: {
391: $this->status = $status;
392:
393: return $this;
394: }
395:
396: /**
397: * Gets the value of billing_agreement.
398: *
399: * @return Syspay_Merchant_Entity_BillingAgreement
400: */
401: public function getBillingAgreement()
402: {
403: return $this->billing_agreement;
404: }
405:
406: /**
407: * Sets the value of billing_agreement.
408: *
409: * @param Syspay_Merchant_Entity_BillingAgreement $billing_agreement the billing_agreement
410: *
411: * @return self
412: */
413: public function setBillingAgreement(Syspay_Merchant_Entity_BillingAgreement $billingAgreement)
414: {
415: $this->billing_agreement = $billingAgreement;
416:
417: return $this;
418: }
419:
420: /**
421: * Gets the value of subscription.
422: *
423: * @return Syspay_Merchant_Entity_Subscription
424: */
425: public function getSubscription()
426: {
427: return $this->subscription;
428: }
429:
430: /**
431: * Sets the value of subscription.
432: *
433: * @param Syspay_Merchant_Entity_Subscription $subscription the subscription
434: *
435: * @return self
436: */
437: public function setSubscription(Syspay_Merchant_Entity_Subscription $subscription)
438: {
439: $this->subscription = $subscription;
440:
441: return $this;
442: }
443:
444: /**
445: * Gets the value of redirect.
446: *
447: * @return string
448: */
449: public function getRedirect()
450: {
451: return $this->redirect;
452: }
453:
454: /**
455: * Sets the value of redirect.
456: *
457: * @param string $redirect the redirect
458: *
459: * @return self
460: */
461: public function setRedirect($redirect)
462: {
463: $this->redirect = $redirect;
464:
465: return $this;
466: }
467:
468: /**
469: * Build a payment entity based on a json-decoded payment stdClass
470: *
471: * @param stdClass $response The payment data
472: * @return Syspay_Merchant_Entity_Payment The payment object
473: */
474: public static function buildFromResponse(stdClass $response)
475: {
476: $payment = new self();
477: $payment->setId(isset($response->id)?$response->id:null);
478: $payment->setReference(isset($response->reference)?$response->reference:null);
479: $payment->setAmount(isset($response->amount)?$response->amount:null);
480: $payment->setCurrency(isset($response->currency)?$response->currency:null);
481: $payment->setStatus(isset($response->status)?$response->status:null);
482: $payment->setExtra(isset($response->extra)?$response->extra:null);
483: $payment->setDescription(isset($response->description)?$response->description:null);
484: $payment->setWebsite(isset($response->website)?$response->website:null);
485: $payment->setFailureCategory(isset($response->failure_category)?$response->failure_category:null);
486: $payment->setChipAndPinStatus(isset($response->chip_and_pin_status)?$response->chip_and_pin_status:null);
487: $payment->setPaymentType(isset($response->payment_type)?$response->payment_type:null);
488: $payment->setWebsiteUrl(isset($response->website_url)?$response->website_url:null);
489: $payment->setContract(isset($response->contract)?$response->contract:null);
490: $payment->setDescriptor(isset($response->descriptor)?$response->descriptor:null);
491: $payment->setAccountId(isset($response->account_id)?$response->account_id:null);
492: $payment->setMerchantLogin(isset($response->merchant_login)?$response->merchant_login:null);
493: $payment->setMerchantId(isset($response->merchant_id)?$response->merchant_id:null);
494: $payment->setSubscriptionCounter(isset($response->subscription_counter)?$response->subscription_counter:null);
495: $payment->setSubscriptionCounterType(isset($response->subscription_counter_type)?$response->subscription_counter_type:null);
496: $payment->setSubscriptionAttempt(isset($response->subscription_attempt)?$response->subscription_attempt:null);
497: $payment->setCaptureDate(isset($response->capture_date)?Syspay_Merchant_Utils::tsToDateTime($response->capture_date):null);
498:
499: if (isset($response->settlement_date)
500: && !is_null($response->settlement_date)) {
501: $payment->setSettlementDate(Syspay_Merchant_Utils::tsToDateTime($response->settlement_date));
502: }
503:
504: if (isset($response->processing_time)
505: && !is_null($response->processing_time)) {
506: $payment->setProcessingTime(Syspay_Merchant_Utils::tsToDateTime($response->processing_time));
507: }
508:
509: if (isset($response->billing_agreement)
510: && ($response->billing_agreement instanceof stdClass)) {
511: $billingAgreement =
512: Syspay_Merchant_Entity_BillingAgreement::buildFromResponse($response->billing_agreement);
513: $payment->setBillingAgreement($billingAgreement);
514: }
515:
516: if (isset($response->subscription)
517: && ($response->subscription instanceof stdClass)) {
518: $subscription = Syspay_Merchant_Entity_Subscription::buildFromResponse($response->subscription);
519: $payment->setSubscription($subscription);
520: }
521:
522: if (isset($response->payment_method)
523: && ($response->payment_method instanceof stdClass)) {
524: $paymentMethod = Syspay_Merchant_Entity_PaymentMethod::buildFromResponse($response->payment_method);
525: $payment->setPaymentMethod($paymentMethod);
526: }
527:
528: $payment->raw = $response;
529:
530: return $payment;
531: }
532:
533: /**
534: * Gets the value of preauth.
535: *
536: * @return boolean
537: */
538: public function getPreauth()
539: {
540: return $this->preauth;
541: }
542:
543: /**
544: * Sets the value of preauth.
545: *
546: * @param boolean $preauth the preauth
547: *
548: * @return self
549: */
550: public function setPreauth($preauth)
551: {
552: $this->preauth = $preauth;
553:
554: return $this;
555: }
556:
557: /**
558: * Gets the value of website.
559: *
560: * @return integer
561: */
562: public function getWebsite()
563: {
564: return $this->website;
565: }
566:
567: /**
568: * Sets the value of website.
569: *
570: * @param integer $website the website
571: *
572: * @return self
573: */
574: public function setWebsite($website)
575: {
576: $this->website = $website;
577:
578: return $this;
579: }
580:
581: /**
582: * Gets the value of processingTime.
583: *
584: * @return DateTime
585: */
586: public function getProcessingTime()
587: {
588: return $this->processingTime;
589: }
590:
591: /**
592: * Sets the value of processingTime.
593: *
594: * @param DateTime $processingTime the processingTime
595: *
596: * @return self
597: */
598: public function setProcessingTime(DateTime $processingTime)
599: {
600: $this->processingTime = $processingTime;
601:
602: return $this;
603: }
604:
605: /**
606: * Gets the failure category, this is one of the FAILURE_* constants
607: * @return string
608: */
609: public function getFailureCategory()
610: {
611: return $this->failureCategory;
612: }
613:
614: /**
615: * Sets the value of failureCategory.
616: *
617: * @param string $failureCategory the failureCategory
618: *
619: * @return self
620: */
621: public function setFailureCategory($failureCategory)
622: {
623: $this->failureCategory = $failureCategory;
624: }
625:
626:
627: /**
628: * Gets the value of chipAndPinStatus.
629: *
630: * @return string
631: */
632: public function getChipAndPinStatus()
633: {
634: return $this->chipAndPinStatus;
635: }
636:
637: /**
638: * Sets the value of chipAndPinStatus.
639: *
640: * @param string $chipAndPinStatus the chipAndPinStatus
641: *
642: * @return self
643: */
644: public function setChipAndPinStatus($chipAndPinStatus)
645: {
646: $this->chipAndPinStatus = $chipAndPinStatus;
647:
648: return $this;
649: }
650:
651: /**
652: * Gets the value of paymentType.
653: *
654: * @return string
655: */
656: public function getPaymentType()
657: {
658: return $this->paymentType;
659: }
660:
661: /**
662: * Sets the value of paymentType.
663: *
664: * @param string $paymentType the paymentType
665: *
666: * @return self
667: */
668: public function setPaymentType($paymentType)
669: {
670: $this->paymentType = $paymentType;
671:
672: return $this;
673: }
674:
675: /**
676: * Gets the value of recipient_map.
677: *
678: * @return array
679: */
680: public function getRecipientMap()
681: {
682: return $this->recipient_map;
683: }
684:
685: /**
686: * Sets the value of recipient_map.
687: *
688: * @param array $recipientMap An array of Syspay_Merchant_Entity_PaymentRecipient
689: *
690: * @return self
691: */
692: public function setRecipientMap(array $recipientMap)
693: {
694: foreach ($recipientMap as $r) {
695: if (!$r instanceof Syspay_Merchant_Entity_PaymentRecipient) {
696: throw new InvalidArgumentException(
697: 'The given array must only contain Syspay_Merchant_Entity_PaymentRecipient instances'
698: );
699: }
700: }
701: $this->recipient_map = $recipientMap;
702:
703: return $this;
704: }
705:
706: /**
707: * Add a PaymentRecipient to the recipient map list
708: *
709: * @param Syspay_Merchant_Entity_PaymentRecipient $paymentRecipient
710: *
711: * @return self
712: */
713: public function addRecipient(Syspay_Merchant_Entity_PaymentRecipient $paymentRecipient)
714: {
715: if (!isset($this->recipient_map)) {
716: $this->recipient_map = array();
717: }
718: array_push($this->recipient_map, $paymentRecipient);
719: }
720:
721: /**
722: * {@inheritDoc}
723: */
724: public function toArray()
725: {
726: $data = parent::toArray();
727: if (!empty($data['recipient_map']) && is_array($data['recipient_map'])) {
728: for ($i = 0; $i < count($data['recipient_map']); $i++) {
729: $data['recipient_map'][$i] = $data['recipient_map'][$i]->toArray();
730: }
731: } else {
732: unset($data['recipient_map']);
733: }
734: return $data;
735: }
736:
737: /**
738: * Gets the value of settlementDate.
739: *
740: * @return DateTime
741: */
742: public function getSettlementDate()
743: {
744: return $this->settlementDate;
745: }
746:
747: /**
748: * Sets the value of settlementDate.
749: *
750: * @param DateTime $settlementDate the settlement date
751: *
752: * @return self
753: */
754: public function setSettlementDate(DateTime $settlementDate = null)
755: {
756: $this->settlementDate = $settlementDate;
757:
758: return $this;
759: }
760:
761: /**
762: * Gets the value of websiteUrl.
763: *
764: * @return string
765: */
766: public function getWebsiteUrl()
767: {
768: return $this->websiteUrl;
769: }
770:
771: /**
772: * Sets the value of websiteUrl.
773: *
774: * @param string $websiteUrl the website url
775: *
776: * @return self
777: */
778: public function setWebsiteUrl($websiteUrl)
779: {
780: $this->websiteUrl = $websiteUrl;
781:
782: return $this;
783: }
784:
785: /**
786: * Gets the value of contract.
787: *
788: * @return string
789: */
790: public function getContract()
791: {
792: return $this->contract;
793: }
794:
795: /**
796: * Sets the value of contract.
797: *
798: * @param string $contract the contract
799: *
800: * @return self
801: */
802: public function setContract($contract)
803: {
804: $this->contract = $contract;
805:
806: return $this;
807: }
808:
809: /**
810: * Gets the value of descriptor.
811: *
812: * @return string
813: */
814: public function getDescriptor()
815: {
816: return $this->descriptor;
817: }
818:
819: /**
820: * Sets the value of descriptor.
821: *
822: * @param string $descriptor the descriptor
823: *
824: * @return self
825: */
826: public function setDescriptor($descriptor)
827: {
828: $this->descriptor = $descriptor;
829:
830: return $this;
831: }
832:
833: /**
834: * Gets the value of accountId.
835: *
836: * @return integer
837: */
838: public function getAccountId()
839: {
840: return $this->accountId;
841: }
842:
843: /**
844: * Sets the value of accountId.
845: *
846: * @param integer $accountId the account id
847: *
848: * @return self
849: */
850: public function setAccountId($accountId)
851: {
852: $this->accountId = $accountId;
853:
854: return $this;
855: }
856:
857: /**
858: * Gets the value of merchantLogin.
859: *
860: * @return string
861: */
862: public function getMerchantLogin()
863: {
864: return $this->merchantLogin;
865: }
866:
867: /**
868: * Sets the value of merchantLogin.
869: *
870: * @param string $merchantLogin the merchant login
871: *
872: * @return self
873: */
874: public function setMerchantLogin($merchantLogin)
875: {
876: $this->merchantLogin = $merchantLogin;
877:
878: return $this;
879: }
880:
881: /**
882: * Gets the value of merchantId.
883: *
884: * @return integer
885: */
886: public function getMerchantId()
887: {
888: return $this->merchantId;
889: }
890:
891: /**
892: * Sets the value of merchantId.
893: *
894: * @param integer $merchantId the merchant id
895: *
896: * @return self
897: */
898: public function setMerchantId($merchantId)
899: {
900: $this->merchantId = $merchantId;
901:
902: return $this;
903: }
904:
905: /**
906: * Gets the value of payment_method.
907: *
908: * @return Syspay_Merchant_Entity_PaymentMethod
909: */
910: public function getPaymentMethod()
911: {
912: return $this->payment_method;
913: }
914:
915: /**
916: * Sets the value of payment_method.
917: *
918: * @param Syspay_Merchant_Entity_PaymentMethod $payment_method the payment_method
919: *
920: * @return self
921: */
922: public function setPaymentMethod(Syspay_Merchant_Entity_PaymentMethod $payment_method)
923: {
924: $this->payment_method = $payment_method;
925:
926: return $this;
927: }
928:
929: /**
930: * Get the value of subscription_counter
931: *
932: * @return int
933: */
934: public function getSubscriptionCounter()
935: {
936: return $this->subscription_counter;
937: }
938:
939: /**
940: * Set the value of subscription_counter
941: *
942: * @param int $subscription_counter
943: * @return $this
944: */
945: public function setSubscriptionCounter($subscription_counter)
946: {
947: $this->subscription_counter = $subscription_counter;
948:
949: return $this;
950: }
951:
952: /**
953: * Get the value of subscription_counter_type
954: *
955: * @return int
956: */
957: public function getSubscriptionCounterType()
958: {
959: return $this->subscription_counter_type;
960: }
961:
962: /**
963: * Set the value of subscription_counter_type
964: *
965: * @param int $subscription_counter_type
966: * @return $this
967: */
968: public function setSubscriptionCounterType($subscription_counter_type)
969: {
970: $this->subscription_counter_type = $subscription_counter_type;
971:
972: return $this;
973: }
974:
975: /**
976: * Get the value of subscription_attempt
977: *
978: * @return int
979: */
980: public function getSubscriptionAttempt()
981: {
982: return $this->subscription_attempt;
983: }
984:
985: /**
986: * Set the value of subscription_attempt
987: *
988: * @param int $subscription_attempt
989: * @return $this
990: */
991: public function setSubscriptionAttempt($subscription_attempt)
992: {
993: $this->subscription_attempt = $subscription_attempt;
994:
995: return $this;
996: }
997:
998: /**
999: * Get the value of capture_date.
1000: *
1001: * @return DateTime
1002: */
1003: public function getCaptureDate()
1004: {
1005: return $this->capture_date;
1006: }
1007:
1008: /**
1009: * Set the value of capture_date.
1010: *
1011: * @param DateTime $capture_date
1012: * @return $this
1013: */
1014: public function setCaptureDate(DateTime $capture_date = null)
1015: {
1016: $this->capture_date = $capture_date;
1017:
1018: return $this;
1019: }
1020: }
1021: