mollie / mollie-api-php

Mollie API client for PHP
http://www.mollie.com
BSD 2-Clause "Simplified" License
552 stars 191 forks source link

Redundant HTTP requests when using embed parameter #502

Closed alecpl closed 2 years ago

alecpl commented 4 years ago
$client = new \Mollie\Api\MollieApiClient();
$client->setApiKey(xxx);

$payment = $client->payments->get('ord_xxx', ['embed' => 'refunds']);
$payment->refunds();

In the above code internal $_embedded property will be properly filled with refunds list. However, when refunds() is called an extra http request is invoked. The point of using embed parameter is to not have to create redundant requests.

The same applies to chargebacks. And the same applies to use of embed parameter in other places, e.g. orders.

Looking at refunds() or chargebacks() code it's clear why that happens. Looks to me that all methods that use $_embedded property have to be reviewed and fixed.

ps. The documentation is not clear at https://docs.mollie.com/reference/v2/payments-api/get-payment (Embedding of related resources). What if I wanted to embed both refunds and chargebacks? Is this supported?

sandervanhooft commented 2 years ago

Closing this for now, feel free to submit a PR if you find a solution.