1: <?php
2:
3: /**
4: * A billing agreement object
5: */
6: class Syspay_Merchant_Entity_BillingAgreement extends Syspay_Merchant_Entity implements
7: Syspay_Merchant_Entity_ReturnedEntityInterface
8: {
9: const TYPE = 'billing_agreement';
10:
11: // First payment not yet successful
12: const STATUS_PENDING = 'PENDING';
13: // Active billing agreement, the merchant can do rebills
14: const STATUS_ACTIVE = 'ACTIVE';
15: // The first payment failed, (or has been cancelled by the user) the billing agreement is cancelled
16: const STATUS_CANCELLED = 'CANCELLED';
17: // Billing agreement has ended, the merchant cannot do rebills anymore
18: const STATUS_ENDED = 'ENDED';
19:
20: // Merchant stopped the billing agreement via his interface or via the API
21: const END_REASON_UNSUBSCRIBED_MERCHANT = 'UNSUBSCRIBED_MERCHANT';
22: // Admin stopped the billing agreement via the admin interface
23: const END_REASON_UNSUBSCRIBED_ADMIN = 'UNSUBSCRIBED_ADMIN';
24: // Payment method has expired
25: const END_REASON_SUSPENDED_EXPIRED = 'SUSPENDED_EXPIRED';
26: // A chargeback was received on this billing agreement
27: const END_REASON_SUSPENDED_CHARGEBACK = 'SUSPENDED_CHARGEBACK';
28:
29: /**
30: * @var integer
31: */
32: private $id;
33:
34: /**
35: * @var string
36: */
37: private $status;
38:
39: /**
40: * @var string
41: */
42: private $currency;
43:
44: /**
45: * @var string
46: */
47: private $extra;
48:
49: /**
50: * @var string
51: */
52: private $endReason;
53:
54: /**
55: * @var Syspay_Merchant_Entity_PaymentMethod
56: */
57: private $payment_method;
58:
59: /**
60: * @var Syspay_Merchant_Entity_Customer
61: */
62: private $customer;
63:
64: /**
65: * @var int
66: */
67: private $expirationDate;
68:
69: /**
70: * @var string
71: */
72: private $redirect;
73:
74: /**
75: * @var string
76: */
77: protected $description;
78:
79: /**
80: * Gets the value of id.
81: *
82: * @return integer
83: */
84: public function getId()
85: {
86: return $this->id;
87: }
88:
89: /**
90: * Sets the value of id.
91: *
92: * @param integer $id the id
93: *
94: * @return self
95: */
96: public function setId($id)
97: {
98: $this->id = $id;
99:
100: return $this;
101: }
102:
103: /**
104: * Gets the value of status.
105: *
106: * @return string
107: */
108: public function getStatus()
109: {
110: return $this->status;
111: }
112:
113: /**
114: * Sets the value of status.
115: *
116: * @param string $status the status
117: *
118: * @return self
119: */
120: public function setStatus($status)
121: {
122: $this->status = $status;
123:
124: return $this;
125: }
126:
127: /**
128: * Gets the value of currency.
129: *
130: * @return string
131: */
132: public function getCurrency()
133: {
134: return $this->currency;
135: }
136:
137: /**
138: * Sets the value of currency.
139: *
140: * @param string $currency the currency
141: *
142: * @return self
143: */
144: public function setCurrency($currency)
145: {
146: $this->currency = $currency;
147:
148: return $this;
149: }
150:
151: /**
152: * Gets the value of extra.
153: *
154: * @return string
155: */
156: public function getExtra()
157: {
158: return $this->extra;
159: }
160:
161: /**
162: * Sets the value of extra.
163: *
164: * @param string $extra the extra
165: *
166: * @return self
167: */
168: public function setExtra($extra)
169: {
170: $this->extra = $extra;
171:
172: return $this;
173: }
174:
175:
176: /**
177: * Build a billing agreement entity based on a json-decoded billing agreement stdClass
178: *
179: * @param stdClass $response The billing agreement data
180: * @return Syspay_Merchant_Entity_BillingAgreement The billing agreement object
181: */
182: public static function buildFromResponse(stdClass $response)
183: {
184: $billingAgreement = new self();
185: $billingAgreement->setId(isset($response->id)?$response->id:null);
186: $billingAgreement->setStatus(isset($response->status)?$response->status:null);
187: $billingAgreement->setCurrency(isset($response->currency)?$response->currency:null);
188: $billingAgreement->setExtra(isset($response->extra)?$response->extra:null);
189: $billingAgreement->setEndReason(isset($response->end_reason)?$response->end_reason:null);
190:
191: if (isset($response->expiration_date)
192: && !is_null($response->expiration_date)) {
193: $billingAgreement->setExpirationDate(Syspay_Merchant_Utils::tsToDateTime($response->expiration_date));
194: }
195:
196: if (isset($response->payment_method)
197: && ($response->payment_method instanceof stdClass)) {
198: $paymentMethod = Syspay_Merchant_Entity_PaymentMethod::buildFromResponse($response->payment_method);
199: $billingAgreement->setPaymentMethod($paymentMethod);
200: }
201:
202: if (isset($response->customer)
203: && ($response->customer instanceof stdClass)) {
204: $customer = Syspay_Merchant_Entity_Customer::buildFromResponse($response->customer);
205: $billingAgreement->setCustomer($customer);
206: }
207:
208: $billingAgreement->raw = $response;
209:
210: return $billingAgreement;
211: }
212:
213: /**
214: * Gets the value of endReason.
215: *
216: * @return string
217: */
218: public function getEndReason()
219: {
220: return $this->endReason;
221: }
222:
223: /**
224: * Sets the value of endReason.
225: *
226: * @param string $endReason the endReason
227: *
228: * @return self
229: */
230: public function setEndReason($endReason)
231: {
232: $this->endReason = $endReason;
233:
234: return $this;
235: }
236:
237: /**
238: * Gets the value of customer.
239: *
240: * @return Syspay_Merchant_Entity_Customer
241: */
242: public function getCustomer()
243: {
244: return $this->customer;
245: }
246:
247: /**
248: * Sets the value of customer.
249: *
250: * @param Syspay_Merchant_Entity_Customer $customer the customer
251: *
252: * @return self
253: */
254: public function setCustomer(Syspay_Merchant_Entity_Customer $customer)
255: {
256: $this->customer = $customer;
257:
258: return $this;
259: }
260:
261: /**
262: * Gets the value of payment_method.
263: *
264: * @return Syspay_Merchant_Entity_PaymentMethod
265: */
266: public function getPaymentMethod()
267: {
268: return $this->payment_method;
269: }
270:
271: /**
272: * Sets the value of payment_method.
273: *
274: * @param Syspay_Merchant_Entity_PaymentMethod $payment_method the payment_method
275: *
276: * @return self
277: */
278: public function setPaymentMethod(Syspay_Merchant_Entity_PaymentMethod $payment_method)
279: {
280: $this->payment_method = $payment_method;
281:
282: return $this;
283: }
284:
285: /**
286: * Gets the value of expirationDate.
287: *
288: * @return DateTime
289: */
290: public function getExpirationDate()
291: {
292: return $this->expirationDate;
293: }
294:
295: /**
296: * Sets the value of expirationDate.
297: *
298: * @param DateTime $expirationDate the expirationDate
299: *
300: * @return self
301: */
302: public function setExpirationDate(DateTime $expirationDate)
303: {
304: $this->expirationDate = $expirationDate;
305:
306: return $this;
307: }
308:
309: /**
310: * Gets the value of redirect.
311: * @return string
312: */
313: public function getRedirect()
314: {
315: return $this->redirect;
316: }
317:
318: /**
319: * Sets the value of redirect.
320: * @param string $redirect the redirect
321: *
322: * @return self
323: */
324: public function setRedirect($redirect)
325: {
326: $this->redirect = $redirect;
327: }
328:
329: /**
330: * Gets the value of description.
331: *
332: * @return string
333: */
334: public function getDescription()
335: {
336: return $this->description;
337: }
338:
339: /**
340: * Sets the value of description.
341: *
342: * @param string $description the description
343: *
344: * @return self
345: */
346: public function setDescription($description)
347: {
348: $this->description = $description;
349:
350: return $this;
351: }
352: }
353: