1010 * Stripe Update Subscription Request
1111 *
1212 * @see \Omnipay\Stripe\Gateway
13- * @link https://stripe.com/docs/api#update_subscription
13+ * @link https://stripe.com/docs/api/subscriptions/update
1414 */
1515class UpdateSubscriptionRequest extends AbstractRequest
1616{
@@ -74,9 +74,22 @@ public function setSubscriptionReference($value)
7474 return $ this ->setParameter ('subscriptionReference ' , $ value );
7575 }
7676
77+ /**
78+ * @return bool
79+ */
80+ public function getCancelAtPeriodEnd ()
81+ {
82+ return $ this ->getParameter ('cancel_at_period_end ' );
83+ }
84+
85+ public function setCancelAtPeriodEnd ($ value )
86+ {
87+ return $ this ->setParameter ('cancel_at_period_end ' , $ value );
88+ }
89+
7790 public function getData ()
7891 {
79- $ this ->validate ('customerReference ' , ' subscriptionReference ' , 'plan ' );
92+ $ this ->validate ('subscriptionReference ' , 'plan ' );
8093
8194 $ data = array (
8295 'plan ' => $ this ->getPlan ()
@@ -86,6 +99,10 @@ public function getData()
8699 $ data ['tax_percent ' ] = (float )$ this ->getParameter ('tax_percent ' );
87100 }
88101
102+ if ($ this ->parameters ->has ('cancel_at_period_end ' )) {
103+ $ data ['cancel_at_period_end ' ] = $ this ->getCancelAtPeriodEnd () ? 'true ' : 'false ' ;
104+ }
105+
89106 if ($ this ->getMetadata ()) {
90107 $ data ['metadata ' ] = $ this ->getMetadata ();
91108 }
@@ -95,7 +112,9 @@ public function getData()
95112
96113 public function getEndpoint ()
97114 {
98- return $ this ->endpoint .'/customers/ ' .$ this ->getCustomerReference ()
99- .'/subscriptions/ ' .$ this ->getSubscriptionReference ();
115+ return $ this ->getCustomerReference () ?
116+ $ this ->endpoint .'/customers/ ' .$ this ->getCustomerReference ()
117+ .'/subscriptions/ ' .$ this ->getSubscriptionReference () :
118+ $ this ->endpoint .'/subscriptions/ ' .$ this ->getSubscriptionReference ();
100119 }
101120}
0 commit comments