From ec651cc64280a46c15aa6f5c2a91a8a2a4057b8e Mon Sep 17 00:00:00 2001 From: pkopac Date: Mon, 13 Feb 2017 09:35:59 +0100 Subject: [PATCH] Add setCancellationDates; simple docker travis build config --- .travis.yml | 7 +++++++ README.md | 7 ++++++- src/Import/Subscription.php | 38 ++++++++++++++++++++++++++++--------- 3 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..2e3480a --- /dev/null +++ b/.travis.yml @@ -0,0 +1,7 @@ +sudo: required + +services: + - docker + +script: + - make test diff --git a/README.md b/README.md index 50dae69..9b3a7de 100644 --- a/README.md +++ b/README.md @@ -417,11 +417,16 @@ $subscriptions = $cus->subscriptions(); ```php $canceldate = '2016-01-01T10:00:00.000Z'; $cus = new ChartMogul\Import\Customer([ - "uuid" => "cus_uuid" + 'uuid' => 'cus_uuid' ]); $subscription = $subscriptions->last()->cancel($canceldate); ``` +Or set the cancellation dates: +```php +$cancellationDates = ['2016-01-01T10:00:00.000Z', '2017-01-01T10:00:00.000Z'] +$subscription = $subscriptions->last()->setCancellationDates($cancellationDates) +``` ### Metrics API diff --git a/src/Import/Subscription.php b/src/Import/Subscription.php index 022823d..7e816aa 100644 --- a/src/Import/Subscription.php +++ b/src/Import/Subscription.php @@ -16,7 +16,7 @@ class Subscription extends AbstractResource use \ChartMogul\Service\CreateTrait; use \ChartMogul\Service\AllTrait; - + /** * @ignore */ @@ -36,6 +36,19 @@ class Subscription extends AbstractResource protected $plan_uuid; protected $data_source_uuid; + + + private function cancellation($payload) + { + $response = $this->getClient()->send( + '/v1/import/subscriptions/'.$this->uuid, + 'PATCH', + $payload + ); + $this->cancellation_dates = $response['cancellation_dates']; + return $this; + } + /** * Cancels a subscription that was generated from an imported invoice. * @param string $cancelledAt The time at which the subscription was cancelled. @@ -43,16 +56,23 @@ class Subscription extends AbstractResource */ public function cancel($cancelledAt) { - $response = $this->getClient()->send( - '/v1/import/subscriptions/'.$this->uuid, - 'PATCH', - [ + return $this->cancellation([ 'cancelled_at' => $cancelledAt - ] - ); - $this->cancellation_dates = $response['cancellation_dates']; - return $this; + ]); + } + + /** + * Changes dates of cancellation for a subscription. + * @param array $cancellationDates The array of times (strings) at which the subscription was cancelled. + * @return Subscription + */ + public function setCancellationDates($cancellationDates) + { + return $this->cancellation([ + 'cancellation_dates' => $cancellationDates + ]); } + /** * @param array $data * @param ClientInterface|null $client