1: <?php
2:
3: /**
4: * A plan object
5: */
6: class Syspay_Merchant_Entity_Plan extends Syspay_Merchant_Entity implements
7: Syspay_Merchant_Entity_ReturnedEntityInterface
8: {
9: const TYPE = 'plan';
10:
11: const UNIT_MINUTE = 'minute';
12: const UNIT_HOUR = 'hour';
13: const UNIT_DAY = 'day';
14: const UNIT_WEEK = 'week';
15: const UNIT_MONTH = 'month';
16: const UNIT_YEAR = 'year';
17:
18: const TYPE_SUBSCRIPTION = 'SUBSCRIPTION';
19: const TYPE_INSTALMENT = 'INSTALMENT';
20:
21: /**
22: * @var integer
23: */
24: private $id;
25:
26: /**
27: * @var DateTime
28: */
29: private $created;
30:
31: /**
32: * @var string
33: */
34: private $status;
35:
36: /**
37: * @var string
38: */
39: protected $type;
40:
41: /**
42: * @var string
43: */
44: protected $name;
45:
46: /**
47: * @var string
48: */
49: protected $description;
50:
51: /**
52: * @var string
53: */
54: protected $currency;
55:
56: /**
57: * @var integer
58: */
59: protected $trial_amount;
60:
61: /**
62: * @var integer
63: */
64: protected $trial_period;
65:
66: /**
67: * @var string
68: */
69: protected $trial_period_unit;
70:
71: /**
72: * @var integer
73: */
74: protected $trial_cycles;
75:
76: /**
77: * @var integer
78: */
79: protected $initial_amount;
80:
81: /**
82: * @var integer
83: */
84: protected $billing_amount;
85:
86: /**
87: * @var integer
88: */
89: protected $billing_period;
90:
91: /**
92: * @var string
93: */
94: protected $billing_period_unit;
95:
96: /**
97: * @var integer
98: */
99: protected $billing_cycles;
100:
101: /**
102: * @var integer
103: */
104: protected $retry_map_id;
105:
106: /**
107: * @var integer
108: */
109: protected $total_amount;
110:
111: /**
112: * @var integer
113: */
114: protected $default_capture_delay = 0;
115:
116: /**
117: * Build a plan entity based on a json-decoded plan stdClass
118: *
119: * @param stdClass $response The plan data
120: * @return Syspay_Merchant_Entity_Plan The plan object
121: */
122: public static function buildFromResponse(stdClass $response)
123: {
124: $plan = new self();
125: $plan->setId(isset($response->id)?$response->id:null);
126: $plan->setStatus(isset($response->status)?$response->status:null);
127: $plan->setName(isset($response->name)?$response->name:null);
128: $plan->setDescription(isset($response->description)?$response->description:null);
129: $plan->setCurrency(isset($response->currency)?$response->currency:null);
130: $plan->setTrialAmount(isset($response->trial_amount)?$response->trial_amount:null);
131: $plan->setTrialPeriod(isset($response->trial_period)?$response->trial_period:null);
132: $plan->setTrialPeriodUnit(isset($response->trial_period_unit)?$response->trial_period_unit:null);
133: $plan->setTrialCycles(isset($response->trial_cycles)?$response->trial_cycles:null);
134: $plan->setBillingAmount(isset($response->billing_amount)?$response->billing_amount:null);
135: $plan->setBillingPeriod(isset($response->billing_period)?$response->billing_period:null);
136: $plan->setBillingPeriodUnit(isset($response->billing_period_unit)?$response->billing_period_unit:null);
137: $plan->setBillingCycles(isset($response->billing_cycles)?$response->billing_cycles:null);
138: $plan->setInitialAmount(isset($response->initial_amount)?$response->initial_amount:null);
139: $plan->setRetryMapId(isset($response->retry_map_id)?$response->retry_map_id:null);
140: $plan->setType(isset($response->type)?$response->type:null);
141: $plan->setDefaultCaptureDelay(isset($response->default_capture_delay)?$response->default_capture_delay:null);
142:
143: if (isset($response->created)
144: && !is_null($response->created)) {
145: $plan->setCreated(Syspay_Merchant_Utils::tsToDateTime($response->created));
146: }
147:
148: $plan->raw = $response;
149:
150: return $plan;
151: }
152:
153: /**
154: * Gets the value of id.
155: *
156: * @return integer
157: */
158: public function getId()
159: {
160: return $this->id;
161: }
162:
163: /**
164: * Sets the value of id.
165: *
166: * @param integer $id the id
167: *
168: * @return self
169: */
170: public function setId($id)
171: {
172: $this->id = $id;
173:
174: return $this;
175: }
176:
177: /**
178: * Gets the value of created.
179: *
180: * @return DateTime
181: */
182: public function getCreated()
183: {
184: return $this->created;
185: }
186:
187: /**
188: * Sets the value of created.
189: *
190: * @param DateTime $created the created
191: *
192: * @return self
193: */
194: public function setCreated(DateTime $created)
195: {
196: $this->created = $created;
197:
198: return $this;
199: }
200:
201: /**
202: * Gets the value of status.
203: *
204: * @return string
205: */
206: public function getStatus()
207: {
208: return $this->status;
209: }
210:
211: /**
212: * Sets the value of status.
213: *
214: * @param string $status the status
215: *
216: * @return self
217: */
218: public function setStatus($status)
219: {
220: $this->status = $status;
221:
222: return $this;
223: }
224:
225: /**
226: * Gets the value of name.
227: *
228: * @return string
229: */
230: public function getName()
231: {
232: return $this->name;
233: }
234:
235: /**
236: * Sets the value of name.
237: *
238: * @param string $name the name
239: *
240: * @return self
241: */
242: public function setName($name)
243: {
244: $this->name = $name;
245:
246: return $this;
247: }
248:
249: /**
250: * Gets the value of description.
251: *
252: * @return string
253: */
254: public function getDescription()
255: {
256: return $this->description;
257: }
258:
259: /**
260: * Sets the value of description.
261: *
262: * @param string $description the description
263: *
264: * @return self
265: */
266: public function setDescription($description)
267: {
268: $this->description = $description;
269:
270: return $this;
271: }
272:
273: /**
274: * Gets the value of currency.
275: *
276: * @return string
277: */
278: public function getCurrency()
279: {
280: return $this->currency;
281: }
282:
283: /**
284: * Sets the value of currency.
285: *
286: * @param string $currency the currency
287: *
288: * @return self
289: */
290: public function setCurrency($currency)
291: {
292: $this->currency = $currency;
293:
294: return $this;
295: }
296:
297: /**
298: * Gets the value of trial_amount.
299: *
300: * @return integer
301: */
302: public function getTrialAmount()
303: {
304: return $this->trial_amount;
305: }
306:
307: /**
308: * Sets the value of trial_amount.
309: *
310: * @param integer $trial_amount the trial_amount
311: *
312: * @return self
313: */
314: public function setTrialAmount($trial_amount)
315: {
316: $this->trial_amount = $trial_amount;
317:
318: return $this;
319: }
320:
321: /**
322: * Gets the value of trial_period.
323: *
324: * @return integer
325: */
326: public function getTrialPeriod()
327: {
328: return $this->trial_period;
329: }
330:
331: /**
332: * Sets the value of trial_period.
333: *
334: * @param integer $trial_period the trial_period
335: *
336: * @return self
337: */
338: public function setTrialPeriod($trial_period)
339: {
340: $this->trial_period = $trial_period;
341:
342: return $this;
343: }
344:
345: /**
346: * Gets the value of trial_period_unit.
347: *
348: * @return string
349: */
350: public function getTrialPeriodUnit()
351: {
352: return $this->trial_period_unit;
353: }
354:
355: /**
356: * Sets the value of trial_period_unit.
357: *
358: * @param string $trial_period_unit the trial_period_unit
359: *
360: * @return self
361: */
362: public function setTrialPeriodUnit($trial_period_unit)
363: {
364: $this->trial_period_unit = $trial_period_unit;
365:
366: return $this;
367: }
368:
369: /**
370: * Gets the value of trial_cycles.
371: *
372: * @return integer
373: */
374: public function getTrialCycles()
375: {
376: return $this->trial_cycles;
377: }
378:
379: /**
380: * Sets the value of trial_cycles.
381: *
382: * @param integer $trial_cycles the trial_cycles
383: *
384: * @return self
385: */
386: public function setTrialCycles($trial_cycles)
387: {
388: $this->trial_cycles = $trial_cycles;
389:
390: return $this;
391: }
392:
393: /**
394: * Gets the value of initial_amount.
395: *
396: * @return integer
397: */
398: public function getInitialAmount()
399: {
400: return $this->initial_amount;
401: }
402:
403: /**
404: * Sets the value of initial_amount.
405: *
406: * @param integer $initial_amount the initial_amount
407: *
408: * @return self
409: */
410: public function setInitialAmount($initial_amount)
411: {
412: $this->initial_amount = $initial_amount;
413:
414: return $this;
415: }
416:
417: /**
418: * Gets the value of billing_amount.
419: *
420: * @return integer
421: */
422: public function getBillingAmount()
423: {
424: return $this->billing_amount;
425: }
426:
427: /**
428: * Sets the value of billing_amount.
429: *
430: * @param integer $billing_amount the billing_amount
431: *
432: * @return self
433: */
434: public function setBillingAmount($billing_amount)
435: {
436: $this->billing_amount = $billing_amount;
437:
438: return $this;
439: }
440:
441: /**
442: * Gets the value of billing_period.
443: *
444: * @return integer
445: */
446: public function getBillingPeriod()
447: {
448: return $this->billing_period;
449: }
450:
451: /**
452: * Sets the value of billing_period.
453: *
454: * @param integer $billing_period the billing_period
455: *
456: * @return self
457: */
458: public function setBillingPeriod($billing_period)
459: {
460: $this->billing_period = $billing_period;
461:
462: return $this;
463: }
464:
465: /**
466: * Gets the value of billing_period_unit.
467: *
468: * @return string
469: */
470: public function getBillingPeriodUnit()
471: {
472: return $this->billing_period_unit;
473: }
474:
475: /**
476: * Sets the value of billing_period_unit.
477: *
478: * @param string $billing_period_unit the billing_period_unit
479: *
480: * @return self
481: */
482: public function setBillingPeriodUnit($billing_period_unit)
483: {
484: $this->billing_period_unit = $billing_period_unit;
485:
486: return $this;
487: }
488:
489: /**
490: * Gets the value of billing_cycles.
491: *
492: * @return integer
493: */
494: public function getBillingCycles()
495: {
496: return $this->billing_cycles;
497: }
498:
499: /**
500: * Sets the value of billing_cycles.
501: *
502: * @param integer $billing_cycles the billing_cycles
503: *
504: * @return self
505: */
506: public function setBillingCycles($billing_cycles)
507: {
508: $this->billing_cycles = $billing_cycles;
509:
510: return $this;
511: }
512:
513: /**
514: * Gets the value of retry_map_id.
515: *
516: * @return integer
517: */
518: public function getRetryMapId()
519: {
520: return $this->retry_map_id;
521: }
522:
523: /**
524: * Sets the value of retry_map_id.
525: *
526: * @param integer $retry_map_id the retry_map_id
527: *
528: * @return self
529: */
530: public function setRetryMapId($retry_map_id)
531: {
532: $this->retry_map_id = $retry_map_id;
533:
534: return $this;
535: }
536:
537: /**
538: * Gets the value of type.
539: *
540: * @return string
541: */
542: public function getType()
543: {
544: return $this->type;
545: }
546:
547: /**
548: * Sets the value of type.
549: *
550: * @param string $type the type
551: *
552: * @return self
553: */
554: public function setType($type)
555: {
556: $this->type = $type;
557:
558: return $this;
559: }
560:
561: /**
562: * Gets the value of total_amount.
563: *
564: * @return integer
565: */
566: public function getTotalAmount()
567: {
568: return $this->total_amount;
569: }
570:
571: /**
572: * Sets the value of total_amount.
573: *
574: * @param integer $total_amount the total_amount
575: *
576: * @return self
577: */
578: public function setTotalAmount($total_amount)
579: {
580: $this->total_amount = $total_amount;
581:
582: return $this;
583: }
584:
585: /**
586: * Gets the value of $default_capture_delay.
587: *
588: * @return int
589: */
590: public function getDefaultCaptureDelay()
591: {
592: return $this->default_capture_delay;
593: }
594:
595: /**
596: * Sets the value of $default_capture_delay.
597: *
598: * @param int $default_capture_delay
599: *
600: * @return self
601: */
602: public function setDefaultCaptureDelay($default_capture_delay)
603: {
604: $this->default_capture_delay = $default_capture_delay;
605:
606: return $this;
607: }
608:
609:
610: }
611: