Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support displaying json in transactions note field. #1

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/controllers/OrdersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1518,6 +1518,15 @@ private function _getTransactionsWithLevelsTableArray(array $transactions, int $
$transactionResponse = Json::htmlEncode($transactionResponse);
}

$transactionNoteType = 'text';
$transactionNote = Json::decodeIfJson($transaction->note);
if (is_array($transactionNote)) {
$transactionNoteType = 'response';
$transactionNote = Json::htmlEncode($transactionNote);
} else {
$transactionNote = Html::encode($transaction->note);
}

$transactionMessage = Json::decodeIfJson($transaction->message);
$transactionMessage = Json::htmlEncode($transactionMessage);

Expand All @@ -1541,7 +1550,7 @@ private function _getTransactionsWithLevelsTableArray(array $transactions, int $
['label' => Html::encode(Craft::t('commerce', 'Transaction Hash')), 'type' => 'code', 'value' => $transaction->hash],
['label' => Html::encode(Craft::t('commerce', 'Gateway Reference')), 'type' => 'code', 'value' => $transaction->reference],
['label' => Html::encode(Craft::t('commerce', 'Gateway Message')), 'type' => 'text', 'value' => $transactionMessage],
['label' => Html::encode(Craft::t('commerce', 'Note')), 'type' => 'text', 'value' => Html::encode($transaction->note)],
['label' => Html::encode(Craft::t('commerce', 'Note')), 'type' => $transactionNoteType, 'value' => $transactionNote],
['label' => Html::encode(Craft::t('commerce', 'Gateway Code')), 'type' => 'code', 'value' => $transaction->code],
['label' => Html::encode(Craft::t('commerce', 'Converted Price')), 'type' => 'text', 'value' => Plugin::getInstance()->getPaymentCurrencies()->convert($transaction->paymentAmount, $transaction->paymentCurrency) . ' <small class="light">(' . $transaction->currency . ')</small>' . ' <small class="light">(1 ' . $transaction->currency . ' = ' . number_format($transaction->paymentRate) . ' ' . $transaction->paymentCurrency . ')</small>'],
['label' => Html::encode(Craft::t('commerce', 'Gateway Response')), 'type' => 'response', 'value' => $transactionResponse],
Expand Down