diff --git a/src/Http/Request.php b/src/Http/Request.php index 886b7eb..c3a45f4 100644 --- a/src/Http/Request.php +++ b/src/Http/Request.php @@ -92,6 +92,10 @@ protected function handleResponse(Response $response) // and include the server error if found. If it is OK and also server // inludes the success variable, we will return the response data. if (!isset($content) || !($response->getStatusCode() == 302 || $response->isSuccess())) { + if ($response->getStatusCode() == 204) { + throw new ItemNotFoundException("No Content."); + } + if ($response->getStatusCode() == 404) { throw new ItemNotFoundException(isset($content->error) ? $content->error : "Error unknown."); } diff --git a/src/Pipedrive.php b/src/Pipedrive.php index dc28e93..9f13ff0 100644 --- a/src/Pipedrive.php +++ b/src/Pipedrive.php @@ -35,6 +35,7 @@ use Devio\Pipedrive\Resources\Roles; use Devio\Pipedrive\Resources\SearchResults; use Devio\Pipedrive\Resources\Stages; +use Devio\Pipedrive\Resources\Subscriptions; use Devio\Pipedrive\Resources\UserConnections; use Devio\Pipedrive\Resources\Users; use Devio\Pipedrive\Resources\UserSettings; @@ -77,6 +78,7 @@ * @method Roles roles() * @method SearchResults searchResults() * @method Stages stages() + * @method Subscriptions subscriptions() * @method UserConnections userConnections() * @method Users users() * @method UserSettings userSettings() @@ -113,6 +115,7 @@ * @property-read Roles $roles * @property-read SearchResults $searchResults * @property-read Stages $stages + * @property-read Subscriptions $subscriptions * @property-read UserConnections $userConnections * @property-read Users $users * @property-read UserSettings $userSettings diff --git a/src/PipedriveFacade.php b/src/PipedriveFacade.php index 5e776c5..3d48570 100644 --- a/src/PipedriveFacade.php +++ b/src/PipedriveFacade.php @@ -37,6 +37,7 @@ * @method static Resources\Roles roles() * @method static Resources\SearchResults searchResults() * @method static Resources\Stages stages() + * @method static Resources\Subscriptions subscriptions() * @method static Resources\UserConnections userConnections() * @method static Resources\Users users() * @method static Resources\UserSettings userSettings() @@ -72,6 +73,7 @@ * @property-read Resources\Roles $roles * @property-read Resources\SearchResults $searchResults * @property-read Resources\Stages $stages + * @property-read Resources\Subscriptions $subscriptions * @property-read Resources\UserConnections $userConnections * @property-read Resources\Users $users * @property-read Resources\UserSettings $userSettings diff --git a/src/Resources/Subscriptions.php b/src/Resources/Subscriptions.php new file mode 100644 index 0000000..5308fe8 --- /dev/null +++ b/src/Resources/Subscriptions.php @@ -0,0 +1,128 @@ +request->get('find/:deal_id', compact('deal_id')); + } + + /** + * Find an element by name. + * + * @param int $id + * @return Response + */ + public function payments($id) + { + return $this->request->get(':id/payments', compact('id')); + } + + /** + * Add a recurring subscription. + * + * @param int $deal_id + * @param string $currency + * @param string $description + * @param string $cadence_type + * @param int $cycle_amount + * @param string $start_date + * @param array $options + * @return Response + */ + public function addRecurring($deal_id, $currency, $description, $cadence_type, $cycle_amount, $start_date, $options = []) + { + $options = array_merge( + compact('deal_id', 'currency', 'description', 'cadence_type', 'cycle_amount', 'start_date'), + $options + ); + + return $this->request->post('recurring', $options); + } + + /** + * Update a recurring subscription. + * + * @param int $id + * @param string $effective_date + * @param array $options + * @return Response + */ + public function updateRecurring($id, $effective_date, $options = []) + { + $options = array_merge( + compact('id','effective_date'), + $options + ); + + return $this->request->put('recurring/:id', $options); + } + + /** + * Cancel a recurring subscription. + * + * @param int $id + * @param array $options + * @return Response + */ + public function cancelRecurring($id, $options = []) + { + $options = array_merge( + compact('id'), + $options + ); + + return $this->request->put('recurring/:id/cancel', $options); + } + + /** + * Add an installment subscription. + * + * @param int $deal_id + * @param string $currency + * @param array $payments + * @param array $options + * @return Response + */ + public function addInstallment($deal_id, $currency, $payments, $options = []) + { + $options = array_merge( + compact('deal_id', 'currency', 'payments'), + $options + ); + + return $this->request->post('installment', $options); + } + + /** + * Update an installment subscription. + * + * @param int $id + * @param array $payments + * @param array $options + * @return Response + */ + public function updateInstallment($id, $payments, $options = []) + { + $options = array_merge( + compact('id', 'payments'), + $options + ); + + return $this->request->put('installment/:id', $options); + } + +}