diff --git a/examples/capabilities/get-capability.php b/examples/capabilities/get-capability.php new file mode 100644 index 00000000..4feb7f36 --- /dev/null +++ b/examples/capabilities/get-capability.php @@ -0,0 +1,23 @@ +capabilities->get("payments"); + + echo $capability->name; +} catch (\Mollie\Api\Exceptions\ApiException $e) { + echo "API call failed: " . htmlspecialchars($e->getMessage()); +} diff --git a/examples/capabilities/list-capabilities.php b/examples/capabilities/list-capabilities.php new file mode 100644 index 00000000..27c2fec2 --- /dev/null +++ b/examples/capabilities/list-capabilities.php @@ -0,0 +1,25 @@ +capabilities->list(); + + foreach ($capabilities as $capability) { + echo '
'; + echo htmlspecialchars($capability->name) . + ' - ' . htmlspecialchars($capability->status) . + ' (' . htmlspecialchars($capability->name) . ')'; + echo '
'; + } +} catch (\Mollie\Api\Exceptions\ApiException $e) { + echo "API call failed: " . htmlspecialchars($e->getMessage()); +} diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 17bb3a20..39aa3335 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,5 +1,15 @@ parameters: ignoreErrors: + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/capabilities/get-capability.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/capabilities/list-capabilities.php + - message: "#^Variable \\$mollie might not be defined\\.$#" count: 1 diff --git a/src/Endpoints/CapabilityEndpoint.php b/src/Endpoints/CapabilityEndpoint.php new file mode 100644 index 00000000..bfece64c --- /dev/null +++ b/src/Endpoints/CapabilityEndpoint.php @@ -0,0 +1,48 @@ +client); + } + + /** + * Retrieve a single capability from Mollie. + * + * @param string $name + * @param array $parameters + * @return \Mollie\Api\Resources\Capability|\Mollie\Api\Resources\BaseResource + * @throws ApiException + */ + public function get(string $name, array $parameters = []) + { + return parent::rest_read($name, $parameters); + } + + /** + * Retrieve all capabilities. + * + * @param array $parameters + * + * @return CapabilityCollection + * @throws ApiException + */ + public function all(array $parameters = []) + { + return parent::rest_list(null, null, $parameters); + } +} diff --git a/src/MollieApiClient.php b/src/MollieApiClient.php index 9b98e586..64cef8b4 100644 --- a/src/MollieApiClient.php +++ b/src/MollieApiClient.php @@ -5,6 +5,7 @@ use Mollie\Api\Endpoints\BalanceEndpoint; use Mollie\Api\Endpoints\BalanceReportEndpoint; use Mollie\Api\Endpoints\BalanceTransactionEndpoint; +use Mollie\Api\Endpoints\CapabilityEndpoint; use Mollie\Api\Endpoints\ChargebackEndpoint; use Mollie\Api\Endpoints\ClientEndpoint; use Mollie\Api\Endpoints\ClientLinkEndpoint; @@ -55,7 +56,7 @@ class MollieApiClient /** * Version of our client. */ - public const CLIENT_VERSION = "2.76.1"; + public const CLIENT_VERSION = "2.77.1"; /** * Endpoint of the remote API. @@ -109,6 +110,11 @@ class MollieApiClient */ public $methodIssuers; + /** + * @var \Mollie\Api\Endpoints\CapabilityEndpoint + */ + public $capabilities; + /** * RESTful Customers resource. * @@ -425,6 +431,7 @@ public function initializeEndpoints() $this->balanceReports = new BalanceReportEndpoint($this); $this->balanceTransactions = new BalanceTransactionEndpoint($this); $this->balances = new BalanceEndpoint($this); + $this->capabilities = new CapabilityEndpoint($this); $this->chargebacks = new ChargebackEndpoint($this); $this->clientLinks = new ClientLinkEndpoint($this); $this->clients = new ClientEndpoint($this); diff --git a/src/Resources/Capability.php b/src/Resources/Capability.php new file mode 100644 index 00000000..8420e39c --- /dev/null +++ b/src/Resources/Capability.php @@ -0,0 +1,66 @@ +status === CapabilityStatus::ENABLED; + } + + public function isPending() + { + return $this->status === CapabilityStatus::PENDING; + } + + public function isDisabled() + { + return $this->status === CapabilityStatus::DISABLED; + } +} diff --git a/src/Resources/CapabilityCollection.php b/src/Resources/CapabilityCollection.php new file mode 100644 index 00000000..b94a662f --- /dev/null +++ b/src/Resources/CapabilityCollection.php @@ -0,0 +1,14 @@ +mockApiCall( + new Request('GET', '/v2/capabilities/payments'), + new Response( + 200, + [], + '{ + "resource": "capability", + "name": "payments", + "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" + } + } + }' + ) + ); + + $capability = $this->apiClient->capabilities->get('payments'); + + $this->assertInstanceOf(Capability::class, $capability); + } + + public function testList() + { + $this->mockApiCall( + new Request('GET', '/v2/capabilities'), + new Response( + 200, + [], + '{ + "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" + } + } + }' + ) + ); + + $capabilities = $this->apiClient->capabilities->all(); + + $this->assertInstanceOf(CapabilityCollection::class, $capabilities); + $this->assertCount(2, $capabilities); + } +}