Skip to content

Commit 46486ca

Browse files
Merge branch 'bugfix/verify-that-details-is-a-json' into release-week-41
2 parents 643e4f5 + 132c52d commit 46486ca

File tree

7 files changed

+77
-14
lines changed

7 files changed

+77
-14
lines changed

Block/Adminhtml/Widget/Grid/PaypalReferenceColumn.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function decorate($value, TransactionInterface $row): string
3636
return '';
3737
}
3838

39-
$details = json_decode($information['details'], true);
39+
$details = $this->getDetails($information);
4040
if (!array_key_exists('paypalReference', $details)) {
4141
return '';
4242
}
@@ -53,4 +53,18 @@ public function filterPaypalReference(Collection $collection, Column $column)
5353
$value = $this->getFilter()->getValue();
5454
$collection->addFieldToFilter('sop.additional_information', ['like' => '%' . $value . '%']);
5555
}
56+
57+
public function getDetails(array $information): array
58+
{
59+
$details = $information['details'];
60+
if (is_array($details)) {
61+
return $details;
62+
}
63+
64+
if (!is_string($details)) {
65+
return [];
66+
}
67+
68+
return json_decode($details, true);
69+
}
5670
}

Block/Info/Base.php

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66

77
namespace Mollie\Payment\Block\Info;
88

9+
use Exception;
910
use Magento\Framework\Pricing\PriceCurrencyInterface;
1011
use Magento\Framework\Registry;
11-
use Magento\Payment\Block\Info;
12-
use Magento\Framework\View\Element\Template\Context;
1312
use Magento\Framework\Stdlib\DateTime;
13+
use Magento\Framework\View\Element\Template\Context;
14+
use Magento\Payment\Block\Info;
1415
use Magento\Sales\Api\Data\OrderInterface;
1516
use Mollie\Payment\Config;
1617
use Mollie\Payment\Helper\General as MollieHelper;
@@ -75,7 +76,7 @@ public function getCheckoutType(): ?string
7576
{
7677
try {
7778
return $this->getInfo()->getAdditionalInformation('checkout_type');
78-
} catch (\Exception $e) {
79+
} catch (Exception $e) {
7980
$this->mollieHelper->addTolog('error', $e->getMessage());
8081
return null;
8182
}
@@ -87,7 +88,7 @@ public function getExpiresAt(): ?string
8788
if ($expiresAt = $this->getInfo()->getAdditionalInformation('expires_at')) {
8889
return $this->timezone->date($expiresAt)->format(DateTime::DATETIME_PHP_FORMAT);
8990
}
90-
} catch (\Exception $e) {
91+
} catch (Exception $e) {
9192
$this->mollieHelper->addTolog('error', $e->getMessage());
9293
}
9394

