-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add capability endpoint (beta)
- Loading branch information
Showing
15 changed files
with
446 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
/* | ||
* Get a capability using the Mollie API. | ||
*/ | ||
|
||
try { | ||
/* | ||
* Initialize the Mollie API library with your OAuth access token. | ||
*/ | ||
require "../initialize_with_oauth.php"; | ||
|
||
/* | ||
* Get the capability with ID "cap_1234567890" | ||
* | ||
* See: https://docs.mollie.com/reference/v2/capabilities-api/get-capability | ||
*/ | ||
$capability = $mollie->capabilities->get("payments"); | ||
|
||
echo $capability->name; | ||
} catch (\Mollie\Api\Exceptions\ApiException $e) { | ||
echo "API call failed: " . htmlspecialchars($e->getMessage()); | ||
} |
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,25 @@ | ||
<?php | ||
/* | ||
* Using access token to list capabilities of an account. | ||
*/ | ||
try { | ||
/* | ||
* Initialize the Mollie API library with your OAuth access token. | ||
*/ | ||
require "../initialize_with_oauth.php"; | ||
|
||
/* | ||
* Get the all the capabilities for this account. | ||
*/ | ||
$capabilities = $mollie->capabilities->list(); | ||
|
||
foreach ($capabilities as $capability) { | ||
echo '<div style="line-height:40px; vertical-align:top">'; | ||
echo htmlspecialchars($capability->name) . | ||
' - ' . htmlspecialchars($capability->status) . | ||
' (' . htmlspecialchars($capability->name) . ')'; | ||
echo '</div>'; | ||
} | ||
} catch (\Mollie\Api\Exceptions\ApiException $e) { | ||
echo "API call failed: " . htmlspecialchars($e->getMessage()); | ||
} |
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,36 @@ | ||
<?php | ||
|
||
namespace Mollie\Api\EndpointCollection; | ||
|
||
use Mollie\Api\Exceptions\RequestException; | ||
use Mollie\Api\Http\Requests\GetCapabilityRequest; | ||
use Mollie\Api\Http\Requests\ListCapabilitiesRequest; | ||
use Mollie\Api\Resources\Capability; | ||
use Mollie\Api\Resources\CapabilityCollection; | ||
|
||
class CapabilityEndpointCollection extends EndpointCollection | ||
{ | ||
/** | ||
* Retrieve a single Permission from Mollie. | ||
* | ||
* Will throw an ApiException if the permission id is invalid. | ||
* | ||
* @throws RequestException | ||
*/ | ||
public function get(string $name): Capability | ||
{ | ||
/** @var Capability */ | ||
return $this->send((new GetCapabilityRequest($name))); | ||
} | ||
|
||
/** | ||
* Retrieve all capabilities from Mollie. | ||
* | ||
* @throws RequestException | ||
*/ | ||
public function list(): CapabilityCollection | ||
{ | ||
/** @var CapabilityCollection */ | ||
return $this->send(new ListCapabilitiesRequest); | ||
} | ||
} |
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,70 @@ | ||
{ | ||
"count": 2, | ||
"_embedded": { | ||
"capabilities": [ | ||
{ | ||
"resource": "capability", | ||
"name": "payments", | ||
"requirements": [ | ||
{ | ||
"name": "legal-representatives", | ||
"dueDate": null, | ||
"status": "requested" | ||
}, | ||
{ | ||
"name": "bank-account", | ||
"dueDate": null, | ||
"status": "requested" | ||
} | ||
], | ||
"status": "pending", | ||
"statusReason": "onboarding-information-needed", | ||
"organizationId": "org_12345678", | ||
"_links": { | ||
"self": { | ||
"href": "...", | ||
"type": "application/hal+json" | ||
}, | ||
"dashboard": { | ||
"href": "https://my.mollie.com/dashboard/...", | ||
"type": "text/html" | ||
} | ||
} | ||
}, | ||
{ | ||
"resource": "capability", | ||
"name": "capital", | ||
"requirements": [ | ||
{ | ||
"name": "legal-representatives", | ||
"dueDate": "2024-05-14T01:29:09.0Z", | ||
"status": "past-due" | ||
} | ||
], | ||
"status": "disabled", | ||
"statusReason": "requirement-past-due", | ||
"organizationId": "org_12345678", | ||
"_links": { | ||
"self": { | ||
"href": "...", | ||
"type": "application/hal+json" | ||
}, | ||
"dashboard": { | ||
"href": "https://my.mollie.com/dashboard/...", | ||
"type": "text/html" | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"_links": { | ||
"self": { | ||
"href": "...", | ||
"type": "application/hal+json" | ||
}, | ||
"documentation": { | ||
"href": "...", | ||
"type": "text/html" | ||
} | ||
} | ||
} |
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,28 @@ | ||
{ | ||
"resource": "capability", | ||
"name": "{{ RESOURCE_ID }}", | ||
"requirements": [ | ||
{ | ||
"name": "legal-representatives", | ||
"dueDate": null, | ||
"status": "requested" | ||
} | ||
], | ||
"status": "pending", | ||
"statusReason": "onboarding-information-needed", | ||
"organizationId": "org_12345678", | ||
"_links": { | ||
"self": { | ||
"href": "...", | ||
"type": "application/hal+json" | ||
}, | ||
"dashboard": { | ||
"href": "https://my.mollie.com/dashboard/...", | ||
"type": "text/html" | ||
}, | ||
"documentation": { | ||
"href": "...", | ||
"type": "text/html" | ||
} | ||
} | ||
} |
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,28 @@ | ||
<?php | ||
|
||
namespace Mollie\Api\Http\Requests; | ||
|
||
use Mollie\Api\Resources\Capability; | ||
use Mollie\Api\Types\Method; | ||
|
||
class GetCapabilityRequest extends ResourceHydratableRequest | ||
{ | ||
protected static string $method = Method::GET; | ||
|
||
/** | ||
* The resource class the request should be casted to. | ||
*/ | ||
protected $hydratableResource = Capability::class; | ||
|
||
private string $name; | ||
|
||
public function __construct(string $name) | ||
{ | ||
$this->name = $name; | ||
} | ||
|
||
public function resolveResourcePath(): string | ||
{ | ||
return "capabilities/{$this->name}"; | ||
} | ||
} |
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,21 @@ | ||
<?php | ||
|
||
namespace Mollie\Api\Http\Requests; | ||
|
||
use Mollie\Api\Resources\CapabilityCollection; | ||
use Mollie\Api\Types\Method; | ||
|
||
class ListCapabilitiesRequest extends ResourceHydratableRequest | ||
{ | ||
protected static string $method = Method::GET; | ||
|
||
/** | ||
* The resource class the request should be casted to. | ||
*/ | ||
protected $hydratableResource = CapabilityCollection::class; | ||
|
||
public function resolveResourcePath(): string | ||
{ | ||
return 'capabilities'; | ||
} | ||
} |
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,64 @@ | ||
<?php | ||
|
||
namespace Mollie\Api\Resources; | ||
|
||
class Capability extends BaseResource | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
public $resource; | ||
|
||
/** | ||
* @var string | ||
* | ||
* @example payments | ||
*/ | ||
public $name; | ||
|
||
/** | ||
* @var \stdClass | ||
*/ | ||
public $requirements; | ||
|
||
/** | ||
* @var string | ||
* | ||
* possible values: disabled, pending, enabled | ||
* | ||
* @example enabled | ||
*/ | ||
public $status; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $statusReason; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $organizationId; | ||
|
||
/** | ||
* Links to help navigate through the Mollie API and related resources. | ||
* | ||
* @var \stdClass | ||
*/ | ||
public $_links; | ||
|
||
public function isEnabled() | ||
{ | ||
return $this->status === 'enabled'; | ||
} | ||
|
||
public function isPending() | ||
{ | ||
return $this->status === 'pending'; | ||
} | ||
|
||
public function isDisabled() | ||
{ | ||
return $this->status === 'disabled'; | ||
} | ||
} |
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,10 @@ | ||
<?php | ||
|
||
namespace Mollie\Api\Resources; | ||
|
||
class CapabilityCollection extends ResourceCollection | ||
{ | ||
public static string $collectionName = 'capabilities'; | ||
|
||
public static string $resource = Capability::class; | ||
} |
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
Oops, something went wrong.