Skip to content

Commit edc202f

Browse files
authored
Merge pull request #20 from thelia-modules/feat/notification_history
Save refund notification id (avoid duplicate refund)
2 parents 08d25bf + 0a29613 commit edc202f

9 files changed

Lines changed: 115 additions & 5 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,26 @@ CREATE TABLE `pay_plug_module_delivery_type`
9393
ON DELETE CASCADE
9494
) ENGINE=InnoDB;
9595

96+
-- ---------------------------------------------------------------------
97+
-- pay_plug_notification_history
98+
-- ---------------------------------------------------------------------
99+
100+
DROP TABLE IF EXISTS `pay_plug_notification_history`;
101+
102+
CREATE TABLE `pay_plug_notification_history`
103+
(
104+
`uuid` VARCHAR(150) NOT NULL,
105+
`order_id` INTEGER NOT NULL,
106+
`created_at` DATETIME,
107+
`updated_at` DATETIME,
108+
PRIMARY KEY (`uuid`,`order_id`),
109+
INDEX `pay_plug_notification_history_fi_75704f` (`order_id`),
110+
CONSTRAINT `pay_plug_notification_history_fk_75704f`
111+
FOREIGN KEY (`order_id`)
112+
REFERENCES `order` (`id`)
113+
ON UPDATE CASCADE
114+
ON DELETE CASCADE
115+
) ENGINE=InnoDB;
116+
96117
# This restores the fkey checks, after having unset them earlier
97118
SET FOREIGN_KEY_CHECKS = 1;

Config/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<language>en_US</language>
1818
<language>fr_FR</language>
1919
</languages>
20-
<version>2.1.1</version>
20+
<version>2.1.2</version>
2121
<authors>
2222
<author>
2323
<name>Vincent Lopes-Vicente</name>

Config/schema.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,15 @@
5353
</foreign-key>
5454
</table>
5555

56+
57+
<table name="pay_plug_notification_history" namespace="PayPlugModule\Model">
58+
<column name="uuid" type="VARCHAR" size="150" primaryKey="true"/>
59+
<column name="order_id" type="INTEGER" required="true" primaryKey="true"/>
60+
<foreign-key foreignTable="order" onDelete="CASCADE" onUpdate="CASCADE">
61+
<reference local="order_id" foreign="id" />
62+
</foreign-key>
63+
<behavior name="timestampable" />
64+
</table>
65+
5666
<external-schema filename="local/config/schema.xml" referenceOnly="true" />
5767
</database>

Config/sqldb.map

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Sqlfile -> Database map
2-
thelia.sql=thelia
2+
TheliaMain.sql=TheliaMain

Config/update/2.1.2.sql

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This is a fix for InnoDB in MySQL >= 4.1.x
2+
# It "suspends judgement" for fkey relationships until are tables are set.
3+
SET FOREIGN_KEY_CHECKS = 0;
4+
5+
-- ---------------------------------------------------------------------
6+
-- pay_plug_notification_history
7+
-- ---------------------------------------------------------------------
8+
9+
DROP TABLE IF EXISTS `pay_plug_notification_history`;
10+
11+
CREATE TABLE `pay_plug_notification_history`
12+
(
13+
`uuid` VARCHAR(150) NOT NULL,
14+
`order_id` INTEGER NOT NULL,
15+
`created_at` DATETIME,
16+
`updated_at` DATETIME,
17+
PRIMARY KEY (`uuid`,`order_id`),
18+
INDEX `pay_plug_notification_history_fi_75704f` (`order_id`),
19+
CONSTRAINT `pay_plug_notification_history_fk_75704f`
20+
FOREIGN KEY (`order_id`)
21+
REFERENCES `order` (`id`)
22+
ON UPDATE CASCADE
23+
ON DELETE CASCADE
24+
) ENGINE=InnoDB;
25+
26+
# This restores the fkey checks, after having unset them earlier
27+
SET FOREIGN_KEY_CHECKS = 1;

