diff --git a/README.md b/README.md index e05b773d1..faa1275e3 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ The easiest way to install the Mollie API client is by using [Composer](http://g composer require mollie/mollie-api-php ``` -To work with the most recent API version, ensure that you are using a version of this API client that is equal to or greater than 2.0.0. If you prefer to continue using the v1 API, make sure your client version is below 2.0.0. For guidance on transitioning from v1 to v2, please refer to the [migration notes](https://docs.mollie.com/migrating-v1-to-v2). +To work with the most recent API version, ensure that you are using a version of this API client that is equal to or greater than 2.0.0. If you prefer to continue using the v1 API, make sure your client version is below 2.0.0. For guidance on transitioning from v1 to v2, please refer to the [migration notes](https://docs.mollie.com/docs/migrating-from-v1-to-v2). ### Manual Installation ### If you're not familiar with using composer we've added a ZIP file to the releases containing the API client and all the packages normally installed by composer. diff --git a/src/Endpoints/MandateEndpoint.php b/src/Endpoints/MandateEndpoint.php index d6dee89f3..7e77c167a 100644 --- a/src/Endpoints/MandateEndpoint.php +++ b/src/Endpoints/MandateEndpoint.php @@ -122,8 +122,8 @@ public function iteratorFor(Customer $customer, ?string $from = null, ?int $limi /** * @param string $customerId - * @param null $from - * @param null $limit + * @param string|null $from + * @param int|null $limit * @param array $parameters * * @return \Mollie\Api\Resources\MandateCollection diff --git a/src/Endpoints/OnboardingEndpoint.php b/src/Endpoints/OnboardingEndpoint.php index 52ba56958..c8cb9a364 100644 --- a/src/Endpoints/OnboardingEndpoint.php +++ b/src/Endpoints/OnboardingEndpoint.php @@ -40,13 +40,13 @@ public function get() } /** + * @deprecated 2023-05-01 For an alternative, see https://docs.mollie.com/reference/create-client-link . * Submit data that will be prefilled in the merchant’s onboarding. * Please note that the data you submit will only be processed when the onboarding status is needs-data. * * Information that the merchant has entered in their dashboard will not be overwritten. * - * Will throw a ApiException if the resource cannot be found. - * + * Will throw an ApiException if the resource cannot be found. * @throws ApiException */ public function submit(array $parameters = []) diff --git a/src/Endpoints/PaymentLinkPaymentEndpoint.php b/src/Endpoints/PaymentLinkPaymentEndpoint.php new file mode 100644 index 000000000..d118b3666 --- /dev/null +++ b/src/Endpoints/PaymentLinkPaymentEndpoint.php @@ -0,0 +1,93 @@ +client, $count, $_links); + } + + /** + * @inheritDoc + */ + protected function getResourceObject() + { + return new Payment($this->client); + } + + public function pageForId(string $paymentLinkId, string $from = null, int $limit = null, array $filters = []) + { + $this->parentId = $paymentLinkId; + + return $this->rest_list($from, $limit, $filters); + } + + public function pageFor(PaymentLink $paymentLink, string $from = null, int $limit = null, array $filters = []) + { + return $this->pageForId($paymentLink->id, $from, $limit, $filters); + } + + /** + * Create an iterator for iterating over payments associated with the provided Payment Link id, retrieved from Mollie. + * + * @param string $paymentLinkId + * @param string|null $from The first resource ID you want to include in your list. + * @param int|null $limit + * @param array $parameters + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). + * + * @return LazyCollection + */ + public function iteratorForId( + string $paymentLinkId, + ?string $from = null, + ?int $limit = null, + array $parameters = [], + bool $iterateBackwards = false + ): LazyCollection { + $this->parentId = $paymentLinkId; + + return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + } + + /** + * Create an iterator for iterating over payments associated with the provided Payment Link object, retrieved from Mollie. + * + * @param PaymentLink $paymentLink + * @param string|null $from The first resource ID you want to include in your list. + * @param int|null $limit + * @param array $parameters + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). + * + * @return LazyCollection + */ + public function iteratorFor( + PaymentLink $paymentLink, + ?string $from = null, + ?int $limit = null, + array $parameters = [], + bool $iterateBackwards = false + ): LazyCollection { + return $this->iteratorForId( + $paymentLink->id, + $from, + $limit, + $parameters, + $iterateBackwards + ); + } +} diff --git a/src/Endpoints/PaymentRefundEndpoint.php b/src/Endpoints/PaymentRefundEndpoint.php index 68524ec8c..6110cdb57 100644 --- a/src/Endpoints/PaymentRefundEndpoint.php +++ b/src/Endpoints/PaymentRefundEndpoint.php @@ -78,8 +78,8 @@ public function listFor(Payment $payment, array $parameters = []) * Create an iterator for iterating over refunds for the given payment, retrieved from Mollie. * * @param Payment $payment - * @param string $from The first resource ID you want to include in your list. - * @param int $limit + * @param string|null $from The first resource ID you want to include in your list. + * @param int|null $limit * @param array $parameters * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). * @@ -108,8 +108,8 @@ public function listForId($paymentId, array $parameters = []) * Create an iterator for iterating over refunds for the given payment id, retrieved from Mollie. * * @param string $paymentId - * @param string $from The first resource ID you want to include in your list. - * @param int $limit + * @param string|null $from The first resource ID you want to include in your list. + * @param int|null $limit * @param array $parameters * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). * diff --git a/src/MollieApiClient.php b/src/MollieApiClient.php index 9c6d17041..d78ccf243 100644 --- a/src/MollieApiClient.php +++ b/src/MollieApiClient.php @@ -25,6 +25,7 @@ use Mollie\Api\Endpoints\PaymentChargebackEndpoint; use Mollie\Api\Endpoints\PaymentEndpoint; use Mollie\Api\Endpoints\PaymentLinkEndpoint; +use Mollie\Api\Endpoints\PaymentLinkPaymentEndpoint; use Mollie\Api\Endpoints\PaymentRefundEndpoint; use Mollie\Api\Endpoints\PaymentRouteEndpoint; use Mollie\Api\Endpoints\PermissionEndpoint; @@ -52,7 +53,7 @@ class MollieApiClient /** * Version of our client. */ - public const CLIENT_VERSION = "2.69.0"; + public const CLIENT_VERSION = "2.70.0"; /** * Endpoint of the remote API. @@ -305,6 +306,13 @@ class MollieApiClient */ public $orderRefunds; + /** + * RESTful Payment Link Payment resource. + * + * @var PaymentLinkPaymentEndpoint + */ + public $paymentLinkPayments; + /** * Manages Payment Links requests * @@ -333,6 +341,20 @@ class MollieApiClient */ public $wallets; + /** + * RESTful Client resource. + * + * @var ClientEndpoint + */ + public $clients; + + /** + * RESTful Client resource. + * + * @var ClientLinkEndpoint + */ + public $clientLinks; + /** * @var string */ @@ -363,20 +385,6 @@ class MollieApiClient */ protected $versionStrings = []; - /** - * RESTful Client resource. - * - * @var ClientEndpoint - */ - public $clients; - - /** - * RESTful Client resource. - * - * @var ClientLinkEndpoint - */ - public $clientLinks; - /** * @param \GuzzleHttp\ClientInterface|\Mollie\Api\HttpAdapter\MollieHttpAdapterInterface|null $httpClient * @param \Mollie\Api\HttpAdapter\MollieHttpAdapterPickerInterface|null $httpAdapterPicker, @@ -398,45 +406,46 @@ public function __construct($httpClient = null, $httpAdapterPicker = null, $idem 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); - $this->settlementChargebacks = new SettlementChargebackEndpoint($this); - $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); - $this->balanceTransactions = new BalanceTransactionEndpoint($this); $this->balanceReports = new BalanceReportEndpoint($this); + $this->balanceTransactions = new BalanceTransactionEndpoint($this); + $this->balances = new BalanceEndpoint($this); + $this->chargebacks = new ChargebackEndpoint($this); + $this->clientLinks = new ClientLinkEndpoint($this); + $this->clients = new ClientEndpoint($this); + $this->customerPayments = new CustomerPaymentsEndpoint($this); + $this->customers = new CustomerEndpoint($this); $this->invoices = new InvoiceEndpoint($this); - $this->permissions = new PermissionEndpoint($this); - $this->profiles = new ProfileEndpoint($this); + $this->mandates = new MandateEndpoint($this); + $this->methods = new MethodEndpoint($this); + $this->methodIssuers = new MethodIssuerEndpoint($this); $this->onboarding = new OnboardingEndpoint($this); - $this->organizations = new OrganizationEndpoint($this); - $this->orders = new OrderEndpoint($this); $this->orderLines = new OrderLineEndpoint($this); $this->orderPayments = new OrderPaymentEndpoint($this); $this->orderRefunds = new OrderRefundEndpoint($this); - $this->shipments = new ShipmentEndpoint($this); - $this->refunds = new RefundEndpoint($this); - $this->paymentRefunds = new PaymentRefundEndpoint($this); + $this->orders = new OrderEndpoint($this); + $this->organizationPartners = new OrganizationPartnerEndpoint($this); + $this->organizations = new OrganizationEndpoint($this); $this->paymentCaptures = new PaymentCaptureEndpoint($this); - $this->paymentRoutes = new PaymentRouteEndpoint($this); - $this->chargebacks = new ChargebackEndpoint($this); $this->paymentChargebacks = new PaymentChargebackEndpoint($this); - $this->wallets = new WalletEndpoint($this); + $this->paymentLinkPayments = new PaymentLinkPaymentEndpoint($this); $this->paymentLinks = new PaymentLinkEndpoint($this); + $this->paymentRefunds = new PaymentRefundEndpoint($this); + $this->paymentRoutes = new PaymentRouteEndpoint($this); + $this->payments = new PaymentEndpoint($this); + $this->permissions = new PermissionEndpoint($this); + $this->profileMethods = new ProfileMethodEndpoint($this); + $this->profiles = new ProfileEndpoint($this); + $this->refunds = new RefundEndpoint($this); + $this->settlementCaptures = new SettlementCaptureEndpoint($this); + $this->settlementChargebacks = new SettlementChargebackEndpoint($this); + $this->settlementPayments = new SettlementPaymentEndpoint($this); + $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->organizationPartners = new OrganizationPartnerEndpoint($this); - $this->clients = new ClientEndpoint($this); - $this->clientLinks = new ClientLinkEndpoint($this); + $this->wallets = new WalletEndpoint($this); } protected function initializeVersionStrings() diff --git a/src/Resources/PaymentLink.php b/src/Resources/PaymentLink.php index 2d65796ed..bef2c9e30 100644 --- a/src/Resources/PaymentLink.php +++ b/src/Resources/PaymentLink.php @@ -158,6 +158,24 @@ public function archive() return $this->client->paymentLinks->update($this->id, $data); } + /** + * Retrieve a paginated list of payments associated with this payment link. + * + * @param string|null $from + * @param int|null $limit + * @param array $filters + * @return mixed|\Mollie\Api\Resources\BaseCollection + */ + public function payments(string $from = null, int $limit = null, array $filters = []) + { + return $this->client->paymentLinkPayments->pageFor( + $this, + $from, + $limit, + $this->withPresetOptions($filters) + ); + } + /** * When accessed by oAuth we want to pass the testmode by default * diff --git a/src/Types/PaymentMethod.php b/src/Types/PaymentMethod.php index fb0f430b1..a20652c86 100644 --- a/src/Types/PaymentMethod.php +++ b/src/Types/PaymentMethod.php @@ -70,6 +70,7 @@ class PaymentMethod public const GIFTCARD = "giftcard"; /** + * @deprecated * @link https://www.mollie.com/en/payments/giropay */ public const GIROPAY = "giropay"; @@ -121,6 +122,11 @@ class PaymentMethod */ public const MYBANK = "mybank"; + /** + * @link https://www.mollie.com/en/payments/payconiq + */ + public const PAYCONIQ = "payconiq"; + /** * @link https://www.mollie.com/en/payments/paypal */ @@ -157,6 +163,11 @@ class PaymentMethod */ public const RIVERTY = "riverty"; + /** + * @link https://www.mollie.com/en/payments/trustly + */ + public const TRUSTLY = "trustly"; + /** * @link https://www.mollie.com/en/payments/twint */ diff --git a/tests/Mollie/API/Endpoints/PaymentLinkPaymentEndpointTest.php b/tests/Mollie/API/Endpoints/PaymentLinkPaymentEndpointTest.php new file mode 100644 index 000000000..722f642c6 --- /dev/null +++ b/tests/Mollie/API/Endpoints/PaymentLinkPaymentEndpointTest.php @@ -0,0 +1,90 @@ +mockApiCall( + new Request( + "GET", + "/v2/payment-links/pl_4Y0eZitmBnQ6IDoMqZQKh/payments" + ), + new Response( + 200, + [], + '{ + "count": 1, + "_embedded": { + "payments": [ + { + "resource": "payment", + "id": "tr_7UhSN1zuXS", + "mode": "live", + "status": "open", + "isCancelable": false, + "amount": { + "value": "75.00", + "currency": "GBP" + }, + "description": "Order #12345", + "method": "ideal", + "metadata": null, + "details": null, + "profileId": "pfl_QkEhN94Ba", + "redirectUrl": "https://webshop.example.org/order/12345/", + "createdAt": "2024-02-12T11:58:35.0Z", + "expiresAt": "2024-02-12T12:13:35.0Z", + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "checkout": { + "href": "https://www.mollie.com/checkout/issuer/select/ideal/7UhSN1zuXS", + "type": "text/html" + }, + "dashboard": { + "href": "https://www.mollie.com/dashboard/org_12345678/payments/tr_7UhSN1zuXS", + "type": "text/html" + } + } + } + ] + }, + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "previous": null, + "next": { + "href": "https://api.mollie.com/v2/payment-links/pl_4Y0eZitmBnQ6IDoMqZQKh/payments?from=tr_SDkzMggpvx&limit=5", + "type": "application/hal+json" + }, + "documentation": { + "href": "...", + "type": "text/html" + } + } + }' + ) + ); + + $response = $this->apiClient->paymentLinkPayments->pageForId("pl_4Y0eZitmBnQ6IDoMqZQKh"); + + $this->assertInstanceOf(PaymentCollection::class, $response); + $this->assertInstanceOf(Payment::class, $response[0]); + $this->assertEquals($response[0]->id, "tr_7UhSN1zuXS"); + // Not necessary to test all fields... + } +}