Skip to content

Commit

Permalink
Merge pull request #728 from sandervanhooft/add_missing_endpoints
Browse files Browse the repository at this point in the history
Add missing endpoints
  • Loading branch information
sandervanhooft authored Jul 17, 2024
2 parents e649712 + e839d85 commit 1987b1c
Show file tree
Hide file tree
Showing 5 changed files with 323 additions and 0 deletions.
85 changes: 85 additions & 0 deletions src/Endpoints/MethodIssuerEndpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

declare(strict_types=1);

namespace Mollie\Api\Endpoints;

use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\Issuer;

class MethodIssuerEndpoint extends EndpointAbstract
{
protected $resourcePath = 'profiles_methods_issuers';

protected $profileId = null;
protected $methodId = null;
protected $issuerId = null;

/**
* @param string $profileId
* @param string $methodId
* @param string $issuerId
* @return Issuer
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function enable(string $profileId, string $methodId, string $issuerId)
{
$this->profileId = $profileId;
$this->methodId = $methodId;
$this->issuerId = $issuerId;

$response = $this->rest_create([], []);

$this->resetResourceIds();

return $response;
}

public function disable(string $profileId, string $methodId, string $issuerId)
{
$this->profileId = $profileId;
$this->methodId = $methodId;

return $this->rest_delete($issuerId);
}

protected function resetResourceIds()
{
$this->profileId = null;
$this->methodId = null;
$this->issuerId = null;
}

/**
* @return string
* @throws ApiException
*/
public function getResourcePath()
{
if (! $this->profileId) {
throw new ApiException("No profileId provided.");
}

if (! $this->methodId) {
throw new ApiException("No methodId provided.");
}

$path = "profiles/{$this->profileId}/methods/{$this->methodId}/issuers";

if ($this->issuerId) {
$path .= "/$this->issuerId";
}

return $path;
}

/**
* Get the object that is used by this API endpoint. Every API endpoint uses one type of object.
*
* @return Issuer
*/
protected function getResourceObject()
{
return new Issuer($this->client);
}
}
79 changes: 79 additions & 0 deletions src/Endpoints/SubscriptionPaymentEndpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

declare(strict_types=1);

namespace Mollie\Api\Endpoints;

use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\Payment;
use Mollie\Api\Resources\PaymentCollection;

class SubscriptionPaymentEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "customers_subscriptions_payments";

protected $customerId = null;

protected $subscriptionId = null;

/**
* Retrieves a paginated collection of Subscription Payments from Mollie.
*
* @param string $customerId
* @param string $subscriptionId
* @param string|null $from The first payment ID you want to include in your list.
* @param int|null $limit The maximum amount of results you want to retrieve per page.
* @param array $parameters
*
* @return PaymentCollection
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function pageForIds(
string $customerId,
string $subscriptionId,
?string $from = null,
?int $limit = null,
array $parameters = []
) {
$this->customerId = $customerId;
$this->subscriptionId = $subscriptionId;

return $this->rest_list($from, $limit, $parameters);
}

/**
* Get the object that is used by this API endpoint. Every API endpoint uses one type of object.
*
* @return Payment
*/
protected function getResourceObject()
{
return new Payment($this->client);
}

/**
* Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object.
*
* @param int $count
* @param \stdClass $_links
*
* @return PaymentCollection
*/
protected function getResourceCollectionObject($count, $_links)
{
return new PaymentCollection($this->client, $count, $_links);
}

public function getResourcePath()
{
if (is_null($this->customerId)) {
throw new ApiException('No customerId provided.');
}

if (is_null($this->subscriptionId)) {
throw new ApiException('No subscriptionId provided.');
}

return "customers/{$this->customerId}/subscriptions/{$this->subscriptionId}/payments";
}
}
16 changes: 16 additions & 0 deletions src/MollieApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Mollie\Api\Endpoints\InvoiceEndpoint;
use Mollie\Api\Endpoints\MandateEndpoint;
use Mollie\Api\Endpoints\MethodEndpoint;
use Mollie\Api\Endpoints\MethodIssuerEndpoint;
use Mollie\Api\Endpoints\OnboardingEndpoint;
use Mollie\Api\Endpoints\OrderEndpoint;
use Mollie\Api\Endpoints\OrderLineEndpoint;
Expand All @@ -38,6 +39,7 @@
use Mollie\Api\Endpoints\SettlementsEndpoint;
use Mollie\Api\Endpoints\ShipmentEndpoint;
use Mollie\Api\Endpoints\SubscriptionEndpoint;
use Mollie\Api\Endpoints\SubscriptionPaymentEndpoint;
use Mollie\Api\Endpoints\TerminalEndpoint;
use Mollie\Api\Endpoints\WalletEndpoint;
use Mollie\Api\Exceptions\ApiException;
Expand Down Expand Up @@ -100,6 +102,11 @@ class MollieApiClient
*/
public $profileMethods;

/**
* @var \Mollie\Api\Endpoints\MethodIssuerEndpoint
*/
public $methodIssuers;

/**
* RESTful Customers resource.
*
Expand Down Expand Up @@ -156,6 +163,13 @@ class MollieApiClient
*/
public $subscriptions;

