mollie / mollie-api-php

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

Order refunds #713

Closed pepeh closed 5 months ago

pepeh commented 5 months ago

Specifications

Describe the issue

Method Order::refunds never returns order refunds.

What is the correct way to get order refunds?

sandervanhooft commented 5 months ago

Hi @pepeh ,

Thanks for reaching out. Can you please share:

  1. the package version you're using, i.e. 2.60.0
  2. a code sample that produces the issue
  3. the exact result you're getting
  4. the result you were expecting

That helps us pinpoint the issue.

pepeh commented 5 months ago

@sandervanhooft This issue exists in all package versions (Lines changed 4-6 years ago) Order documentation says _links object will contain self, checkout, dashboard, and documentation objects inside but here code uses $this->_links->refunds that will never present inside order object

pepeh commented 5 months ago

According to the API documentation at Mollie's Orders API, it appears that refunds are only included within the order object if the embed=refunds parameter is utilized. However, even with this parameter, the Order::refunds method may not function as expected since it relies on _links to access refunds.

Furthermore, when examining the documentation for Order Refunds, it's clear that retrieving refunds requires a separate HTTP request as demonstrated in the provided CURL example. Despite this, the PHP code snippet suggests accessing refunds directly through the Order object, akin to how it's approached in Node.js with a method that iterates over order refunds. This discrepancy suggests that there might be a more streamlined way to access refunds similar to the Node.js implementation, which uses mollieClient.orderRefunds.iterate({ orderId: 'ord_stTC2WHAuS' }) for a more intuitive and direct method of retrieval.

pepeh commented 5 months ago

a code sample that produces the issue

@sandervanhooft The PHP code snippet provided mirrors what is found in the documentation available at Mollie's Refunds API

<?php
$mollie = new \Mollie\Api\MollieApiClient();
$mollie->setApiKey("test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM");

$order = $mollie->orders->get("ord_stTC2WHAuS");
$refunds = $order->refunds();
sandervanhooft commented 5 months ago

Hi @pepeh ,

It looks like you're right! Investigating.

sandervanhooft commented 5 months ago

A patch is being prepared in #714

sandervanhooft commented 5 months ago

@pepeh Once this patch is released you can shave off a call to the Mollie API:

<?php
$mollie = new \Mollie\Api\MollieApiClient();
$mollie->setApiKey("test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM");

// $order = $mollie->orders->get("ord_stTC2WHAuS"); // no longer required to fetch the Order first
$refunds = $mollie->orderRefunds->pageForId("ord_stTC2WHAuS");