Skip to content

Commit

Permalink
Add Webhooks Endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
tacio7brito committed Aug 21, 2019
1 parent be55760 commit 70256ce
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 5 deletions.
41 changes: 41 additions & 0 deletions src/Contracts/ZoopWebhooks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Zoop\Contracts;

use Zoop\Lib\APIResource;

interface ZoopWebhooks{

/**
* API Resource.
*
* @param $APIResource $APIResource
*/
public function __construct(APIResource $APIResource);

/**
* Create a new Webhook
*
* @param $post array
*/
public function create($post);

/**
* Delete a Webhook by id
*
* @param $webhookID string
*/
public function delete($webhookID);

/**
* Retrieve the details of a Webhook by id
*
* @param $webhookID string
*/
public function get($webhookID);

/**
* Returns a JSON object with a list of plans.
*/
public function getAll();
}
2 changes: 1 addition & 1 deletion src/Exceptions/ZoopAuthenticationException.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

namespace Zoop\Exceptions;
namespace Zoop\src\Exceptions;

class ZoopAuthenticationException extends \Exception{}
2 changes: 1 addition & 1 deletion src/Exceptions/ZoopException.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

namespace Zoop\Exceptions;
namespace Zoop\src\Exceptions;

class ZoopException extends \Exception {}
2 changes: 1 addition & 1 deletion src/Exceptions/ZoopObjectNotFound.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

namespace Zoop\Exceptions;
namespace Zoop\src\Exceptions;

class ZoopObjectNotFound extends \Exception {}
15 changes: 15 additions & 0 deletions src/Facades/ZoopWebhooks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Zoop\Facades;

use Illuminate\Support\Facades\Facade;

class ZoopWebhooks extends Facade{

/**
* @return string
*/
protected static function getFacadeAccessor(){
return 'ZoopWebhooks';
}
}
57 changes: 57 additions & 0 deletions src/Lib/ZoopWebhooks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace Zoop\Lib;


class ZoopWebhooks implements \Zoop\Contracts\ZoopPlans {

/**
* API Resource
*
* @var object
*/
protected $APIResource;

/**
* ZoopPlans constructor.
* @param APIResource $APIResource
*/
public function __construct(APIResource $APIResource){
$this->APIResource = $APIResource;
}

/**
* @param array $post
* @return mixed
*/
public function create($post = []){
$api = 'webhooks';
return $this->APIResource->createAPI($api, $post);
}

/**
* @param string $webhookID
* @return mixed
*/
public function delete($webhookID){
$api = 'webhooks/' . $webhookID;
return $this->APIResource->deleteAPI($api);
}

/**
* @param string $webhookID
* @return mixed
*/
public function get($webhookID){
$api = 'webhooks/' . $webhookID;
return $this->APIResource->searchAPI($api);
}

/**
* @return mixed
*/
public function getAll(){
$api = 'webhooks';
return $this->APIResource->searchAPI($api);
}
}
8 changes: 7 additions & 1 deletion src/ZoopServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Zoop\Lib\ZoopPlans;
use Zoop\Lib\ZoopSubscriptions;
use Zoop\Lib\ZoopInvoices;
use Zoop\Lib\ZoopWebhooks;

class ZoopServiceProvider extends ServiceProvider {

Expand Down Expand Up @@ -80,6 +81,10 @@ public function register(){
$this->app->singleton('ZoopInvoices', function () use ($service) {
return new ZoopInvoices(APIResource::getSingleton($service));
});

$this->app->singleton('ZoopWebhooks', function () use ($service) {
return new ZoopWebhooks(APIResource::getSingleton($service));
});
}

/**
Expand All @@ -96,7 +101,8 @@ public function provides(){
ZoopTransfers::class,
ZoopPlans::class,
ZoopSubscriptions::class,
ZoopInvoices::class
ZoopInvoices::class,
ZoopWebhooks::class
];
}

Expand Down
2 changes: 1 addition & 1 deletion src/resources/config/config.example.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
'endpoint' => 'https://api.zoop.ws',
'endpoint_beta' => 'https://api-beta.zoop.ws',
'api_version' => 'v1',
'apis_use_beta' => ['plans', 'subscriptions', 'invoices'],
'apis_use_beta' => ['tests', 'examples'],
]
];

0 comments on commit 70256ce

Please sign in to comment.