Add option to pass payment methode to transaction (mollie) #2644
Replies: 1 comment
-
Hey @WHITE-developer Thanks for the question. Because this is specific to the Mollie gateway, at the moment we are not sure this is something that we would add in the core of Commerce (although there might be scope in the Mollie gateway plugin). However, it is possible to retrieve this information already using an order edit template hook and a custom module: use Craft;
use craft\commerce\elements\Order;
use craft\commerce\models\Transaction;
use craft\helpers\ArrayHelper;
use craft\helpers\Json;
...
Craft::$app->view->hook('cp.commerce.order.edit.details', function(array &$context) {
/** @var Order $order */
if (!isset($context['order']) || !$order = $context['order']) {
return '';
}
if (!$order->isCompleted || empty($transactions = $order->getTransactions())) {
return '';
}
/** @var Transaction $transaction */
if (!$transaction = ArrayHelper::firstWhere($transactions, 'gateway.name', 'Mollie')) {
return '';
}
if (!$transaction->response || !$response = Json::decodeIfJson($transaction->response)) {
return '';
}
return sprintf('
<div class="meta read-only">
<div class="data">
<h5 class="heading">Payment Method</h5>
<span class="value">%s</span>
</div>
</div>
', $response['method'] ?? '');
}); In this example code, I have put a number of caveats based on the fact my local setup uses a number of different gateways etc. You will probably be able to make your code more specific to your project and possibly do things like checking if the transaction is a successful one. But hopefully, this gives you an idea of how to retrieve and display this info. Here is a screenshot of the output at the end. Hope this helps, thanks! |
Beta Was this translation helpful? Give feedback.
-
Hi,
It would be nice if there was an extra field in the transaction model to pass the payment methode of Mollie (paypal, ideal, credit card, ...)
And the option to add this field to the order overview so you have a quick visual over the orders which payment method is used.
Beta Was this translation helpful? Give feedback.
All reactions