Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OX6-160: Add order status safety for late/bad timing TxStatus handling #278

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 31 additions & 8 deletions extend/application/models/fcPayOneOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,15 @@ protected function _fcpoFinalizeOrder($oBasket, $oUser, $blRecalculatingOrder) {
$this->_updateOrderDate();
}

$this->_fcpoSetOrderStatus();
/**
* OX6-160 : This parameter forces the check of DB for appointed TxStatus
* That helps preventing incorrect order status (error) when TxStatus handling finished late, at the wrong moment
*/
$blFcpoRefreshFromDb = true;
$this->_fcpoSetOrderStatus($blFcpoRefreshFromDb);
if ($blFcpoRefreshFromDb) {
$this->save();
}

// store orderid
$oBasket->setOrderId($this->getId());
Expand Down Expand Up @@ -969,9 +977,9 @@ protected function _fcpoSaveAfterRedirect($blSaveAfterRedirect)
*
* @return void
*/
protected function _fcpoSetOrderStatus() {
protected function _fcpoSetOrderStatus($blFcpoRefreshFromDb = false) {
$blIsAmazonPending = $this->_oFcpoHelper->fcpoGetSessionVariable('fcpoAmazonPayOrderIsPending');
$blOrderOk = $this->_fcpoValidateOrderAgainstProblems();
$blOrderOk = $this->_fcpoValidateOrderAgainstProblems($blFcpoRefreshFromDb);

if ($blIsAmazonPending) {
$this->_setOrderStatus('PENDING');
Expand All @@ -991,7 +999,12 @@ protected function _fcpoSetOrderStatus() {
* @param void
* @return bool
*/
protected function _fcpoValidateOrderAgainstProblems() {
protected function _fcpoValidateOrderAgainstProblems($blFcpoRefreshFromDb = false) {

if ($blFcpoRefreshFromDb) {
$this->_fcpoCheckTxid();
}

$blOrderOk = (
$this->_fcpoGetAppointedError() === false &&
$this->_blOrderHasProblems === false
Expand Down Expand Up @@ -1070,20 +1083,30 @@ protected function _fcpoCheckTxid()
{
$blAppointedError = false;
$sTxid = $this->_oFcpoHelper->fcpoGetSessionVariable('fcpoTxid');
if (!$sTxid) {
$sTxid = $this->oxorder__fcpotxid->value;
}

$sTestOxid = '';
if ($sTxid) {
$sQuery = "SELECT oxid FROM fcpotransactionstatus WHERE FCPO_TXACTION = 'appointed' AND fcpo_txid = '" . $sTxid . "'";
$sTestOxid = $this->_oFcpoDb->getOne($sQuery);
}

$oLang = $this->_oFcpoHelper->fcpoGetLang();
$sCurrentRemark = $this->oxorder__oxremark->value;
$sAppointedErrorRemark = $oLang->translateString('FCPO_REMARK_APPOINTED_MISSING');
$blAppointedRemarkExists = strpos($sCurrentRemark, $sAppointedErrorRemark);
if (!$sTestOxid) {
$blAppointedError = true;
$this->oxorder__oxfolder = new oxField('ORDERFOLDER_PROBLEMS', oxField::T_RAW);
$oLang = $this->_oFcpoHelper->fcpoGetLang();
$sCurrentRemark = $this->oxorder__oxremark->value;
$sAddErrorRemark = $oLang->translateString('FCPO_REMARK_APPOINTED_MISSING');
$sNewRemark = $sCurrentRemark." ".$sAddErrorRemark;
if ($blAppointedRemarkExists === false) {
$sNewRemark = $sCurrentRemark." ".$sAppointedErrorRemark;
$this->oxorder__oxremark = new oxField($sNewRemark, oxField::T_RAW);
}
} else {
$this->oxorder__oxfolder = new oxField('ORDERFOLDER_NEW', oxField::T_RAW);
$sNewRemark = str_replace($sAppointedErrorRemark, '', $sCurrentRemark);
$this->oxorder__oxremark = new oxField($sNewRemark, oxField::T_RAW);
}
$this->_fcpoSetAppointedError($blAppointedError);
Expand Down
Loading