From 8c2a2b28eca0ba9a7f6427e926c093f8869761f2 Mon Sep 17 00:00:00 2001 From: Michiel Gerritsen Date: Tue, 23 Sep 2025 14:54:30 +0200 Subject: [PATCH 1/3] Bugfix: Verify that details is a JSON string --- .../Widget/Grid/PaypalReferenceColumn.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Block/Adminhtml/Widget/Grid/PaypalReferenceColumn.php b/Block/Adminhtml/Widget/Grid/PaypalReferenceColumn.php index 67399b13b89..521f01150be 100644 --- a/Block/Adminhtml/Widget/Grid/PaypalReferenceColumn.php +++ b/Block/Adminhtml/Widget/Grid/PaypalReferenceColumn.php @@ -36,7 +36,7 @@ public function decorate($value, TransactionInterface $row): string return ''; } - $details = json_decode($information['details'], true); + $details = $this->getDetails($information); if (!array_key_exists('paypalReference', $details)) { return ''; } @@ -53,4 +53,18 @@ public function filterPaypalReference(Collection $collection, self $column) $value = $this->getFilter()->getValue(); $collection->addFieldToFilter('sop.additional_information', ['like' => '%' . $value . '%']); } + + public function getDetails(array $information): array + { + $details = $information['details']; + if (is_array($details)) { + return $details; + } + + if (!is_string($details)) { + return []; + } + + return json_decode($details, true); + } } From a96d8ef39a1528f597365cc97ab24b544490765b Mon Sep 17 00:00:00 2001 From: Michiel Gerritsen Date: Wed, 24 Sep 2025 13:36:52 +0200 Subject: [PATCH 2/3] Add option to enable/disable the paypal reference column, show reference on the orders page --- Block/Info/Base.php | 44 ++++++++++++++----- Config.php | 9 ++++ etc/adminhtml/methods/paypal.xml | 8 ++++ etc/config.xml | 1 + .../layout/sales_transactions_grid_block.xml | 4 +- .../templates/info/mollie_base.phtml | 9 ++++ 6 files changed, 62 insertions(+), 13 deletions(-) diff --git a/Block/Info/Base.php b/Block/Info/Base.php index e09f6356691..56a5b1b67f9 100644 --- a/Block/Info/Base.php +++ b/Block/Info/Base.php @@ -6,11 +6,12 @@ namespace Mollie\Payment\Block\Info; +use Exception; use Magento\Framework\Pricing\PriceCurrencyInterface; use Magento\Framework\Registry; -use Magento\Payment\Block\Info; -use Magento\Framework\View\Element\Template\Context; use Magento\Framework\Stdlib\DateTime; +use Magento\Framework\View\Element\Template\Context; +use Magento\Payment\Block\Info; use Magento\Sales\Api\Data\OrderInterface; use Mollie\Payment\Config; use Mollie\Payment\Helper\General as MollieHelper; @@ -75,7 +76,7 @@ public function getCheckoutType(): ?string { try { return $this->getInfo()->getAdditionalInformation('checkout_type'); - } catch (\Exception $e) { + } catch (Exception $e) { $this->mollieHelper->addTolog('error', $e->getMessage()); return null; } @@ -87,7 +88,7 @@ public function getExpiresAt(): ?string if ($expiresAt = $this->getInfo()->getAdditionalInformation('expires_at')) { return $this->timezone->date($expiresAt)->format(DateTime::DATETIME_PHP_FORMAT); } - } catch (\Exception $e) { + } catch (Exception $e) { $this->mollieHelper->addTolog('error', $e->getMessage()); } @@ -116,7 +117,7 @@ public function getCheckoutUrl(): ?string { try { return $this->getInfo()->getAdditionalInformation('checkout_url'); - } catch (\Exception $e) { + } catch (Exception $e) { $this->mollieHelper->addTolog('error', $e->getMessage()); return null; } @@ -126,7 +127,7 @@ public function getPaymentStatus(): ?string { try { return $this->getInfo()->getAdditionalInformation('payment_status'); - } catch (\Exception $e) { + } catch (Exception $e) { $this->mollieHelper->addTolog('error', $e->getMessage()); return null; } @@ -136,7 +137,26 @@ public function getDashboardUrl(): ?string { try { return $this->getInfo()->getAdditionalInformation('dashboard_url'); - } catch (\Exception $e) { + } catch (Exception $e) { + $this->mollieHelper->addTolog('error', $e->getMessage()); + return null; + } + } + + public function getPayPalReference(): ?string + { + try { + $details = $this->getInfo()->getAdditionalInformation('details'); + if (is_string($details)) { + $details = json_decode($details, true); + } + + if (!array_key_exists('paypalReference', $details)) { + return null; + } + + return $details['paypalReference']; + } catch (Exception $e) { $this->mollieHelper->addTolog('error', $e->getMessage()); return null; } @@ -146,7 +166,7 @@ public function getChangePaymentStatusUrl(): ?string { try { return (string)$this->getInfo()->getAdditionalInformation('mollie_change_payment_state_url'); - } catch (\Exception $exception) { + } catch (Exception $exception) { return null; } } @@ -155,7 +175,7 @@ public function getMollieId(): ?string { try { return $this->getInfo()->getAdditionalInformation('mollie_id'); - } catch (\Exception $e) { + } catch (Exception $e) { $this->mollieHelper->addTolog('error', $e->getMessage()); return null; } @@ -181,7 +201,7 @@ public function isBuyNowPayLaterMethod(): bool if (in_array($code, $methods)) { return true; } - } catch (\Exception $e) { + } catch (Exception $e) { $this->mollieHelper->addTolog('error', $e->getMessage()); } @@ -205,7 +225,7 @@ public function getOrderId(): ?string { try { return $this->getInfo()->getParentId(); - } catch (\Exception $e) { + } catch (Exception $e) { $this->mollieHelper->addTolog('error', $e->getMessage()); return null; } @@ -224,7 +244,7 @@ public function getRemainderAmount() { try { return $this->getInfo()->getAdditionalInformation('remainder_amount'); - } catch (\Exception $e) { + } catch (Exception $e) { $this->mollieHelper->addTolog('error', $e->getMessage()); } diff --git a/Config.php b/Config.php index 25635eafdcf..81764260ef9 100644 --- a/Config.php +++ b/Config.php @@ -77,6 +77,7 @@ class Config const PAYMENT_PAYMENTLINK_NEW_STATUS = 'payment/mollie_methods_paymentlink/order_status_new'; const PAYMENT_PAYMENTLINK_ADD_MESSAGE = 'payment/mollie_methods_paymentlink/add_message'; const PAYMENT_PAYMENTLINK_MESSAGE = 'payment/mollie_methods_paymentlink/message'; + const PAYMENT_PAYPAL_SHOW_REFERENCE_IN_TRANSACTIONS_GRID = 'payment/mollie_methods_paypal/show_reference_in_transactions_grid'; const PAYMENT_USE_CUSTOM_PAYMENTLINK_URL = 'payment/mollie_general/use_custom_paymentlink_url'; const PAYMENT_CUSTOM_PAYMENTLINK_URL = 'payment/mollie_general/custom_paymentlink_url'; const PAYMENT_POINTOFSALE_ALLOWED_CUSTOMER_GROUPS = 'payment/mollie_methods_pointofsale/allowed_customer_groups'; @@ -549,6 +550,14 @@ public function paymentLinkMessage($storeId = null): string ); } + public function showPaypalReferenceInTransactionsGrid(?int $storeId = null): bool + { + return (string)$this->isSetFlag( + static::PAYMENT_PAYPAL_SHOW_REFERENCE_IN_TRANSACTIONS_GRID, + $storeId + ); + } + public function useCustomPaymentLinkUrl($storeId = null): bool { return $this->isSetFlag(static::PAYMENT_USE_CUSTOM_PAYMENTLINK_URL, $storeId); diff --git a/etc/adminhtml/methods/paypal.xml b/etc/adminhtml/methods/paypal.xml index c74d9049c26..d601ae8f0ac 100644 --- a/etc/adminhtml/methods/paypal.xml +++ b/etc/adminhtml/methods/paypal.xml @@ -152,5 +152,13 @@ 1 + + + Magento\Config\Model\Config\Source\Yesno + payment/mollie_methods_paypal/show_reference_in_transactions_grid + diff --git a/etc/config.xml b/etc/config.xml index 7325d65b7c0..a26b9d4a1f4 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -587,6 +587,7 @@ 0 0 1 + 1 1 diff --git a/view/adminhtml/layout/sales_transactions_grid_block.xml b/view/adminhtml/layout/sales_transactions_grid_block.xml index 485051d8a85..af8055f9edc 100644 --- a/view/adminhtml/layout/sales_transactions_grid_block.xml +++ b/view/adminhtml/layout/sales_transactions_grid_block.xml @@ -6,7 +6,9 @@ - + Mollie PayPal ID additional_information_renderer diff --git a/view/adminhtml/templates/info/mollie_base.phtml b/view/adminhtml/templates/info/mollie_base.phtml index bdb225aada4..3ee5b899825 100644 --- a/view/adminhtml/templates/info/mollie_base.phtml +++ b/view/adminhtml/templates/info/mollie_base.phtml @@ -9,6 +9,7 @@ * @var \Mollie\Payment\Block\Info\Base $block * @var \Magento\Framework\Escaper $escaper */ + use Mollie\Payment\Model\Methods\Voucher; // Magento 2.3 compatibility @@ -87,6 +88,14 @@ $status = $block->getPaymentStatus(); + getPayPalReference()): ?> + + escapeHtml(__('PayPal Reference')); ?> + + escapeHtml($paypalReference); ?> + + + escapeHtml(__('Update Payment Status')); ?> From 132c52d131119765b7a32acc67eee19db7eb1a04 Mon Sep 17 00:00:00 2001 From: Michiel Gerritsen Date: Tue, 30 Sep 2025 09:03:23 +0200 Subject: [PATCH 3/3] Verify that the variable is an array --- Block/Info/Base.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Block/Info/Base.php b/Block/Info/Base.php index 56a5b1b67f9..acdb0cff6e5 100644 --- a/Block/Info/Base.php +++ b/Block/Info/Base.php @@ -151,7 +151,7 @@ public function getPayPalReference(): ?string $details = json_decode($details, true); } - if (!array_key_exists('paypalReference', $details)) { + if (!is_array($details) || !array_key_exists('paypalReference', $details)) { return null; }