-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #116 from gocardless/template-changes
Add support for webhook endpoints
- Loading branch information
Showing
17 changed files
with
460 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
/** | ||
* WARNING: Do not edit by hand, this file was generated by Crank: | ||
* | ||
* https://github.com/gocardless/crank | ||
*/ | ||
|
||
namespace GoCardlessPro\Resources; | ||
|
||
/** | ||
* A thin wrapper around a webhook, providing access to its | ||
* attributes | ||
* | ||
* @property-read $created_at | ||
* @property-read $id | ||
* @property-read $is_test | ||
* @property-read $request_body | ||
* @property-read $request_headers | ||
* @property-read $response_body | ||
* @property-read $response_body_truncated | ||
* @property-read $response_code | ||
* @property-read $response_headers | ||
* @property-read $response_headers_content_truncated | ||
* @property-read $response_headers_count_truncated | ||
* @property-read $successful | ||
* @property-read $url | ||
*/ | ||
class Webhook extends BaseResource | ||
{ | ||
protected $model_name = "Webhook"; | ||
|
||
/** | ||
* Fixed [timestamp](#api-usage-time-zones--dates), recording when this | ||
* resource was created. | ||
*/ | ||
protected $created_at; | ||
|
||
/** | ||
* Unique identifier, beginning with "WB". | ||
*/ | ||
protected $id; | ||
|
||
/** | ||
* Boolean value showing whether this was a demo webhook for testing | ||
*/ | ||
protected $is_test; | ||
|
||
/** | ||
* The body of the request sent to the webhook URL | ||
*/ | ||
protected $request_body; | ||
|
||
/** | ||
* The request headers sent with the webhook | ||
*/ | ||
protected $request_headers; | ||
|
||
/** | ||
* The body of the response from the webhook URL | ||
*/ | ||
protected $response_body; | ||
|
||
/** | ||
* Boolean value indicating the webhook response body was truncated | ||
*/ | ||
protected $response_body_truncated; | ||
|
||
/** | ||
* The response code from the webhook request | ||
*/ | ||
protected $response_code; | ||
|
||
/** | ||
* The headers sent with the response from the webhook URL | ||
*/ | ||
protected $response_headers; | ||
|
||
/** | ||
* Boolean indicating the content of response headers was truncated | ||
*/ | ||
protected $response_headers_content_truncated; | ||
|
||
/** | ||
* Boolean indicating the number of response headers was truncated | ||
*/ | ||
protected $response_headers_count_truncated; | ||
|
||
/** | ||
* Boolean indicating whether the request was successful or failed | ||
*/ | ||
protected $successful; | ||
|
||
/** | ||
* URL the webhook was POST-ed to | ||
*/ | ||
protected $url; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
<?php | ||
/** | ||
* WARNING: Do not edit by hand, this file was generated by Crank: | ||
* | ||
* https://github.com/gocardless/crank | ||
*/ | ||
|
||
namespace GoCardlessPro\Services; | ||
|
||
use \GoCardlessPro\Core\Paginator; | ||
use \GoCardlessPro\Core\Util; | ||
use \GoCardlessPro\Core\ListResponse; | ||
use \GoCardlessPro\Resources\Webhook; | ||
use \GoCardlessPro\Core\Exception\InvalidStateException; | ||
|
||
|
||
/** | ||
* Service that provides access to the Webhook | ||
* endpoints of the API | ||
* | ||
* @method list() | ||
* @method get() | ||
* @method retry() | ||
*/ | ||
class WebhooksService extends BaseService | ||
{ | ||
|
||
protected $envelope_key = 'webhooks'; | ||
protected $resource_class = '\GoCardlessPro\Resources\Webhook'; | ||
|
||
|
||
/** | ||
* List webhooks | ||
* | ||
* Example URL: /webhooks | ||
* | ||
* @param string[mixed] $params An associative array for any params | ||
* @return ListResponse | ||
**/ | ||
protected function _doList($params = array()) | ||
{ | ||
$path = "/webhooks"; | ||
if(isset($params['params'])) { $params['query'] = $params['params']; | ||
unset($params['params']); | ||
} | ||
|
||
|
||
$response = $this->api_client->get($path, $params); | ||
|
||
|
||
return $this->getResourceForResponse($response); | ||
} | ||
|
||
/** | ||
* Get a single webhook | ||
* | ||
* Example URL: /webhooks/:identity | ||
* | ||
* @param string $identity Unique identifier, beginning with "WB". | ||
* @param string[mixed] $params An associative array for any params | ||
* @return Webhook | ||
**/ | ||
public function get($identity, $params = array()) | ||
{ | ||
$path = Util::subUrl( | ||
'/webhooks/:identity', | ||
array( | ||
|
||
'identity' => $identity | ||
) | ||
); | ||
if(isset($params['params'])) { $params['query'] = $params['params']; | ||
unset($params['params']); | ||
} | ||
|
||
|
||
$response = $this->api_client->get($path, $params); | ||
|
||
|
||
return $this->getResourceForResponse($response); | ||
} | ||
|
||
/** | ||
* Retry a webhook | ||
* | ||
* Example URL: /webhooks/:identity/actions/retry | ||
* | ||
* @param string $identity Unique identifier, beginning with "WB". | ||
* @param string[mixed] $params An associative array for any params | ||
* @return Webhook | ||
**/ | ||
public function retry($identity, $params = array()) | ||
{ | ||
$path = Util::subUrl( | ||
'/webhooks/:identity/actions/retry', | ||
array( | ||
|
||
'identity' => $identity | ||
) | ||
); | ||
if(isset($params['params'])) { | ||
$params['body'] = json_encode(array("data" => (object)$params['params'])); | ||
|
||
unset($params['params']); | ||
} | ||
|
||
|
||
try { | ||
$response = $this->api_client->post($path, $params); | ||
} catch(InvalidStateException $e) { | ||
if ($e->isIdempotentCreationConflict()) { | ||
if ($this->api_client->error_on_idempotency_conflict) { | ||
throw $e; | ||
} | ||
return $this->get($e->getConflictingResourceId()); | ||
} | ||
|
||
throw $e; | ||
} | ||
|
||
|
||
return $this->getResourceForResponse($response); | ||
} | ||
|
||
/** | ||
* List webhooks | ||
* | ||
* Example URL: /webhooks | ||
* | ||
* @param string[mixed] $params | ||
* @return Paginator | ||
**/ | ||
public function all($params = array()) | ||
{ | ||
return new Paginator($this, $params); | ||
} | ||
|
||
} |
Oops, something went wrong.