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

Feature/add capabilities endpoint #762

Merged
merged 7 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from 5 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
23 changes: 23 additions & 0 deletions examples/capabilities/get-capability.php
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());
}
25 changes: 25 additions & 0 deletions examples/capabilities/list-capabilities.php
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());
}
10 changes: 10 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -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
Expand Down
48 changes: 48 additions & 0 deletions src/Endpoints/CapabilityEndpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Mollie\Api\Endpoints;

use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\Capability;
use Mollie\Api\Resources\CapabilityCollection;

class CapabilityEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "capabilities";

protected function getResourceCollectionObject($count, $_links)
{
return new CapabilityCollection($count, $_links);
}

protected function getResourceObject()
{
return new Capability($this->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 list(array $parameters = [])
{
return parent::rest_list(null, null, $parameters);
}
}
9 changes: 8 additions & 1 deletion src/MollieApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -109,6 +110,11 @@ class MollieApiClient
*/
public $methodIssuers;

/**
* @var \Mollie\Api\Endpoints\CapabilityEndpoint
*/
public $capabilities;

/**
* RESTful Customers resource.
*
Expand Down Expand Up @@ -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);
Expand Down
64 changes: 64 additions & 0 deletions src/Resources/Capability.php
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';
}
}
14 changes: 14 additions & 0 deletions src/Resources/CapabilityCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Mollie\Api\Resources;

class CapabilityCollection extends BaseCollection
{
/**
* @return string
*/
public function getCollectionResourceName()
{
return "capabilities";
}
}
143 changes: 143 additions & 0 deletions tests/Mollie/API/Endpoints/CapabilityEndpointTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
<?php

namespace Tests\Mollie\Api\Endpoints;

use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use Mollie\Api\Resources\Capability;
use Mollie\Api\Resources\CapabilityCollection;
use Tests\Mollie\TestHelpers\LinkObjectTestHelpers;

class CapabilityEndpointTest extends BaseEndpointTest
{
use LinkObjectTestHelpers;

public function testGet()
{
$this->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->list();

$this->assertInstanceOf(CapabilityCollection::class, $capabilities);
$this->assertCount(2, $capabilities);
}
}