1: <?php
2:
3: /**
4: * Uodate a plan
5: * @see https://app.syspay.com/docs/api/merchant_subscription.html#update-a-plan
6: */
7: class Syspay_Merchant_PlanUpdateRequest extends Syspay_Merchant_Request
8: {
9: const METHOD = 'PUT';
10: const PATH = '/api/v1/merchant/plan/%d';
11:
12: /**
13: * @var integer
14: */
15: private $plan_id;
16:
17: /**
18: * @var integer
19: */
20: protected $trial_amount;
21:
22: /**
23: * @var integer
24: */
25: protected $initial_amount;
26:
27: /**
28: * @var integer
29: */
30: protected $billing_amount;
31:
32: /**
33: * @var integer
34: */
35: protected $default_capture_delay;
36:
37: /**
38: * PlanUpdate Constuctor
39: *
40: * @param int $plan_id
41: */
42: public function __construct($plan_id = null)
43: {
44: if (null !== $plan_id) {
45: $this->setPlanId($plan_id);
46: }
47: }
48:
49: /**
50: * {@inheritDoc}
51: */
52: public function getMethod()
53: {
54: return self::METHOD;
55: }
56:
57: /**
58: * {@inheritDoc}
59: */
60: public function getPath()
61: {
62: return sprintf(self::PATH, $this->plan_id);
63: }
64:
65: /**
66: * Gets the value of planId.
67: *
68: * @return integer
69: */
70: public function getPlanId()
71: {
72: return $this->plan_id;
73: }
74:
75: /**
76: * Sets the value of planId.
77: *
78: * @param integer $planId the planId
79: *
80: * @return self
81: */
82: public function setPlanId($plan_id)
83: {
84: $this->plan_id = $plan_id;
85:
86: return $this;
87: }
88:
89: /**
90: * Gets the value of trial_amount.
91: *
92: * @return integer
93: */
94: public function getTrialAmount()
95: {
96: return $this->trial_amount;
97: }
98:
99: /**
100: * Sets the value of trial_amount.
101: *
102: * @param integer $trial_amount the trial_amount
103: *
104: * @return self
105: */
106: public function setTrialAmount($trial_amount)
107: {
108: $this->trial_amount = $trial_amount;
109:
110: return $this;
111: }
112:
113: /**
114: * Gets the value of initial_amount.
115: *
116: * @return integer
117: */
118: public function getInitialAmount()
119: {
120: return $this->initial_amount;
121: }
122:
123: /**
124: * Sets the value of initial_amount.
125: *
126: * @param integer $initial_amount the initial_amount
127: *
128: * @return self
129: */
130: public function setInitialAmount($initial_amount)
131: {
132: $this->initial_amount = $initial_amount;
133:
134: return $this;
135: }
136:
137: /**
138: * Gets the value of billing_amount.
139: *
140: * @return integer
141: */
142: public function getBillingAmount()
143: {
144: return $this->billing_amount;
145: }
146:
147: /**
148: * Sets the value of billing_amount.
149: *
150: * @param integer $billing_amount the billing_amount
151: *
152: * @return self
153: */
154: public function setBillingAmount($billing_amount)
155: {
156: $this->billing_amount = $billing_amount;
157:
158: return $this;
159: }
160:
161: /**
162: * Gets the value of $default_capture_delay.
163: *
164: * @return int
165: */
166: public function getDefaultCaptureDelay()
167: {
168: return $this->default_capture_delay;
169: }
170:
171: /**
172: * Sets the value of $default_capture_delay.
173: *
174: * @param int $default_capture_delay
175: *
176: * @return self
177: */
178: public function setDefaultCaptureDelay($default_capture_delay)
179: {
180: $this->default_capture_delay = $default_capture_delay;
181:
182: return $this;
183: }
184:
185:
186: /**
187: * {@inheritDoc}
188: */
189: public function getData()
190: {
191: $data = array();
192: $data['plan_id'] = $this->plan_id;
193:
194: if ($this->trial_amount !== null) {
195: $data['trial_amount'] = $this->trial_amount;
196: }
197:
198: if ($this->initial_amount !== null) {
199: $data['initial_amount'] = $this->initial_amount;
200: }
201:
202: if ($this->billing_amount !== null) {
203: $data['billing_amount'] = $this->billing_amount;
204: }
205:
206: if ($this->default_capture_delay !== null) {
207: $data['default_capture_delay'] = $this->default_capture_delay;
208: }
209:
210: return $data;
211: }
212:
213: /**
214: * {@inheritDoc}
215: */
216: public function buildResponse(stdClass $response)
217: {
218: if (!isset($response->plan)) {
219: throw new Syspay_Merchant_UnexpectedResponseException(
220: 'Unable to retrieve "plan" data from response',
221: $response
222: );
223: }
224:
225: $plan = Syspay_Merchant_Entity_Plan::buildFromResponse($response->plan);
226:
227: return $plan;
228: }
229: }
230: