PaymentStorage loadByProperties is broken

Created on 4 March 2022, over 2 years ago
Updated 7 April 2023, about 1 year ago

Problem/Motivation

In \Drupal\mollie_commerce\EventSubscriber\MollieRedirectEventSubscriber::setRedirectUrl() the mollie_payment storage handler is called with loadByProperties() method, given the context & context id.

However this not actually do any conditional logic on these properties, but just returns the latest Mollie payment.

Steps to reproduce

Call the loadByProperties() method for a Mollie transaction that is NOT the most recent one.
E.g.

$payments = \Drupal::entityTypeManager()->getStorage('mollie_payment')
      ->loadByProperties([
        'context' => 'mollie_commerce',
        'context_id' => "13851"
      ]);
    $payment = reset($payments);

The payment entity you receive, is not the one with these properties.

Proposed resolution

The PaymentStorage logic seems flawed currently (probably caused by all the "TODO" comments in the source code).
Currently, via the query execution, it always loads the latest 50 transactions. No conditional logic is applied.

Remaining tasks

Improve logic to retrieve conditional transactions from Mollie API
Maybe override \Drupal\Core\Entity\EntityStorageBase::loadByProperties() in TransactionStorageBase, so it does some conditional checking on the results, although it will only be the last 50 ones, and will be difficult to filter on any kind of property...

Alternatively, add a dedicated method to retrieve a transaction by context, and use that method in the event subscriber, instead of loadByProperties

πŸ› Bug report
Status

Closed: won't fix

Version

2.1

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium svendecabooter Gent

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024