/**
* RESTful Subscription Payments resource.
*
* @var SubscriptionPaymentEndpoint
*/
public $subscriptionPayments;

/**
* RESTful Mandate resource.
*
Expand Down Expand Up @@ -403,6 +417,7 @@ public function initializeEndpoints()
$this->invoices = new InvoiceEndpoint($this);
$this->mandates = new MandateEndpoint($this);
$this->methods = new MethodEndpoint($this);
$this->methodIssuers = new MethodIssuerEndpoint($this);
$this->onboarding = new OnboardingEndpoint($this);
$this->orderLines = new OrderLineEndpoint($this);
$this->orderPayments = new OrderPaymentEndpoint($this);
Expand All @@ -427,6 +442,7 @@ public function initializeEndpoints()
$this->settlementRefunds = new SettlementRefundEndpoint($this);
$this->settlements = new SettlementsEndpoint($this);
$this->shipments = new ShipmentEndpoint($this);
$this->subscriptionPayments = new SubscriptionPaymentEndpoint($this);
$this->subscriptions = new SubscriptionEndpoint($this);
$this->terminals = new TerminalEndpoint($this);
$this->wallets = new WalletEndpoint($this);
Expand Down
57 changes: 57 additions & 0 deletions tests/Mollie/API/Endpoints/MethodIssuerEndpointTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

declare(strict_types=1);

namespace Tests\Mollie\Api\Endpoints;

use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use Mollie\Api\Resources\Issuer;

class MethodIssuerEndpointTest extends BaseEndpointTest
{
/** @test */
public function testEnableIssuer()
{
$this->mockApiCall(
new Request(
'POST',
'https://api.mollie.com/v2/profiles/pfl_QkEhN94Ba/methods/ideal/issuers/festivalcadeau'
),
new Response(
201,
[],
'{
"resource": "issuer",
"id": "festivalcadeau",
"name": "Festival Cadeau",
"method": "ideal",
"image": {
"size1x": "https://www.mollie.com/images/payscreen/methods/ideal.png",
"size2x": "https://www.mollie.com/images/payscreen/methods/ideal%402x.png"
}
}'
)
);

$response = $this->apiClient->methodIssuers->enable('pfl_QkEhN94Ba', 'ideal', 'festivalcadeau');
$this->assertInstanceOf(Issuer::class, $response);
$this->assertEquals('festivalcadeau', $response->id);
}

/** @test */
public function testDisableIssuer()
{
$this->mockApiCall(
new Request(
'DELETE',
'https://api.mollie.com/v2/profiles/pfl_QkEhN94Ba/methods/ideal/issuers/festivalcadeau'
),
new Response(204)
);

$response = $this->apiClient->methodIssuers->disable('pfl_QkEhN94Ba', 'ideal', 'festivalcadeau');

$this->assertNull($response);
}
}
86 changes: 86 additions & 0 deletions tests/Mollie/API/Endpoints/SubscriptionPaymentEndpointTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

declare(strict_types=1);

namespace Tests\Mollie\API\Endpoints;

use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use Mollie\Api\Resources\PaymentCollection;
use Tests\Mollie\Api\Endpoints\BaseEndpointTest;

class SubscriptionPaymentEndpointTest extends BaseEndpointTest
{
/** @test */
public function testListSubscriptionPayments(): void
{
$this->mockApiCall(
new Request(
'GET',
'/v2/customers/cst_stTC2WHAuS/subscriptions/sub_8JfGzs6v3K/payments?limit=25'
),
new Response(
200,
[],
'{
"count": 1,
"_embedded": {
"payments": [
{
"resource": "payment",
"id": "tr_7UhSN1zuXS",
"mode": "live",
"amount": {
"currency": "EUR",
"value": "25.00"
},
"description": "Quarterly payment",
"method": "creditcard",
"sequenceType": "recurring",
"status": "paid",
"isCancelable": false,
"webhookUrl": "https://webshop.example.org/payments/webhook",
"profileId": "pfl_QkEhN94Ba",
"customerId": "cst_stTC2WHAuS",
"mandateId": "mdt_38HS4fsS",
"createdAt": "2023-09-01T03:58:35.0Z",
"paidAt": "2023-09-01T04:02:01.0Z",
"_links": {
"self": {
"href": "...",
"type": "application/hal+json"
},
"dashboard": {
"href": "https://www.mollie.com/dashboard/org_12345678/payments/tr_7UhSN1zuXS",
"type": "text/html"
}
}
}
]
},
"_links": {
"self": {
"href": "https://api.mollie.com/v2/customers/cst_stTC2WHAuS/subscriptions/sub_8JfGzs6v3K/payments?limit=25",
"type": "application/hal+json"
},
"previous": null,
"next": null,
"documentation": {
"href": "https://docs.mollie.com/reference/list-subscription-payments",
"type": "text/html"
}
}
}'
)
);

$response = $this->apiClient->subscriptionPayments->pageForIds(
'cst_stTC2WHAuS',
'sub_8JfGzs6v3K',
null,
25
);

$this->assertInstanceOf(PaymentCollection::class, $response);
}
}

0 comments on commit 1987b1c

Please sign in to comment.