1: <?php
2:
3: /**
4: * Cancel a subscription
5: * @see https://app.syspay.com/docs/api/merchant_subscription.html#cancelling-a-subscription
6: */
7: class Syspay_Merchant_SubscriptionCancellationRequest extends Syspay_Merchant_Request
8: {
9: const METHOD = 'POST';
10: const PATH = '/api/v1/merchant/subscription/%d/cancel';
11:
12: /**
13: * @var integer
14: */
15: private $subscriptionId;
16:
17: /**
18: * @var boolean
19: */
20: private $now = false;
21:
22: public function __construct($subscriptionId = null)
23: {
24: if (null !== $subscriptionId) {
25: $this->setSubscriptionId($subscriptionId);
26: }
27: }
28:
29: /**
30: * {@inheritDoc}
31: */
32: public function getMethod()
33: {
34: return self::METHOD;
35: }
36:
37: /**
38: * {@inheritDoc}
39: */
40: public function getPath()
41: {
42: return sprintf(self::PATH, $this->subscriptionId);
43: }
44:
45: /**
46: * {@inheritDoc}
47: */
48: public function buildResponse(stdClass $response)
49: {
50: if (!isset($response->subscription)) {
51: throw new Syspay_Merchant_UnexpectedResponseException(
52: 'Unable to retrieve "subscription" data from response',
53: $response
54: );
55: }
56:
57: $subscription = Syspay_Merchant_Entity_Subscription::buildFromResponse($response->subscription);
58:
59: return $subscription;
60: }
61:
62: /**
63: * Gets the value of subscriptionId.
64: *
65: * @return integer
66: */
67: public function getSubscriptionId()
68: {
69: return $this->subscriptionId;
70: }
71:
72: /**
73: * Sets the value of subscriptionId.
74: *
75: * @param integer $subscriptionId the subscription id
76: *
77: * @return self
78: */
79: public function setSubscriptionId($subscriptionId)
80: {
81: $this->subscriptionId = $subscriptionId;
82:
83: return $this;
84: }
85:
86: /**
87: * Sets the value of now.
88: *
89: * @param boolean $now Terminate the subscription right away
90: *
91: * @return self
92: */
93: public function setNow($now)
94: {
95: $this->now = $now;
96:
97: return $this;
98: }
99:
100: /**
101: * Gets the value of now.
102: *
103: * @return boolean
104: */
105: public function getNow()
106: {
107: return $this->now;
108: }
109:
110: /**
111: * {@inheritDoc}
112: */
113: public function getData()
114: {
115: $data = array();
116: $data['now'] = $this->now;
117:
118: return $data;
119: }
120: }
121: