Skip to content

Commit

Permalink
Merge pull request #274 from BoulangerV/OX6-154-Amz_Fix_for_release
Browse files Browse the repository at this point in the history
OX6-154: Fix ref number double increment during AmzPay order
  • Loading branch information
janteuber authored Nov 14, 2023
2 parents d47883a + b88f3ea commit 4649a40
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
9 changes: 8 additions & 1 deletion extend/application/models/fcPayOneOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1696,7 +1696,14 @@ public function fcHandleAuthorization($blReturnRedirectUrl = false, $oPayGateway
$oPayment->load($this->oxorder__oxpaymenttype->value);
$sAuthorizationType = $oPayment->oxpayments__fcpoauthmode->value;

$sRefNr = $oPORequest->getRefNr($this);
if (
$this->oxorder__oxpaymenttype->value === 'fcpoamazonpay'
&& !empty($this->_oFcpoHelper->fcpoGetSessionVariable('fcpoRefNr'))
) {
$sRefNr = $oPORequest->getRefNr(false, true);
} else {
$sRefNr = $oPORequest->getRefNr($this);
}

$aResponse = $oPORequest->sendRequestAuthorization($sAuthorizationType, $this, $this->getOrderUser(), $aDynvalue, $sRefNr);
$sMode = $oPayment->fcpoGetMode($aDynvalue);
Expand Down
43 changes: 43 additions & 0 deletions lib/fcpohelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -643,4 +643,47 @@ protected static function _useRegistry()
return self::$_blUseRegistry;
}

/**
* Method that updates fcporefnr table if combination Prefix+RefNr isn't there yet
*
* @param string $sRefNr
* @param bool $blIncludesPrefix
* @return int
* @throws \OxidEsales\Eshop\Core\Exception\DatabaseConnectionException
*/
public function fcpoUpdateRefNr($sRefNr, $blIncludesPrefix = true)
{
try {
$iRet = 0;

$sRawPrefix = (string) $this->getConfig()->getConfigParam('sFCPORefPrefix');
$sBasePrefix = $blIncludesPrefix ? substr($sRefNr, 0, strlen($sRawPrefix)) : '';
if ($blIncludesPrefix && $sRawPrefix !== $sBasePrefix) {
// abort, the $sRefNr was built with a different prefix. Not possible to extract incremental part
return -1;
}
$sRawIncrement = $blIncludesPrefix ? substr($sRefNr, strlen($sRawPrefix)) : $sRefNr;

$oDb = oxDb::getDb();
$sPrefix = $oDb->quote($sRawPrefix);
$sIncrement = $oDb->quote($sRawIncrement);

$sQuery = "SELECT fcpo_refnr FROM fcporefnr WHERE fcpo_refprefix = {$sPrefix} AND fcpo_refnr = {$sIncrement}";
$sExistingRefNr = $oDb->GetOne($sQuery);

if ($sExistingRefNr) {
return $iRet;
}

$sQuery = "INSERT INTO fcporefnr (fcpo_refnr, fcpo_txid, fcpo_refprefix) VALUES ({$sIncrement}, '', {$sPrefix})";
$oResult = $oDb->Execute($sQuery);
if ($oResult) {
$iRet = 1;
}

return $iRet;
} catch (Exception $oEx) {
return -1;
}
}
}
2 changes: 2 additions & 0 deletions lib/fcporequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3322,6 +3322,7 @@ public function getRefNr($oOrder = false, $blAddPrefixToSession = false)
if ($blUseSessionRefNr) {
$sRefNrComplete = ($blAddPrefixToSession) ?
$sRawPrefix . $sSessionRefNr : $sSessionRefNr;
$this->_oFcpoHelper->fcpoUpdateRefNr($sSessionRefNr, false);
return $sRefNrComplete;
}

Expand All @@ -3330,6 +3331,7 @@ public function getRefNr($oOrder = false, $blAddPrefixToSession = false)

if ($oOrder && !empty($oOrder->oxorder__oxordernr->value)) {
$sRefNr = $oOrder->oxorder__oxordernr->value;
$this->_oFcpoHelper->fcpoUpdateRefNr($sRefNr, false);
} else {
$sQuery = "SELECT MAX(fcpo_refnr) FROM fcporefnr WHERE fcpo_refprefix = {$sPrefix}";
$iMaxRefNr = $oDb->GetOne($sQuery);
Expand Down

0 comments on commit 4649a40

Please sign in to comment.