Skip to content

Commit

Permalink
UNZER-497 Send order confirmation only on order with status OK
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniil Tkachev committed Oct 14, 2024
1 parent d3e25d1 commit 383630b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 32 deletions.
37 changes: 7 additions & 30 deletions src/Model/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,13 @@ class Order extends Order_parent
* @param Basket $oBasket
* @param User $oUser
* @return int|bool
* @throws Exception
* @throws \Doctrine\DBAL\Driver\Exception
*
* @throws \UnzerSDK\Exceptions\UnzerApiException
* @SuppressWarnings(PHPMD.ElseExpression)
*/
public function finalizeUnzerOrderAfterRedirect(
Basket $oBasket,
User $oUser
) {
): bool|int {
$orderId = Registry::getSession()->getVariable('sess_challenge');
$orderId = is_string($orderId) ? $orderId : '';
$iRet = self::ORDER_STATE_PAYMENTERROR;
Expand All @@ -64,21 +62,13 @@ public function finalizeUnzerOrderAfterRedirect(
$unzerService = $this->getServiceFromContainer(Unzer::class);
$unzerPaymentStatus = $paymentService->getUnzerPaymentStatus();

// copies user info
$this->setUser($oUser);

// copies user info
$this->assignUserInformation($oUser);

// copies basket info
$this->loadFromBasket($oBasket);

$oUserPayment = $this->setPayment($oBasket->getPaymentId());

// set folder information, order is new
$this->setFolder();

//saving all order data to DB
$this->save();

if (!$this->getFieldData('oxordernr')) {
Expand All @@ -90,35 +80,22 @@ public function finalizeUnzerOrderAfterRedirect(
$this->setUnzerOrderNr((string)$unzerOrderId);
$unzerService->resetUnzerOrderId();

// deleting remark info only when order is finished
Registry::getSession()->deleteVariable('ordrem');

//#4005: Order creation time is not updated when order processing is complete
$this->updateOrderDate();

// store orderid
$oBasket->setOrderId($orderId);

// updating wish lists
$this->updateWishlist($oBasket->getContents(), $oUser);

// updating users notice list
$this->updateNoticeList($oBasket->getContents(), $oUser);

// marking vouchers as used and sets them to $this->_aVoucherList (will be used in order email)
$this->markVouchers($oBasket, $oUser);

// send order by email to shop owner and current user
// don't let order fail due to stock check while sending out the order mail
Registry::getSession()->setVariable('blDontCheckProductStockForUnzerMails', true);
$iRet = $this->sendOrderByEmail($oUser, $oBasket, $oUserPayment);
Registry::getSession()->deleteVariable('blDontCheckProductStockForUnzerMails');

$this->setOrderStatus($unzerPaymentStatus);

if ($unzerPaymentStatus === 'OK') {
$this->markUnzerOrderAsPaid();
$this->setTmpOrderStatus($unzerOrderId, 'FINISHED');
// send order by email to shop owner and current user
// don't let order fail due to stock check while sending out the order mail
Registry::getSession()->setVariable('blDontCheckProductStockForUnzerMails', true);
$iRet = $this->sendOrderByEmail($oUser, $oBasket, $oUserPayment);
Registry::getSession()->deleteVariable('blDontCheckProductStockForUnzerMails');
} else {
Registry::getSession()->setVariable('orderCancellationProcessed', true);
$this->setOrderStatus($unzerPaymentStatus); //ERROR if paypal
Expand Down
6 changes: 4 additions & 2 deletions src/Service/UnzerSDKLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
use OxidSolutionCatalysts\Unzer\Core\UnzerDefinitions;
use UnzerSDK\Unzer;

/**
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
class UnzerSDKLoader
{
use ServiceContainer;
Expand Down Expand Up @@ -77,8 +80,7 @@ public function getUnzerSDK(string $paymentId = '', string $currency = '', strin
} catch (UnzerException $e) {
$logEntry = sprintf(
'Try to get the SDK with the Key "%s" defined by paymentId "%s", currency "%s", customerType "%s" '
. $e->getTraceAsString()
,
. $e->getTraceAsString(),
$key,
$paymentId,
$currency,
Expand Down
1 change: 1 addition & 0 deletions tests/PhpMd/standard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
</properties>
<!-- Exclude UnzerPayment.php specifically -->
<exclude-pattern>*UnzerPayment.php</exclude-pattern>
<exclude-pattern>*UnzerSDKLoader.php</exclude-pattern>
</rule>
</rule>

Expand Down

0 comments on commit 383630b

Please sign in to comment.