Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add subscriptions resource #132

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
Expand Down
3 changes: 3 additions & 0 deletions src/Pipedrive.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/PipedriveFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
128 changes: 128 additions & 0 deletions src/Resources/Subscriptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?php

namespace Devio\Pipedrive\Resources;

use Devio\Pipedrive\Http\Response;
use Devio\Pipedrive\Resources\Basics\Resource;

class Subscriptions extends Resource
{
protected $enabled = ['find', 'delete'];

/**
* Find subscription by deal.
*
* @param int $deal_id
* @return Response
*/
public function findByDealId($deal_id)
{
return $this->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);
}

}