@@ -116,7 +117,7 @@ public function getCheckoutUrl(): ?string
116117
{
117118
try {
118119
return $this->getInfo()->getAdditionalInformation('checkout_url');
119-
} catch (\Exception $e) {
120+
} catch (Exception $e) {
120121
$this->mollieHelper->addTolog('error', $e->getMessage());
121122
return null;
122123
}
@@ -126,7 +127,7 @@ public function getPaymentStatus(): ?string
126127
{
127128
try {
128129
return $this->getInfo()->getAdditionalInformation('payment_status');
129-
} catch (\Exception $e) {
130+
} catch (Exception $e) {
130131
$this->mollieHelper->addTolog('error', $e->getMessage());
131132
return null;
132133
}
@@ -136,7 +137,26 @@ public function getDashboardUrl(): ?string
136137
{
137138
try {
138139
return $this->getInfo()->getAdditionalInformation('dashboard_url');
139-
} catch (\Exception $e) {
140+
} catch (Exception $e) {
141+
$this->mollieHelper->addTolog('error', $e->getMessage());
142+
return null;
143+
}
144+
}
145+
146+
public function getPayPalReference(): ?string
147+
{
148+
try {
149+
$details = $this->getInfo()->getAdditionalInformation('details');
150+
if (is_string($details)) {
151+
$details = json_decode($details, true);
152+
}
153+
154+
if (!is_array($details) || !array_key_exists('paypalReference', $details)) {
155+
return null;
156+
}
157+
158+
return $details['paypalReference'];
159+
} catch (Exception $e) {
140160
$this->mollieHelper->addTolog('error', $e->getMessage());
141161
return null;
142162
}
@@ -146,7 +166,7 @@ public function getChangePaymentStatusUrl(): ?string
146166
{
147167
try {
148168
return (string)$this->getInfo()->getAdditionalInformation('mollie_change_payment_state_url');
149-
} catch (\Exception $exception) {
169+
} catch (Exception $exception) {
150170
return null;
151171
}
152172
}
@@ -155,7 +175,7 @@ public function getMollieId(): ?string
155175
{
156176
try {
157177
return $this->getInfo()->getAdditionalInformation('mollie_id');
158-
} catch (\Exception $e) {
178+
} catch (Exception $e) {
159179
$this->mollieHelper->addTolog('error', $e->getMessage());
160180
return null;
161181
}
@@ -181,7 +201,7 @@ public function isBuyNowPayLaterMethod(): bool
181201
if (in_array($code, $methods)) {
182202
return true;
183203
}
184-
} catch (\Exception $e) {
204+
} catch (Exception $e) {
185205
$this->mollieHelper->addTolog('error', $e->getMessage());
186206
}
187207

@@ -205,7 +225,7 @@ public function getOrderId(): ?string
205225
{
206226
try {
207227
return $this->getInfo()->getParentId();
208-
} catch (\Exception $e) {
228+
} catch (Exception $e) {
209229
$this->mollieHelper->addTolog('error', $e->getMessage());
210230
return null;
211231
}
@@ -224,7 +244,7 @@ public function getRemainderAmount()
224244
{
225245
try {
226246
return $this->getInfo()->getAdditionalInformation('remainder_amount');
227-
} catch (\Exception $e) {
247+
} catch (Exception $e) {
228248
$this->mollieHelper->addTolog('error', $e->getMessage());
229249
}
230250

Config.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class Config
7777
const PAYMENT_PAYMENTLINK_NEW_STATUS = 'payment/mollie_methods_paymentlink/order_status_new';
7878
const PAYMENT_PAYMENTLINK_ADD_MESSAGE = 'payment/mollie_methods_paymentlink/add_message';
7979
const PAYMENT_PAYMENTLINK_MESSAGE = 'payment/mollie_methods_paymentlink/message';
80+
const PAYMENT_PAYPAL_SHOW_REFERENCE_IN_TRANSACTIONS_GRID = 'payment/mollie_methods_paypal/show_reference_in_transactions_grid';
8081
const PAYMENT_USE_CUSTOM_PAYMENTLINK_URL = 'payment/mollie_general/use_custom_paymentlink_url';
8182
const PAYMENT_CUSTOM_PAYMENTLINK_URL = 'payment/mollie_general/custom_paymentlink_url';
8283
const PAYMENT_POINTOFSALE_ALLOWED_CUSTOMER_GROUPS = 'payment/mollie_methods_pointofsale/allowed_customer_groups';
@@ -549,6 +550,14 @@ public function paymentLinkMessage($storeId = null): string
549550
);
550551
}
551552

553+
public function showPaypalReferenceInTransactionsGrid(?int $storeId = null): bool
554+
{
555+
return (string)$this->isSetFlag(
556+
static::PAYMENT_PAYPAL_SHOW_REFERENCE_IN_TRANSACTIONS_GRID,
557+
$storeId
558+
);
559+
}
560+
552561
public function useCustomPaymentLinkUrl($storeId = null): bool
553562
{
554563
return $this->isSetFlag(static::PAYMENT_USE_CUSTOM_PAYMENTLINK_URL, $storeId);

etc/adminhtml/methods/paypal.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,5 +152,13 @@
152152
<field id="active">1</field>
153153
</depends>
154154
</field>
155+
<field id="show_reference_in_transactions_grid" translate="label" type="select" sortOrder="160"
156+
showInDefault="1"
157+
showInWebsite="1"
158+
showInStore="1">
159+
<label>Add reference column to transactions grid</label>
160+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
161+
<config_path>payment/mollie_methods_paypal/show_reference_in_transactions_grid</config_path>
162+
</field>
155163
</group>
156164
</include>

etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@
587587
<can_authorize>0</can_authorize>
588588
<can_authorize_vault>0</can_authorize_vault>
589589
<can_edit>1</can_edit>
590+
<show_reference_in_transactions_grid>1</show_reference_in_transactions_grid>
590591
</mollie_methods_paypal>
591592
<mollie_methods_paysafecard>
592593
<active>1</active>

view/adminhtml/layout/sales_transactions_grid_block.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
77
<body>
88
<referenceBlock name="sales.transactions.grid.columnSet">
9-
<block class="Mollie\Payment\Block\Adminhtml\Widget\Grid\PaypalReferenceColumn" name="mollie_paypal_reference">
9+
<block class="Mollie\Payment\Block\Adminhtml\Widget\Grid\PaypalReferenceColumn"
10+
name="mollie_paypal_reference"
11+
ifconfig="payment/mollie_methods_paypal/show_reference_in_transactions_grid">
1012
<arguments>
1113
<argument name="header" xsi:type="string" translate="true">Mollie PayPal ID</argument>
1214
<argument name="type" xsi:type="string">additional_information_renderer</argument>

view/adminhtml/templates/info/mollie_base.phtml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* @var \Mollie\Payment\Block\Info\Base $block
1010
* @var \Magento\Framework\Escaper $escaper
1111
*/
12+
1213
use Mollie\Payment\Model\Methods\Voucher;
1314

1415
// Magento 2.3 compatibility
@@ -87,6 +88,14 @@ $status = $block->getPaymentStatus();
8788
</td>
8889
</tr>
8990
<?php endif; ?>
91+
<?php if ($paypalReference = $block->getPayPalReference()): ?>
92+
<tr>
93+
<th><?= $escaper->escapeHtml(__('PayPal Reference')); ?></th>
94+
<td>
95+
<?= $escaper->escapeHtml($paypalReference); ?>
96+
</td>
97+
</tr>
98+
<?php endif; ?>
9099
<tr>
91100
<th><?= $escaper->escapeHtml(__('Update Payment Status')); ?></th>
92101
<td>

0 commit comments

Comments
 (0)