Skip to content

Commit a590129

Browse files
authored
Merge pull request #314 from BoulangerV/OX6-188-Code_improve
OX6-188: Refactor txstatus endpoints (status, base and forward)
2 parents bbb6b54 + afe2dcc commit a590129

13 files changed

Lines changed: 456 additions & 207 deletions

File tree

application/controllers/admin/fcpayone_log.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,20 @@ public function render()
8282
public function getStatus($oOrder)
8383
{
8484
if(!$this->_aStatus) {
85-
$oDb = $this->_oFcpoHelper->fcpoGetDb();
86-
$aRows = $oDb->getAll("SELECT oxid FROM fcpotransactionstatus WHERE fcpo_txid = '{$oOrder->oxorder__fcpotxid->value}' ORDER BY oxid ASC");
85+
$oDb = $this->_oFcpoHelper->fcpoGetPdoDb();
86+
$sQuery = "
87+
SELECT oxid
88+
FROM fcpotransactionstatus
89+
WHERE fcpo_txid = :sTxid
90+
ORDER BY oxid ASC";
91+
$aRows = $oDb->fetchAllAssociative($sQuery, [
92+
'sTxid' => $oOrder->oxorder__fcpotxid->value
93+
]);
94+
8795
$aStatus = array();
8896
foreach ($aRows as $aRow) {
8997
$oTransactionStatus = oxNew('fcpotransactionstatus');
90-
$oTransactionStatus->load($aRow[0]);
98+
$oTransactionStatus->load($aRow['oxid']);
9199
$aStatus[] = $oTransactionStatus;
92100
}
93101
$this->_aStatus = $aStatus;

application/models/fcpotransactionstatus.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ public function fcpoGetForwardRedirects()
215215
sfq.FCRESPONSEINFO
216216
FROM fcpostatusforwardqueue sfq
217217
LEFT JOIN fcpostatusforwarding sf ON (sfq.FCSTATUSFORWARDID = sf.OXID)
218-
WHERE sfq.FCSTATUSMESSAGEID='{$sStatusmessageId}'
218+
WHERE sfq.FCSTATUSMESSAGEID= " . $this->_oFcpoDb->quote($sStatusmessageId) . "
219219
";
220220

221221
$aRows = $this->_oFcpoDb->GetAll($sQuery);
@@ -283,7 +283,7 @@ protected function _fcpoGetMapAction($sTxAction, $aMatchMap, $sDefault)
283283
*/
284284
protected function _fcpoGetOrderByTxid($sTxid)
285285
{
286-
$sOxid = $this->_oFcpoDb->GetOne("SELECT oxid FROM oxorder WHERE fcpotxid = '{$sTxid}'");
286+
$sOxid = $this->_oFcpoDb->GetOne("SELECT oxid FROM oxorder WHERE fcpotxid = " . $this->_oFcpoDb->quote($sTxid));
287287
$oOrder = $this->_oFcpoHelper->getFactoryObject('oxorder');
288288
$oOrder->load($sOxid);
289289

extend/application/models/fcPayOneOrder.php

Lines changed: 67 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class fcPayOneOrder extends fcPayOneOrder_parent
3434
/**
3535
* Helper object for dealing with different shop versions
3636
*
37-
* @var object
37+
* @var fcpohelper
3838
*/
3939
protected $_oFcpoHelper = null;
4040

@@ -930,8 +930,12 @@ public function fcpoGetShadowBasket($blByOrderId=false) {
930930

931931
$sSerializedShadowBasket = $oDb->GetOne($sQuery);
932932

933-
if ($sSerializedShadowBasket) {
934-
$oShadowBasket = unserialize(base64_decode($sSerializedShadowBasket));
933+
if (!empty($sSerializedShadowBasket)) {
934+
try {
935+
$oShadowBasket = unserialize(base64_decode($sSerializedShadowBasket), ['allowed_classes' => true]);
936+
} catch (Exception $oEx) {
937+
$oShadowBasket = false;
938+
}
935939
}
936940

937941
return $oShadowBasket;
@@ -976,8 +980,20 @@ protected function _fcpoFinishOrder($blRecalculatingOrder, $oUser, $oBasket, $oU
976980
protected function _fcpoSaveAfterRedirect($blSaveAfterRedirect)
977981
{
978982
if ($blSaveAfterRedirect === true && !empty($this->oxorder__fcpotxid->value)) {
979-
$sQuery = "UPDATE fcpotransactionstatus SET fcpo_ordernr = '{$this->oxorder__oxordernr->value}' WHERE fcpo_txid = '".$this->oxorder__fcpotxid->value."'";
980-
$this->_oFcpoDb->Execute($sQuery);
983+
984+
$oDb = $this->_oFcpoHelper->fcpoGetDb();
985+
$sQuery = "
986+
UPDATE
987+
fcpotransactionstatus
988+
SET
989+
fcpo_ordernr = :iOrderNr
990+
WHERE
991+
fcpo_txid = :sTxid
992+
";
993+
$oDb->execute($sQuery, [
994+
'iOrderNr' => $this->oxorder__oxordernr->value,
995+
'sTxid' => $this->oxorder__fcpotxid->value
996+
]);
981997
}
982998
}
983999

@@ -1070,7 +1086,11 @@ protected function _fcpoSaveOrderValues($sTxid, $iOrderNotChecked)
10701086
if ($sWorkorderId) {
10711087
$this->oxorder__fcpoworkorderid = new oxField($sWorkorderId, oxField::T_RAW);
10721088
}
1073-
$this->_oFcpoDb->Execute("UPDATE fcporefnr SET fcpo_txid = '" . $sTxid . "' WHERE fcpo_refnr = '" . $this->_oFcpoHelper->fcpoGetRequestParameter('refnr') . "'");
1089+
$this->_oFcpoDb->Execute("
1090+
UPDATE fcporefnr
1091+
SET fcpo_txid = " . $this->_oFcpoDb->quote($sTxid) . "
1092+
WHERE fcpo_refnr = " . $this->_oFcpoDb->quote($this->_oFcpoHelper->fcpoGetRequestParameter('refnr')) . "
1093+
");
10741094
$this->_oFcpoHelper->fcpoDeleteSessionVariable('fcpoOrderNr');
10751095
$this->_oFcpoHelper->fcpoDeleteSessionVariable('fcpoTxid');
10761096
$this->_oFcpoHelper->fcpoDeleteSessionVariable('fcpoRefNr');
@@ -1180,7 +1200,17 @@ public function allowCapture()
11801200
}
11811201

11821202
if ($blReturn) {
1183-
$iCount = $this->_oFcpoDb->GetOne("SELECT COUNT(*) FROM fcpotransactionstatus WHERE fcpo_txid = '{$this->oxorder__fcpotxid->value}'");
1203+
$oDb = $this->_oFcpoHelper->fcpoGetPdoDb();
1204+
1205+
$sQuery = "
1206+
SELECT COUNT(*)
1207+
FROM fcpotransactionstatus
1208+
WHERE fcpo_txid = :sTxid
1209+
";
1210+
$iCount = $oDb->fetchOne($sQuery, [
1211+
'sTxid' => $this->oxorder__fcpotxid->value
1212+
]);
1213+
11841214
$blReturn = ($iCount == 0) ? false : true;
11851215
}
11861216

@@ -1199,17 +1229,21 @@ public function allowDebit() {
11991229

12001230
if ($blIsAuthorization) return true;
12011231

1232+
$oDb = $this->_oFcpoHelper->fcpoGetPdoDb();
12021233
$sQuery = "
1203-
SELECT
1204-
COUNT(*)
1205-
FROM
1206-
fcpotransactionstatus
1207-
WHERE
1208-
fcpo_txid = '{$this->oxorder__fcpotxid->value}' AND
1209-
fcpo_txaction = 'appointed'
1234+
SELECT
1235+
COUNT(*)
1236+
FROM
1237+
fcpotransactionstatus
1238+
WHERE
1239+
fcpo_txid = :sTxid
1240+
AND
1241+
fcpo_txaction = :sTxaction
12101242
";
1211-
1212-
$iCount = (int) $this->_oFcpoDb->GetOne($sQuery);
1243+
$iCount = (int) $oDb->fetchOne($sQuery, [
1244+
'sTxid' => $this->oxorder__fcpotxid->value,
1245+
'sTxaction' => 'appointed'
1246+
]);
12131247

12141248
$blReturn = ($iCount === 1);
12151249

@@ -1300,7 +1334,7 @@ public function isCancellationReasonNeeded()
13001334
*/
13011335
public function getSequenceNumber()
13021336
{
1303-
$iCount = $this->_oFcpoDb->GetOne("SELECT MAX(fcpo_sequencenumber) FROM fcpotransactionstatus WHERE fcpo_txid = '{$this->oxorder__fcpotxid->value}'");
1337+
$iCount = $this->_oFcpoDb->GetOne("SELECT MAX(fcpo_sequencenumber) FROM fcpotransactionstatus WHERE fcpo_txid = " . $this->_oFcpoDb->quote($this->oxorder__fcpotxid->value));
13041338

13051339
$iReturn = ($iCount === null) ? 0 : $iCount + 1;
13061340

@@ -1314,7 +1348,7 @@ public function getSequenceNumber()
13141348
*/
13151349
public function getLastStatus()
13161350
{
1317-
$sOxid = $this->_oFcpoDb->GetOne("SELECT * FROM fcpotransactionstatus WHERE fcpo_txid = '{$this->oxorder__fcpotxid->value}' ORDER BY fcpo_sequencenumber DESC, oxtimestamp DESC");
1351+
$sOxid = $this->_oFcpoDb->GetOne("SELECT * FROM fcpotransactionstatus WHERE fcpo_txid = " . $this->_oFcpoDb->quote($this->oxorder__fcpotxid->value) . " ORDER BY fcpo_sequencenumber DESC, oxtimestamp DESC");
13181352
if ($sOxid) {
13191353
$oStatus = $this->_oFcpoHelper->getFactoryObject('fcpotransactionstatus');
13201354
$oStatus->load($sOxid);
@@ -1361,7 +1395,7 @@ protected function getRequest($aAcceptedStatus = array('APPROVED'))
13611395
$sSelect = "
13621396
SELECT oxid
13631397
FROM fcporequestlog
1364-
WHERE fcpo_refnr = '{$this->oxorder__fcporefnr->value}'
1398+
WHERE fcpo_refnr = ". $this->_oFcpoDb->quote($this->oxorder__fcporefnr->value) . "
13651399
AND (
13661400
fcpo_requesttype = 'preauthorization' OR
13671401
fcpo_requesttype = 'authorization'
@@ -1643,9 +1677,17 @@ public function fcGetArtStockInBasket($oBasket, $sArtId, $sExpiredArtId = null)
16431677
*/
16441678
public function fcpoGetMandateFilename()
16451679
{
1680+
$oDb = $this->_oFcpoHelper->fcpoGetPdoDb();
1681+
16461682
$sOxid = $this->getId();
1647-
$sQuery = "SELECT fcpo_filename FROM fcpopdfmandates WHERE oxorderid = '{$sOxid}'";
1648-
$sFile = $this->_oFcpoDb->GetOne($sQuery);
1683+
$sQuery = "
1684+
SELECT fcpo_filename
1685+
FROM fcpopdfmandates
1686+
WHERE oxorderid = :sOxid
1687+
";
1688+
$sFile = $oDb->fetchOne($sQuery, [
1689+
'sOxid' => $sOxid
1690+
]);
16491691

16501692
return $sFile;
16511693
}
@@ -1658,7 +1700,7 @@ public function fcpoGetMandateFilename()
16581700
*/
16591701
public function fcpoGetStatus()
16601702
{
1661-
$sQuery = "SELECT oxid FROM fcpotransactionstatus WHERE fcpo_txid = '{$this->oxorder__fcpotxid->value}' ORDER BY fcpo_sequencenumber ASC";
1703+
$sQuery = "SELECT oxid FROM fcpotransactionstatus WHERE fcpo_txid = " . $this->_oFcpoDb->quote($this->oxorder__fcpotxid->value) . " ORDER BY fcpo_sequencenumber ASC";
16621704
$aRows = $this->_oFcpoDb->getAll($sQuery);
16631705

16641706
$aStatus = array();
@@ -2097,17 +2139,18 @@ protected function _fcpoWriteClearingInformation($sPaymentId, $aResponse)
20972139
}
20982140

20992141
if(!empty($aUpdatedFields)) {
2142+
$oDb = oxdb::getDb();
21002143
$sQuery = 'UPDATE oxorder SET ';
21012144

21022145
foreach ($aUpdatedFields as $sField => $sValue) {
2103-
$sQuery .= " $sField = '$sValue',";
2146+
$sQuery .= " $sField = " . $oDb->quote($sValue) . ",";
21042147
}
21052148

21062149
$sQuery = substr($sQuery, 0, strlen($sQuery)-1);
21072150

21082151
$sQuery .= " WHERE oxid='" . $this->oxorder__oxid . "'";
21092152

2110-
oxdb::getDb()->execute($sQuery);
2153+
$oDb->execute($sQuery);
21112154
}
21122155
}
21132156
}

extend/application/models/fcPayOnePayment.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,11 +332,11 @@ public function fcpoGetUserPaymentId($sUserOxid, $sPaymentType)
332332
*/
333333
public function isPaymentMethodAvailableToUser($sSubPaymentId, $sType, $sUserBillCountryId, $sUserDelCountryId)
334334
{
335-
$sBaseQuery = "SELECT COUNT(*) FROM fcpopayment2country WHERE fcpo_paymentid = '{$sSubPaymentId}' AND fcpo_type = '{$sType}'";
335+
$sBaseQuery = "SELECT COUNT(*) FROM fcpopayment2country WHERE fcpo_paymentid = " . $this->_oFcpoDb->quote($sSubPaymentId) . " AND fcpo_type = " . $this->_oFcpoDb->quote($sType);
336336
if ($sUserDelCountryId !== false && $sUserBillCountryId != $sUserDelCountryId) {
337-
$sWhereCountry = "AND (fcpo_countryid = '{$sUserBillCountryId}' || fcpo_countryid = '{$sUserDelCountryId}')";
337+
$sWhereCountry = "AND (fcpo_countryid = " . $this->_oFcpoDb->quote($sUserBillCountryId) . " || fcpo_countryid = " . $this->_oFcpoDb->quote($sUserDelCountryId) . ")";
338338
} else {
339-
$sWhereCountry = "AND fcpo_countryid = '{$sUserBillCountryId}'";
339+
$sWhereCountry = "AND fcpo_countryid = " . $this->_oFcpoDb->quote($sUserBillCountryId);
340340
}
341341
$sQuery = "SELECT IF(({$sBaseQuery} LIMIT 1) > 0,IF(({$sBaseQuery} {$sWhereCountry} LIMIT 1) > 0,1,0),1)";
342342

@@ -412,7 +412,7 @@ protected function _fcGetCountries($sCampaignId)
412412
{
413413
$aCountries = array();
414414

415-
$sQuery = "SELECT fcpo_countryid FROM fcpopayment2country WHERE fcpo_paymentid = 'KLR_{$sCampaignId}'";
415+
$sQuery = "SELECT fcpo_countryid FROM fcpopayment2country WHERE fcpo_paymentid = " . $this->_oFcpoDb->quote('KLR_' .$sCampaignId);
416416
$aRows = $this->_oFcpoDb->getAll($sQuery);
417417
foreach ($aRows as $aRow) {
418418
$aCountries[] = $aRow[0];

lib/fcpohelper.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,4 +686,14 @@ public function fcpoUpdateRefNr($sRefNr, $blIncludesPrefix = true)
686686
return -1;
687687
}
688688
}
689+
690+
/**
691+
* @return \Doctrine\DBAL\Connection
692+
*/
693+
public function fcpoGetPdoDb()
694+
{
695+
$oContainer = \OxidEsales\EshopCommunity\Internal\Container\ContainerFactory::getInstance()->getContainer();
696+
697+
return $oContainer->get('fcpayone.db_connection');
698+
}
689699
}

lib/fcporequest.php

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -964,8 +964,16 @@ public function addProductInfo($oOrder, $aPositions = false, $blDebit = false)
964964
}
965965
}
966966

967-
$sQuery = "SELECT IF(SUM(fcpocapturedamount) = 0, 1, 0) AS b FROM oxorderarticles WHERE oxorderid = '{$oOrder->getId()}' GROUP BY oxorderid";
968-
$blFirstCapture = (bool) oxDb::getDb()->GetOne($sQuery);
967+
$oDb = $this->_oFcpoHelper->fcpoGetPdoDb();
968+
$sQuery = "
969+
SELECT IF(SUM(fcpocapturedamount) = 0, 1, 0) AS b
970+
FROM oxorderarticles
971+
WHERE oxorderid = :sOxid
972+
GROUP BY oxorderid
973+
";
974+
$blFirstCapture = (bool) $oDb->fetchOne($sQuery, [
975+
'sOxid' => $oOrder->getId()
976+
]);
969977

970978
if ($aPositions === false || $blFirstCapture === true || $blDebit === true) {
971979
$oLang = $this->_oFcpoHelper->fcpoGetLang();
@@ -2803,8 +2811,8 @@ protected function _getCurlCliResponse($aUrlArray, $sCurlPath)
28032811
{
28042812
$aResponse = array();
28052813

2806-
$sPostUrl = $aUrlArray['scheme'] . "://" . $aUrlArray['host'] . $aUrlArray['path'];
2807-
$sPostData = $aUrlArray['query'];
2814+
$sPostUrl = escapeshellarg($aUrlArray['scheme'] . "://" . $aUrlArray['host'] . $aUrlArray['path']);
2815+
$sPostData = escapeshellarg($aUrlArray['query']);
28082816

28092817
$sCommand = $sCurlPath . " -m 45 -k -d \"" . $sPostData . "\" " . $sPostUrl;
28102818
$iSysOut = -1;
@@ -2958,29 +2966,30 @@ protected function _logRequest($sResponse, $sStatus = '')
29582966
$sQuery = " INSERT INTO fcporequestlog (
29592967
FCPO_REFNR, FCPO_REQUESTTYPE, FCPO_RESPONSESTATUS, FCPO_REQUEST, FCPO_RESPONSE, FCPO_PORTALID, FCPO_AID
29602968
) VALUES (
2961-
'{$this->getParameter('reference')}',
2962-
'{$this->getParameter('request')}',
2963-
'{$sStatus}',
2969+
" . $oDb->quote($this->getParameter('reference')) . ",
2970+
" . $oDb->quote($this->getParameter('request')) . ",
2971+
" . $oDb->quote($sStatus) . ",
29642972
" . $oDb->quote($sRequest) . ",
29652973
" . $oDb->quote($sResponse) . ",
2966-
'{$oConfig->getConfigParam('sFCPOPortalID')}',
2967-
'{$oConfig->getConfigParam('sFCPOSubAccountID')}'
2974+
" . $oDb->quote($oConfig->getConfigParam('sFCPOPortalID')) . ",
2975+
" . $oDb->quote($oConfig->getConfigParam('sFCPOSubAccountID')) . "
29682976
)";
29692977
$oDb->Execute($sQuery);
29702978
}
29712979

29722980
protected function _getPayoneUserIdByCustNr($sCustNr)
29732981
{
2982+
$oDb = oxDb::getDb();
29742983
$sQuery = " SELECT
29752984
fcpo_userid
29762985
FROM
29772986
fcpotransactionstatus
29782987
WHERE
2979-
fcpo_customerid = '{$sCustNr}'
2988+
fcpo_customerid = " . $oDb->quote($sCustNr) . "
29802989
ORDER BY
29812990
oxtimestamp DESC
29822991
LIMIT 1";
2983-
$sPayOneUserId = oxDb::getDb()->GetOne($sQuery);
2992+
$sPayOneUserId = $oDb->GetOne($sQuery);
29842993
return $sPayOneUserId;
29852994
}
29862995

@@ -3191,7 +3200,7 @@ public function getRefNr($oOrder = false, $blAddPrefixToSession = false)
31913200
$sQuery = "SELECT MAX(fcpo_refnr) FROM fcporefnr WHERE fcpo_refprefix = {$sPrefix}";
31923201
$iMaxRefNr = $oDb->GetOne($sQuery);
31933202
$sRefNr = (int) $iMaxRefNr + 1;
3194-
$sQuery = "INSERT INTO fcporefnr (fcpo_refnr, fcpo_txid, fcpo_refprefix) VALUES ('{$sRefNr}', '', {$sPrefix})";
3203+
$sQuery = "INSERT INTO fcporefnr (fcpo_refnr, fcpo_txid, fcpo_refprefix) VALUES (" . $oDb->quote($sRefNr) . ", '', " . $sPrefix . ")";
31953204

31963205
$oDb->Execute($sQuery);
31973206
}

services.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
services:
2+
fcpayone.db_connection:
3+
alias: 'Doctrine\DBAL\Connection'
4+
public: true

0 commit comments

Comments
 (0)