diff --git a/Observer/ConfirmDonationOnOrderComplete.php b/Observer/ConfirmDonationOnOrderComplete.php
index 9c099e0..680a071 100644
--- a/Observer/ConfirmDonationOnOrderComplete.php
+++ b/Observer/ConfirmDonationOnOrderComplete.php
@@ -37,9 +37,12 @@ public function execute(Observer $observer)
{
try {
$order = $observer->getEvent()->getOrder();
+ $donationAmount = (float) $order->getDonmodonation();
+
if ($order->getState() == 'complete') {
- if ($order->getDonmodonation() > 0) {
+ if ($donationAmount > 0) {
+ $orderId = $order->getId();
$quoteId = $order->getQuoteId();
$maskedId = $this->quoteIdToMaskedQuoteId->execute($quoteId);
@@ -48,11 +51,11 @@ public function execute(Observer $observer)
$this->donationResource->load($donationModel, $maskedId, 'masked_quote_id');
$donationModel
- ->setStatus(DonationModel::STATUS_CONFIRMED);
+ ->setStatus(DonationModel::STATUS_CONFIRMED)
+ ->setOrderId($orderId);
$this->donationResource->save($donationModel);
}
- $this->donationResource->save($donationModel);
}
} catch (\Exception $exception) {
$this->logger->error("Donmo ConfirmDonationOnOrderComplete Observer error:\n" . $exception);
diff --git a/Observer/CreateDonation.php b/Observer/CreateDonation.php
index c3b4c11..f3cc8f4 100644
--- a/Observer/CreateDonation.php
+++ b/Observer/CreateDonation.php
@@ -8,8 +8,6 @@
use Donmo\Roundup\Model\Config as DonmoConfig;
-use Magento\Framework\Intl\DateTimeFactory;
-
use Donmo\Roundup\Model\Donmo\DonationFactory;
use Donmo\Roundup\Model\Donmo\Donation as DonationModel;
@@ -24,7 +22,6 @@ class CreateDonation implements ObserverInterface
private DonationFactory $donationFactory;
private DonationResource $donationResource;
- private DateTimeFactory $dateTimeFactory;
private Logger $logger;
private QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteId;
@@ -32,7 +29,6 @@ class CreateDonation implements ObserverInterface
public function __construct(
DonationFactory $donationFactory,
DonationResource $donationResource,
- DateTimeFactory $dateTimeFactory,
Logger $logger,
DonmoConfig $config,
QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteId
@@ -40,7 +36,6 @@ public function __construct(
{
$this->donationFactory = $donationFactory;
$this->donationResource = $donationResource;
- $this->dateTimeFactory = $dateTimeFactory;
$this->logger = $logger;
$this->donmoConfig = $config;
$this->quoteIdToMaskedQuoteId = $quoteIdToMaskedQuoteId;
@@ -49,29 +44,23 @@ public function __construct(
public function execute(Observer $observer)
{
+ $order = $observer->getEvent()->getOrder();
+
+ $donationAmount = (float) $order->getDonmodonation();
+
try {
- $order = $observer->getEvent()->getOrder();
- if ($order->getState() == 'new') {
- if ($order->getDonmodonation() > 0) {
- $orderId = $order->getId();
- $quoteId = $order->getQuoteId();
- $maskedId = $this->quoteIdToMaskedQuoteId->execute($quoteId);
- $currentMode = $this->donmoConfig->getCurrentMode();
- $createdAt = $this->dateTimeFactory->create(
- $order->getCreatedAt(),
- new \DateTimeZone('UTC')
- );
-
- $donationModel = $this->donationFactory->create();
-
- $donationModel
- ->setMaskedQuoteId($maskedId)
- ->setOrderId($orderId)
- ->setDonationAmount($order->getDonmodonation())
- ->setCreatedAt($createdAt)
- ->setStatus(DonationModel::STATUS_PENDING)
- ->setMode($currentMode);
- }
+ if ($donationAmount > 0) {
+ $quoteId = $order->getQuoteId();
+ $maskedId = $this->quoteIdToMaskedQuoteId->execute($quoteId);
+ $currentMode = $this->donmoConfig->getCurrentMode();
+
+ $donationModel = $this->donationFactory->create();
+
+ $donationModel
+ ->setMaskedQuoteId($maskedId)
+ ->setDonationAmount($donationAmount)
+ ->setStatus(DonationModel::STATUS_PENDING)
+ ->setMode($currentMode);
$this->donationResource->save($donationModel);
}
diff --git a/Observer/RemoveDonationWithOrder.php b/Observer/RemoveDonationWithOrder.php
index faeedb8..ef41633 100644
--- a/Observer/RemoveDonationWithOrder.php
+++ b/Observer/RemoveDonationWithOrder.php
@@ -54,7 +54,9 @@ public function execute(Observer $observer)
$newDonationStatus = DonationModel::STATUS_REFUNDED;
}
- if ($order->getDonmodonation() > 0) {
+ $donationAmount = (float) $order->getDonmodonation();
+
+ if ($donationAmount> 0) {
$quoteId = $order->getQuoteId();
$maskedId = $this->quoteIdToMaskedQuoteId->execute($quoteId);
@@ -65,7 +67,8 @@ public function execute(Observer $observer)
if ($donationModel->getData('status') != DonationModel::STATUS_SENT) {
$donationModel->setData('status', $newDonationStatus);
$this->donationResource->save($donationModel);
- } // make Delete request to Donmo API for only if donation is already sent
+ }
+ // make Delete request to Donmo API for only if donation is already sent
else {
$status = $this->apiService->deleteDonation($donationMode, $maskedId);
diff --git a/etc/db_schema.xml b/etc/db_schema.xml
index f6df9dc..a92174e 100644
--- a/etc/db_schema.xml
+++ b/etc/db_schema.xml
@@ -20,9 +20,9 @@
-
+
-
+
@@ -31,6 +31,8 @@
+
+
-
+
-
+
+
+
diff --git a/lib/ApiService.php b/lib/ApiService.php
index bebd3e9..2289e21 100644
--- a/lib/ApiService.php
+++ b/lib/ApiService.php
@@ -71,6 +71,7 @@ public function deleteDonation($donationMode, $id) {
$this->logger->error("Unsuccessful Delete Donation API request: \n" . $body);
}
+ return $status;
}
}