-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #728 from sandervanhooft/add_missing_endpoints
Add missing endpoints
- Loading branch information
Showing
5 changed files
with
323 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,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); | ||
} | ||
} |
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,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"; | ||
} | ||
} |
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,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
86
tests/Mollie/API/Endpoints/SubscriptionPaymentEndpointTest.php
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,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); | ||
} | ||
} |