EventListener/NotificationListener.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@
1414
use PayPlugModule\Model\PayPlugCard;
1515
use PayPlugModule\Model\PayPlugCardQuery;
1616
use PayPlugModule\Model\PayPlugConfigValue;
17+
use PayPlugModule\Model\PayPlugNotificationHistory;
18+
use PayPlugModule\Model\PayPlugNotificationHistoryQuery;
1719
use PayPlugModule\PayPlugModule;
1820
use PayPlugModule\Service\OrderStatusService;
1921
use Propel\Runtime\Collection\Collection;
2022
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
2123
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
2224
use Thelia\Core\Event\Order\OrderEvent;
2325
use Thelia\Core\Event\TheliaEvents;
26+
use Thelia\Log\Tlog;
2427
use Thelia\Model\Order;
2528
use Thelia\Model\OrderQuery;
2629
use Thelia\Model\OrderStatusQuery;
@@ -164,11 +167,20 @@ public function handleRefundNotification(RefundNotificationEvent $event)
164167
if (!$transactionRef) {
165168
return;
166169
}
167-
170+
$id = $event->getResource()->id;
168171
$order = OrderQuery::create()
169172
->filterByTransactionRef($transactionRef)
170173
->findOne();
171174

175+
$notificationHistory = PayPlugNotificationHistoryQuery::create()
176+
->filterByUuid($id)
177+
->findOne();
178+
179+
if (!!$notificationHistory) {
180+
Tlog::getInstance()->addAlert("Notification '{$id}' already exist");
181+
return;
182+
}
183+
172184
$multiPayment = OrderPayPlugMultiPaymentQuery::create()
173185
->findOneByPaymentId($transactionRef);
174186

@@ -182,6 +194,8 @@ public function handleRefundNotification(RefundNotificationEvent $event)
182194
return;
183195
}
184196

197+
(new PayPlugNotificationHistory())->setUuid($id)->setOrderId($order->getId())->save();
198+
185199
$orderPayPlugData = OrderPayPlugDataQuery::create()
186200
->findOneById($order->getId());
187201

@@ -204,4 +218,4 @@ public static function getSubscribedEvents()
204218
RefundNotificationEvent::REFUND_NOTIFICATION_EVENT => ['handleRefundNotification', 128]
205219
];
206220
}
207-
}
221+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace PayPlugModule\Model;
4+
5+
use PayPlugModule\Model\Base\PayPlugNotificationHistory as BasePayPlugNotificationHistory;
6+
7+
/**
8+
* Skeleton subclass for representing a row from the 'pay_plug_notification_history' table.
9+
*
10+
*
11+
*
12+
* You should add additional methods to this class to meet the
13+
* application requirements. This class will only be generated as
14+
* long as it does not already exist in the output directory.
15+
*/
16+
class PayPlugNotificationHistory extends BasePayPlugNotificationHistory
17+
{
18+
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace PayPlugModule\Model;
4+
5+
use PayPlugModule\Model\Base\PayPlugNotificationHistoryQuery as BasePayPlugNotificationHistoryQuery;
6+
7+
/**
8+
* Skeleton subclass for performing query and update operations on the 'pay_plug_notification_history' table.
9+
*
10+
*
11+
*
12+
* You should add additional methods to this class to meet the
13+
* application requirements. This class will only be generated as
14+
* long as it does not already exist in the output directory.
15+
*/
16+
class PayPlugNotificationHistoryQuery extends BasePayPlugNotificationHistoryQuery
17+
{
18+
19+
}

PayPlugModule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function postActivation(ConnectionInterface $con = null): void
3737
{
3838
if (!$this->getConfigValue('is_initialized', false)) {
3939
$database = new Database($con);
40-
$database->insertSql(null, [__DIR__ . "/Config/thelia.sql"]);
40+
$database->insertSql(null, [__DIR__ . "/Config/TheliaMain.sql"]);
4141
}
4242
}
4343

0 commit comments

Comments
 (0)