Skip to content

Commit

Permalink
Merge pull request #7 from khipu/SG-322
Browse files Browse the repository at this point in the history
SG-322 add successful payment data in Payment Information section, in admin order view
  • Loading branch information
dt-khipu authored Jan 26, 2024
2 parents 6f7f665 + 541413c commit 136956c
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Model/Simplified.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

class Simplified extends \Magento\Payment\Model\Method\AbstractMethod
{
const KHIPU_MAGENTO_VERSION = "2.4.8";
const KHIPU_MAGENTO_VERSION = "2.4.9";
protected $_code = 'simplified';
protected $_isInitializeNeeded = true;
protected $urlBuilder;
Expand Down
67 changes: 67 additions & 0 deletions Plugin/Block/Adminhtml/SalesOrderViewInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace Khipu\Payment\Plugin\Block\Adminhtml;

use Magento\Sales\Api\OrderRepositoryInterface;

class SalesOrderViewInfo
{
/**
* @var OrderRepositoryInterface
*/
protected $orderRepository;


/**
* @param OrderRepositoryInterface $orderRepository
*/
public function __construct(
OrderRepositoryInterface $orderRepository
) {
$this->orderRepository = $orderRepository;
}

/**
* @param \Magento\Sales\Block\Adminhtml\Order\View\Info $subject
* @param string $result
* @return string
*/
public function afterToHtml(
\Magento\Sales\Block\Adminhtml\Order\View\Info $subject,
$result
)
{
$orderId = $subject->getOrder()->getId();
$paymentInformation = $this->getOrderStatusHistoryComment($orderId);

$customBlock = $subject->getLayout()->getBlock('custom_block');
if ($customBlock !== false && $subject->getNameInLayout() == 'order_info') {
$customBlock->setData('payment_information', $paymentInformation);
$result = $result;
}
return $result;
}

/**
* Retrieve order status history comment
*
* @param int $orderId
* @return string
*/
protected function getOrderStatusHistoryComment($orderId)
{
try {
$order = $this->orderRepository->get($orderId);
$orderStatusHistory = $order->getStatusHistories();

// Reverse the array to get the last status history comment
$reversedOrderStatusHistory = array_reverse($orderStatusHistory);
$lastStatusHistory = array_pop($reversedOrderStatusHistory);

return $lastStatusHistory ? $lastStatusHistory->getComment() : '';
} catch (\Exception $e) {
// Handle exception if needed
return '';
}
}
}
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Magento 2 Khipu Plugin

khipu payment gateway Magento 2.4.8 plugin.
khipu payment gateway Magento 2.4.9 plugin.

This version is compatible with Magento 2.3 to 2.6

You can sign up for khipu account at <https://khipu.com>

## Install via Composer

You can install Magento 2.4.8 khipu plugin via [Composer](http://getcomposer.org/). Run the following command in your terminal:
You can install Magento 2.4.9 khipu plugin via [Composer](http://getcomposer.org/). Run the following command in your terminal:

1. Go to your Magento 2 root folder.

Expand All @@ -17,6 +17,7 @@ You can install Magento 2.4.8 khipu plugin via [Composer](http://getcomposer.org
```bash
composer require khipu/magento2-khipu
```

Wait while dependencies are updated.

3. Enter following commands to enable plugin:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "khipu/magento2-khipu",
"type": "magento2-module",
"description": "khipu integration for Magento 2",
"version": "2.4.8",
"version": "2.4.9",
"homepage": "https://khipu.com",
"license": [
"OSL-3.0"
Expand Down
6 changes: 6 additions & 0 deletions etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Sales\Block\Adminhtml\Order\View\Info">
<plugin name="custom_block_add" type="Khipu\Payment\Plugin\Block\Adminhtml\SalesOrderViewInfo" sortOrder="10" />
</type>
</config>
4 changes: 2 additions & 2 deletions etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noTestSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Khipu_Payment" setup_version="2.4.8" active="true">
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Khipu_Payment" setup_version="2.4.9" active="true">
<sequence>
<module name="Magento_Sales"/>
<module name="Magento_Checkout"/>
Expand Down
9 changes: 9 additions & 0 deletions view/adminhtml/layout/sales_order_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="order_additional_info">
<block class="Magento\Backend\Block\Template" name="custom_block" template="Khipu_Payment::order/view/custom.phtml" after="-" />
</referenceBlock>
</body>
</page>
30 changes: 30 additions & 0 deletions view/adminhtml/templates/order/view/custom.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<section class="admin__page-section">
<div class="admin__page-section-content">
<?php if ($paymentInformation = $block->getData('payment_information')): ?>
<?php
$lines = preg_split('/<br\s*\/?>/i', $paymentInformation);
$firstLine = reset($lines);

if (strpos($firstLine, 'Pago Khipu Aceptado') !== false):
?>
<table class="admin__table-secondary order-information-table" style="width: 50%;">
<?php
foreach ($lines as $line):
$parts = explode(': ', trim($line));
$label = isset($parts[0]) ? $parts[0] : '';
$value = isset($parts[1]) ? $parts[1] : '';

if (empty($label) && empty($value)) {
continue;
}
?>
<tr>
<th style="width: 30%;"><?php echo $label; ?></th>
<td><?php echo $value; ?></td>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
<?php endif; ?>
</div>
</section>

0 comments on commit 136956c

Please sign in to comment.