pronamic / wp-pay-core

Core components for the WordPress payment processing library. This library is used in the WordPress plugin Pronamic Pay: https://www.pronamicpay.com/, but also allows other plugin developers to set up a payment plugin.
https://www.wp-pay.org/
GNU General Public License v3.0
27 stars 3 forks source link

`PaymentInfo::get_meta()` results in empty string due to `get_post_meta()` fallback #163

Closed rvdsteege closed 9 months ago

rvdsteege commented 9 months ago

There is an issue with starting first payments with some integrations since the Pronamic Pay 9.6 release. This has to do with recent changes in setting the Mollie sequence type:

The underlying issue is PaymentInfo::get_meta() falling back to get_post_meta(), which results in an empty string instead of null value if there is no meta stored for the given meta key.

https://github.com/pronamic/wp-pay-core/blob/a6f6c6cd2379f6c4b292804e7225e7101cc43cca/src/Payments/PaymentInfo.php#L440-L458

rvdsteege commented 9 months ago

Discussed with @remcotolsma at HQ. We'll resolve this by retrieving post meta with the $single parameter set to false and checking the number of results. For 0 results, we'll return null in PaymentInfo::get_meta().

remcotolsma commented 9 months ago

We may need to check type, since get_post_meta returns mixed: https://developer.wordpress.org/reference/functions/get_post_meta/.

With all the filters in the meta functions you are never sure what it will return.

I could remember us doing something similar somewhere:

https://github.com/pronamic/wp-pay-core/blob/649ec6aff28464abd8ce9905431fcf6d84ed8f0e/src/AbstractDataStoreCPT.php#L205-L217

An 'empty' check as above might also be workable for now?