From 72f72fa4909513fc2accf65dccaca9b8b68aab2d Mon Sep 17 00:00:00 2001 From: Sander van Hooft Date: Tue, 2 Jul 2024 15:03:33 +0200 Subject: [PATCH 1/8] wip --- src/Endpoints/SubscriptionPaymentEndpoint.php | 78 +++++++++++++++++ src/MollieApiClient.php | 9 ++ .../SubscriptionPaymentEndpointTest.php | 86 +++++++++++++++++++ 3 files changed, 173 insertions(+) create mode 100644 src/Endpoints/SubscriptionPaymentEndpoint.php create mode 100644 tests/Mollie/API/Endpoints/SubscriptionPaymentEndpointTest.php diff --git a/src/Endpoints/SubscriptionPaymentEndpoint.php b/src/Endpoints/SubscriptionPaymentEndpoint.php new file mode 100644 index 000000000..35c4a9f9d --- /dev/null +++ b/src/Endpoints/SubscriptionPaymentEndpoint.php @@ -0,0 +1,78 @@ +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('Missing required parameter customerId.'); + } + + if (is_null($this->subscriptionId)) { + throw new ApiException('Missing required parameter subscriptionId.'); + } + + return "customers/{$this->customerId}/subscriptions/{$this->subscriptionId}/payments"; + } +} \ No newline at end of file diff --git a/src/MollieApiClient.php b/src/MollieApiClient.php index 820d2fff4..1861bcda1 100644 --- a/src/MollieApiClient.php +++ b/src/MollieApiClient.php @@ -37,6 +37,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; @@ -155,6 +156,13 @@ class MollieApiClient */ public $subscriptions; + /** + * RESTful Subscription Payments resource. + * + * @var SubscriptionPaymentEndpoint + */ + public $subscriptionPayments; + /** * RESTful Mandate resource. * @@ -394,6 +402,7 @@ public function initializeEndpoints() $this->settlementPayments = new SettlementPaymentEndpoint($this); $this->settlementRefunds = new SettlementRefundEndpoint($this); $this->subscriptions = new SubscriptionEndpoint($this); + $this->subscriptionPayments = new SubscriptionPaymentEndpoint($this); $this->customerPayments = new CustomerPaymentsEndpoint($this); $this->mandates = new MandateEndpoint($this); $this->balances = new BalanceEndpoint($this); diff --git a/tests/Mollie/API/Endpoints/SubscriptionPaymentEndpointTest.php b/tests/Mollie/API/Endpoints/SubscriptionPaymentEndpointTest.php new file mode 100644 index 000000000..d63da0da6 --- /dev/null +++ b/tests/Mollie/API/Endpoints/SubscriptionPaymentEndpointTest.php @@ -0,0 +1,86 @@ +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); + } +} \ No newline at end of file From b6bda5e11ba118c80d31e4d848764f4fca3b0c0d Mon Sep 17 00:00:00 2001 From: Sander van Hooft Date: Tue, 2 Jul 2024 15:12:34 +0200 Subject: [PATCH 2/8] wip --- src/Endpoints/MethodIssuerEndpoint.php | 23 +++++++++++++++++++ src/Endpoints/SubscriptionPaymentEndpoint.php | 1 + src/MollieApiClient.php | 7 ++++++ tests/Mollie/API/MethodIssuerEndpointTest.php | 22 ++++++++++++++++++ 4 files changed, 53 insertions(+) create mode 100644 src/Endpoints/MethodIssuerEndpoint.php create mode 100644 tests/Mollie/API/MethodIssuerEndpointTest.php diff --git a/src/Endpoints/MethodIssuerEndpoint.php b/src/Endpoints/MethodIssuerEndpoint.php new file mode 100644 index 000000000..3fa299907 --- /dev/null +++ b/src/Endpoints/MethodIssuerEndpoint.php @@ -0,0 +1,23 @@ +client); + } +} \ No newline at end of file diff --git a/src/Endpoints/SubscriptionPaymentEndpoint.php b/src/Endpoints/SubscriptionPaymentEndpoint.php index 35c4a9f9d..cb8981d3c 100644 --- a/src/Endpoints/SubscriptionPaymentEndpoint.php +++ b/src/Endpoints/SubscriptionPaymentEndpoint.php @@ -19,6 +19,7 @@ class SubscriptionPaymentEndpoint extends CollectionEndpointAbstract /** * Retrieves a collection of Subscription Payments from Mollie. * + * @param string $customerId * @param string $subscriptionId * @param null $from The first payment ID you want to include in your list. * @param null $limit diff --git a/src/MollieApiClient.php b/src/MollieApiClient.php index 1861bcda1..9c6d17041 100644 --- a/src/MollieApiClient.php +++ b/src/MollieApiClient.php @@ -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; @@ -100,6 +101,11 @@ class MollieApiClient */ public $profileMethods; + /** + * @var \Mollie\Api\Endpoints\MethodIssuerEndpoint + */ + public $methodIssuers; + /** * RESTful Customers resource. * @@ -395,6 +401,7 @@ public function initializeEndpoints() $this->payments = new PaymentEndpoint($this); $this->methods = new MethodEndpoint($this); $this->profileMethods = new ProfileMethodEndpoint($this); + $this->methodIssuers = new MethodIssuerEndpoint($this); $this->customers = new CustomerEndpoint($this); $this->settlements = new SettlementsEndpoint($this); $this->settlementCaptures = new SettlementCaptureEndpoint($this); diff --git a/tests/Mollie/API/MethodIssuerEndpointTest.php b/tests/Mollie/API/MethodIssuerEndpointTest.php new file mode 100644 index 000000000..d5bf11964 --- /dev/null +++ b/tests/Mollie/API/MethodIssuerEndpointTest.php @@ -0,0 +1,22 @@ +markTestIncomplete('To be implemented'); + } + + /** @test */ + public function testDisableIssuer() + { + $this->markTestIncomplete('To be implemented'); + } +} \ No newline at end of file From 2e28d3f487652fc9afb7131b0cb5b28b9ec176e9 Mon Sep 17 00:00:00 2001 From: Sander van Hooft Date: Tue, 2 Jul 2024 15:17:37 +0200 Subject: [PATCH 3/8] wip --- src/Endpoints/MethodIssuerEndpoint.php | 23 +++++++++++++++++++ src/Endpoints/SubscriptionPaymentEndpoint.php | 4 ++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Endpoints/MethodIssuerEndpoint.php b/src/Endpoints/MethodIssuerEndpoint.php index 3fa299907..561990f72 100644 --- a/src/Endpoints/MethodIssuerEndpoint.php +++ b/src/Endpoints/MethodIssuerEndpoint.php @@ -5,12 +5,35 @@ 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; + + + + /** + * @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."); + } + + return "profiles/{$this->profileId}/methods/{$this->methodId}/issuers"; + } + /** * Get the object that is used by this API endpoint. Every API endpoint uses one type of object. * diff --git a/src/Endpoints/SubscriptionPaymentEndpoint.php b/src/Endpoints/SubscriptionPaymentEndpoint.php index cb8981d3c..e7539b5fa 100644 --- a/src/Endpoints/SubscriptionPaymentEndpoint.php +++ b/src/Endpoints/SubscriptionPaymentEndpoint.php @@ -67,11 +67,11 @@ protected function getResourceCollectionObject($count, $_links) public function getResourcePath() { if (is_null($this->customerId)) { - throw new ApiException('Missing required parameter customerId.'); + throw new ApiException('No customerId provided.'); } if (is_null($this->subscriptionId)) { - throw new ApiException('Missing required parameter subscriptionId.'); + throw new ApiException('No subscriptionId provided.'); } return "customers/{$this->customerId}/subscriptions/{$this->subscriptionId}/payments"; From 680aed20f4b566fca2723bfe94429f552224ee83 Mon Sep 17 00:00:00 2001 From: Sander van Hooft Date: Tue, 2 Jul 2024 15:57:07 +0200 Subject: [PATCH 4/8] wip --- src/Endpoints/MethodIssuerEndpoint.php | 44 ++++++++++++++++++- tests/Mollie/API/MethodIssuerEndpointTest.php | 28 +++++++++++- 2 files changed, 69 insertions(+), 3 deletions(-) diff --git a/src/Endpoints/MethodIssuerEndpoint.php b/src/Endpoints/MethodIssuerEndpoint.php index 561990f72..6be04107a 100644 --- a/src/Endpoints/MethodIssuerEndpoint.php +++ b/src/Endpoints/MethodIssuerEndpoint.php @@ -14,8 +14,42 @@ class MethodIssuerEndpoint extends EndpointAbstract 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 @@ -31,7 +65,13 @@ public function getResourcePath() throw new ApiException("No methodId provided."); } - return "profiles/{$this->profileId}/methods/{$this->methodId}/issuers"; + $path = "profiles/{$this->profileId}/methods/{$this->methodId}/issuers"; + + if ($this->issuerId) { + $path .= "/$this->issuerId"; + } + + return $path; } /** diff --git a/tests/Mollie/API/MethodIssuerEndpointTest.php b/tests/Mollie/API/MethodIssuerEndpointTest.php index d5bf11964..30fd31a06 100644 --- a/tests/Mollie/API/MethodIssuerEndpointTest.php +++ b/tests/Mollie/API/MethodIssuerEndpointTest.php @@ -4,6 +4,9 @@ namespace Tests\Mollie\API; +use GuzzleHttp\Psr7\Request; +use GuzzleHttp\Psr7\Response; +use Mollie\Api\Resources\Issuer; use Tests\Mollie\Api\Endpoints\BaseEndpointTest; class MethodIssuerEndpointTest extends BaseEndpointTest @@ -11,7 +14,30 @@ class MethodIssuerEndpointTest extends BaseEndpointTest /** @test */ public function testEnableIssuer() { - $this->markTestIncomplete('To be implemented'); + $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 */ From 5b4fb4927e823fb7d41e44e48c0cc1e986356777 Mon Sep 17 00:00:00 2001 From: Sander van Hooft Date: Tue, 2 Jul 2024 15:59:50 +0200 Subject: [PATCH 5/8] wip --- tests/Mollie/API/MethodIssuerEndpointTest.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/Mollie/API/MethodIssuerEndpointTest.php b/tests/Mollie/API/MethodIssuerEndpointTest.php index 30fd31a06..3769671e4 100644 --- a/tests/Mollie/API/MethodIssuerEndpointTest.php +++ b/tests/Mollie/API/MethodIssuerEndpointTest.php @@ -43,6 +43,16 @@ public function testEnableIssuer() /** @test */ public function testDisableIssuer() { - $this->markTestIncomplete('To be implemented'); + $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); } } \ No newline at end of file From 007e5717abd382b71a59bf8b89fd23eb0e1dbce0 Mon Sep 17 00:00:00 2001 From: Sander van Hooft Date: Tue, 2 Jul 2024 16:13:24 +0200 Subject: [PATCH 6/8] move --- tests/Mollie/API/{ => Endpoints}/MethodIssuerEndpointTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) rename tests/Mollie/API/{ => Endpoints}/MethodIssuerEndpointTest.php (95%) diff --git a/tests/Mollie/API/MethodIssuerEndpointTest.php b/tests/Mollie/API/Endpoints/MethodIssuerEndpointTest.php similarity index 95% rename from tests/Mollie/API/MethodIssuerEndpointTest.php rename to tests/Mollie/API/Endpoints/MethodIssuerEndpointTest.php index 3769671e4..6a9145e6c 100644 --- a/tests/Mollie/API/MethodIssuerEndpointTest.php +++ b/tests/Mollie/API/Endpoints/MethodIssuerEndpointTest.php @@ -2,12 +2,11 @@ declare(strict_types=1); -namespace Tests\Mollie\API; +namespace Tests\Mollie\API\Endpoints; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use Mollie\Api\Resources\Issuer; -use Tests\Mollie\Api\Endpoints\BaseEndpointTest; class MethodIssuerEndpointTest extends BaseEndpointTest { From 3596cfee38ebd1bec44596c56174f925832ec27e Mon Sep 17 00:00:00 2001 From: sandervanhooft Date: Tue, 2 Jul 2024 14:13:47 +0000 Subject: [PATCH 7/8] Fix styling --- src/Endpoints/MethodIssuerEndpoint.php | 3 +-- src/Endpoints/SubscriptionPaymentEndpoint.php | 2 +- tests/Mollie/API/Endpoints/MethodIssuerEndpointTest.php | 2 +- tests/Mollie/API/Endpoints/SubscriptionPaymentEndpointTest.php | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Endpoints/MethodIssuerEndpoint.php b/src/Endpoints/MethodIssuerEndpoint.php index 6be04107a..2cb661b91 100644 --- a/src/Endpoints/MethodIssuerEndpoint.php +++ b/src/Endpoints/MethodIssuerEndpoint.php @@ -4,7 +4,6 @@ namespace Mollie\Api\Endpoints; - use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Resources\Issuer; @@ -83,4 +82,4 @@ protected function getResourceObject() { return new Issuer($this->client); } -} \ No newline at end of file +} diff --git a/src/Endpoints/SubscriptionPaymentEndpoint.php b/src/Endpoints/SubscriptionPaymentEndpoint.php index e7539b5fa..33b5ea4af 100644 --- a/src/Endpoints/SubscriptionPaymentEndpoint.php +++ b/src/Endpoints/SubscriptionPaymentEndpoint.php @@ -76,4 +76,4 @@ public function getResourcePath() return "customers/{$this->customerId}/subscriptions/{$this->subscriptionId}/payments"; } -} \ No newline at end of file +} diff --git a/tests/Mollie/API/Endpoints/MethodIssuerEndpointTest.php b/tests/Mollie/API/Endpoints/MethodIssuerEndpointTest.php index 6a9145e6c..929e6e744 100644 --- a/tests/Mollie/API/Endpoints/MethodIssuerEndpointTest.php +++ b/tests/Mollie/API/Endpoints/MethodIssuerEndpointTest.php @@ -54,4 +54,4 @@ public function testDisableIssuer() $this->assertNull($response); } -} \ No newline at end of file +} diff --git a/tests/Mollie/API/Endpoints/SubscriptionPaymentEndpointTest.php b/tests/Mollie/API/Endpoints/SubscriptionPaymentEndpointTest.php index d63da0da6..72991f1ae 100644 --- a/tests/Mollie/API/Endpoints/SubscriptionPaymentEndpointTest.php +++ b/tests/Mollie/API/Endpoints/SubscriptionPaymentEndpointTest.php @@ -83,4 +83,4 @@ public function testListSubscriptionPayments(): void $this->assertInstanceOf(PaymentCollection::class, $response); } -} \ No newline at end of file +} From 468f376d963b9496a3ebc8cf17355c2a750e793c Mon Sep 17 00:00:00 2001 From: Sander van Hooft Date: Wed, 17 Jul 2024 09:59:14 +0200 Subject: [PATCH 8/8] fix phpstan --- src/Endpoints/SubscriptionPaymentEndpoint.php | 10 +++++----- .../Mollie/API/Endpoints/MethodIssuerEndpointTest.php | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Endpoints/SubscriptionPaymentEndpoint.php b/src/Endpoints/SubscriptionPaymentEndpoint.php index 33b5ea4af..b65e0682a 100644 --- a/src/Endpoints/SubscriptionPaymentEndpoint.php +++ b/src/Endpoints/SubscriptionPaymentEndpoint.php @@ -17,12 +17,12 @@ class SubscriptionPaymentEndpoint extends CollectionEndpointAbstract protected $subscriptionId = null; /** - * Retrieves a collection of Subscription Payments from Mollie. + * Retrieves a paginated collection of Subscription Payments from Mollie. * * @param string $customerId * @param string $subscriptionId - * @param null $from The first payment ID you want to include in your list. - * @param null $limit + * @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 @@ -31,8 +31,8 @@ class SubscriptionPaymentEndpoint extends CollectionEndpointAbstract public function pageForIds( string $customerId, string $subscriptionId, - $from = null, - $limit = null, + ?string $from = null, + ?int $limit = null, array $parameters = [] ) { $this->customerId = $customerId; diff --git a/tests/Mollie/API/Endpoints/MethodIssuerEndpointTest.php b/tests/Mollie/API/Endpoints/MethodIssuerEndpointTest.php index 929e6e744..a251c2b1a 100644 --- a/tests/Mollie/API/Endpoints/MethodIssuerEndpointTest.php +++ b/tests/Mollie/API/Endpoints/MethodIssuerEndpointTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Tests\Mollie\API\Endpoints; +namespace Tests\Mollie\Api\Endpoints; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response;