Skip to content

Commit 2c7cc0a

Browse files
Update Create plan request (#185)
* Update Create plan request * Remove BC and add deprecated
1 parent d287bd3 commit 2c7cc0a

File tree

3 files changed

+304
-21
lines changed

3 files changed

+304
-21
lines changed

src/Message/CreatePlanRequest.php

Lines changed: 289 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Stripe Create Plan Request
1111
*
1212
* @see \Omnipay\Stripe\Gateway
13-
* @link https://stripe.com/docs/api#create_plan
13+
* @link https://stripe.com/docs/api/plans/create
1414
*/
1515
class CreatePlanRequest extends AbstractRequest
1616
{
@@ -79,27 +79,30 @@ public function getIntervalCount()
7979

8080
/**
8181
* Set the plan name
82+
* @deprecated use setNickname() instead
8283
*
8384
* @param $value
8485
* @return \Omnipay\Common\Message\AbstractRequest|CreatePlanRequest
8586
*/
8687
public function setName($value)
8788
{
88-
return $this->setParameter('name', $value);
89+
return $this->setNickname($value);
8990
}
9091

9192
/**
9293
* Get the plan name
94+
* @deprecated use getNickname() instead
9395
*
9496
* @return string
9597
*/
9698
public function getName()
9799
{
98-
return $this->getParameter('name');
100+
return $this->getNickname();
99101
}
100102

101103
/**
102104
* Set the plan statement descriptor
105+
* @deprecated Not used anymore
103106
*
104107
* @param $planStatementDescriptor
105108
* @return \Omnipay\Common\Message\AbstractRequest|CreatePlanRequest
@@ -111,6 +114,7 @@ public function setStatementDescriptor($planStatementDescriptor)
111114

112115
/**
113116
* Get the plan statement descriptor
117+
* @deprecated Not used anymore
114118
*
115119
* @return string
116120
*/
@@ -119,6 +123,192 @@ public function getStatementDescriptor()
119123
return $this->getParameter('statement_descriptor');
120124
}
121125

126+
/**
127+
* Set the plan product
128+
*
129+
* @param $value
130+
* @return \Omnipay\Common\Message\AbstractRequest|CreatePlanRequest
131+
*/
132+
public function setProduct($value)
133+
{
134+
return $this->setParameter('product', $value);
135+
}
136+
137+
/**
138+
* Get the plan product
139+
*
140+
* @return string|array
141+
*/
142+
public function getProduct()
143+
{
144+
return $this->getParameter('product');
145+
}
146+
147+
/**
148+
* Set the plan amount
149+
* @param $value
150+
* @return \Omnipay\Common\Message\AbstractRequest|CreatePlanRequest
151+
*/
152+
public function setAmount($value)
153+
{
154+
return $this->setParameter('amount', (integer)$value);
155+
}
156+
157+
/**
158+
* Get the plan amount
159+
*
160+
* @return int
161+
*/
162+
public function getAmount()
163+
{
164+
return $this->getParameter('amount');
165+
}
166+
167+
/**
168+
* Set the plan tiers
169+
* @param $value
170+
* @return \Omnipay\Common\Message\AbstractRequest|CreatePlanRequest
171+
*/
172+
public function setTiers($value)
173+
{
174+
return $this->setParameter('tiers', $value);
175+
}
176+
177+
/**
178+
* Get the plan tiers
179+
*
180+
* @return int
181+
*/
182+
public function getTiers()
183+
{
184+
return $this->getParameter('tiers');
185+
}
186+
187+
/**
188+
* Set the plan tiers mode
189+
* @param $value
190+
* @return \Omnipay\Common\Message\AbstractRequest|CreatePlanRequest
191+
*/
192+
public function setTiersMode($value)
193+
{
194+
return $this->setParameter('tiers_mode', $value);
195+
}
196+
197+
/**
198+
* Get the plan tiers mode
199+
*
200+
* @return int
201+
*/
202+
public function getTiersMode()
203+
{
204+
return $this->getParameter('tiers_mode');
205+
}
206+
207+
/**
208+
* Set the plan nickname
209+
*
210+
* @param $value
211+
* @return \Omnipay\Common\Message\AbstractRequest|CreatePlanRequest
212+
*/
213+
public function setNickname($value)
214+
{
215+
return $this->setParameter('nickname', $value);
216+
}
217+
218+
/**
219+
* Get the plan nickname
220+
*
221+
* @return string|array
222+
*/
223+
public function getNickname()
224+
{
225+
return $this->getParameter('nickname');
226+
}
227+
228+
/**
229+
* Set the plan metadata
230+
*
231+
* @param $value
232+
* @return \Omnipay\Common\Message\AbstractRequest|CreatePlanRequest
233+
*/
234+
public function setMetadata($value)
235+
{
236+
return $this->setParameter('metadata', $value);
237+
}
238+
239+
/**
240+
* Get the plan metadata
241+
*
242+
* @return string|array
243+
*/
244+
public function getMetadata()
245+
{
246+
return $this->getParameter('metadata');
247+
}
248+
249+
/**
250+
* Set the plan active
251+
*
252+
* @param $value
253+
* @return \Omnipay\Common\Message\AbstractRequest|CreatePlanRequest
254+
*/
255+
public function setActive($value)
256+
{
257+
return $this->setParameter('active', $value);
258+
}
259+
260+
/**
261+
* Get the plan active
262+
*
263+
* @return string|array
264+
*/
265+
public function getActive()
266+
{
267+
return $this->getParameter('active');
268+
}
269+
270+
/**
271+
* Set the plan billingScheme
272+
*
273+
* @param $value
274+
* @return \Omnipay\Common\Message\AbstractRequest|CreatePlanRequest
275+
*/
276+
public function setBillingScheme($value)
277+
{
278+
return $this->setParameter('billing_scheme', $value);
279+
}
280+
281+
/**
282+
* Get the plan billingScheme
283+
*
284+
* @return string|array
285+
*/
286+
public function getBillingScheme()
287+
{
288+
return $this->getParameter('billing_scheme');
289+
}
290+
291+
/**
292+
* Set the plan aggregate usage
293+
*
294+
* @param $planAggregateUsage
295+
* @return \Omnipay\Common\Message\AbstractRequest|CreatePlanRequest
296+
*/
297+
public function setAggregateUsage($planAggregateUsage)
298+
{
299+
return $this->setParameter('aggregate_usage', $planAggregateUsage);
300+
}
301+
302+
/**
303+
* Get the plan aggregate usage
304+
*
305+
* @return string
306+
*/
307+
public function getAggregateUsage()
308+
{
309+
return $this->getParameter('aggregate_usage');
310+
}
311+
122312
/**
123313
* Set the plan trial period days
124314
*
@@ -140,31 +330,114 @@ public function getTrialPeriodDays()
140330
return $this->getParameter('trial_period_days');
141331
}
142332

333+
/**
334+
* Set the plan transform usage
335+
*
336+
* @param $value
337+
* @return \Omnipay\Common\Message\AbstractRequest|CreatePlanRequest
338+
*/
339+
public function setTransformUsage($value)
340+
{
341+
return $this->setParameter('transform_usage', $value);
342+
}
343+
344+
/**
345+
* Get the plan transform usage
346+
*
347+
* @return int
348+
*/
349+
public function getTransformUsage()
350+
{
351+
return $this->getParameter('transform_usage');
352+
}
353+
354+
/**
355+
* Set the plan usage type
356+
*
357+
* @param $value
358+
* @return \Omnipay\Common\Message\AbstractRequest|CreatePlanRequest
359+
*/
360+
public function setUsageType($value)
361+
{
362+
return $this->setParameter('usage_type', $value);
363+
}
364+
365+
/**
366+
* Get the plan usage type
367+
*
368+
* @return int
369+
*/
370+
public function getUsageType()
371+
{
372+
return $this->getParameter('usage_type');
373+
}
374+
143375
public function getData()
144376
{
145-
$this->validate('id', 'amount', 'currency', 'interval', 'name');
377+
$this->validate('currency', 'interval', 'product');
378+
379+
if (null == $this->getBillingScheme() || 'per_unit' == $this->getBillingScheme()) {
380+
$this->validate('amount');
381+
} elseif ('tiered' == $this->getBillingScheme()) {
382+
$this->validate('tiers', 'tiers_mode');
383+
}
146384

147385
$data = array(
148-
'id' => $this->getId(),
149-
'amount' => $this->getAmountInteger(),
150386
'currency' => $this->getCurrency(),
151387
'interval' => $this->getInterval(),
152-
'name' => $this->getName()
388+
'product' => $this->getProduct()
153389
);
154390

155-
$intervalCount = $this->getIntervalCount();
156-
if ($intervalCount != null) {
157-
$data['interval_count'] = $intervalCount;
391+
if (null != $this->getBillingScheme()) {
392+
$data['billing_scheme'] = $this->getBillingScheme();
393+
}
394+
395+
if (null != $this->getId()) {
396+
$data['id'] = $this->getId();
397+
}
398+
399+
if (null != $this->getAmount()) {
400+
$data['amount'] = $this->getAmount();
401+
}
402+
403+
if (null != $this->getNickName()) {
404+
$data['nickname'] = $this->getNickName();
405+
}
406+
407+
if (null != $this->getMetadata()) {
408+
$data['metadata'] = $this->getMetadata();
409+
}
410+
411+
if (null != $this->getActive()) {
412+
$data['active'] = $this->getActive();
413+
}
414+
415+
if (null != $this->getIntervalCount()) {
416+
$data['interval_count'] = $this->getIntervalCount();
417+
}
418+
419+
if (null != $this->getAggregateUsage()) {
420+
$data['aggregate_usage'] = $this->getAggregateUsage();
421+
}
422+
423+
if (null != $this->getTrialPeriodDays()) {
424+
$data['trial_period_days'] = $this->getTrialPeriodDays();
425+
}
426+
427+
if (null != $this->getTransformUsage()) {
428+
$data['transform_usage'] = $this->getTransformUsage();
429+
}
430+
431+
if (null != $this->getUsageType()) {
432+
$data['usage_type'] = $this->getUsageType();
158433
}
159434

160-
$statementDescriptor = $this->getStatementDescriptor();
161-
if ($statementDescriptor != null) {
162-
$data['statement_descriptor'] = $statementDescriptor;
435+
if (null != $this->getTiers()) {
436+
$data['tiers'] = $this->getTiers();
163437
}
164438

165-
$trialPeriodDays = $this->getTrialPeriodDays();
166-
if ($trialPeriodDays != null) {
167-
$data['trial_period_days'] = $trialPeriodDays;
439+
if (null != $this->getTiersMode()) {
440+
$data['tiers_mode'] = $this->getTiersMode();
168441
}
169442

170443
return $data;

tests/Message/CreatePlanRequestTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ public function setUp()
1818
$this->request->setAmount('19.00');
1919
$this->request->setCurrency('usd');
2020
$this->request->setInterval('month');
21-
$this->request->setName('Amazing Gold Plan');
21+
$this->request->setNickname('Amazing Gold Plan');
22+
$this->request->setProduct('prod_GWN5y0jpQeU9yj');
2223
$this->request->setIntervalCount(1);
23-
$this->request->setStatementDescriptor('Omnipay Basic Plan');
24+
$this->request->setActive(false);
2425
$this->request->setTrialPeriodDays(3);
2526
}
2627

@@ -38,6 +39,7 @@ public function testSendSuccess()
3839
$this->assertFalse($response->isRedirect());
3940
$this->assertSame('basic', $response->getPlanId());
4041
$this->assertNotNull($response->getPlan());
42+
$this->assertFalse($response->getPlan()['active']);
4143
$this->assertNull($response->getMessage());
4244
}
4345

0 commit comments

Comments
 (0)