Skip to content

Commit 5d3b909

Browse files
authored
Merge pull request #286 from FatchipRobert/OX6-164-PPEV2-UnitTests
OX6-164 - Added UnitTests to PPE V2 integration
2 parents 6cacb02 + e035f09 commit 5d3b909

21 files changed

+691
-80
lines changed

application/controllers/admin/fcpayone_main.php

+9
Original file line numberDiff line numberDiff line change
@@ -1155,4 +1155,13 @@ private function writeFile($filename, $content, $destinationPath)
11551155
}
11561156
}
11571157

1158+
public function isPayPalV2DelAddressActive()
1159+
{
1160+
$aConfBools = $this->fcpoGetConfBools();
1161+
$sConfigOptionName = "blFCPOPayPalV2DelAddress";
1162+
if (!isset($aConfBools[$sConfigOptionName]) || $aConfBools[$sConfigOptionName] === true) {
1163+
return true;
1164+
}
1165+
return false;
1166+
}
11581167
}

application/helper/fcpobasehelper.php

+19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
<?php
22

3+
/**
4+
* PAYONE OXID Connector is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Lesser General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* PAYONE OXID Connector is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public License
15+
* along with PAYONE OXID Connector. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
* @link http://www.payone.de
18+
* @copyright (C) Payone GmbH
19+
* @version OXID eShop CE
20+
*/
21+
322
abstract class fcpobasehelper
423
{
524
/**

application/helper/fcpopaymenthelper.php

+19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
<?php
22

3+
/**
4+
* PAYONE OXID Connector is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Lesser General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* PAYONE OXID Connector is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public License
15+
* along with PAYONE OXID Connector. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
* @link http://www.payone.de
18+
* @copyright (C) Payone GmbH
19+
* @version OXID eShop CE
20+
*/
21+
322
class fcpopaymenthelper extends fcpobasehelper
423
{
524
/**

application/helper/fcpopaypalhelper.php

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
<?php
22

3+
/**
4+
* PAYONE OXID Connector is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Lesser General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* PAYONE OXID Connector is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public License
15+
* along with PAYONE OXID Connector. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
* @link http://www.payone.de
18+
* @copyright (C) Payone GmbH
19+
* @version OXID eShop CE
20+
*/
21+
322
class fcpopaypalhelper extends fcpobasehelper
423
{
524
const PPE_EXPRESS = 'fcpopaypal_express';
@@ -118,7 +137,7 @@ protected function getClientId()
118137
protected function getSupportedLocaleCode($sLocale = null)
119138
{
120139
if (!$sLocale || !in_array($sLocale, $this->aSupportedLocales)) {
121-
return 'en_US';
140+
$sLocale = 'en_US';
122141
}
123142
return $sLocale;
124143
}

application/helper/fcporedirecthelper.php

+28-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
<?php
22

3+
/**
4+
* PAYONE OXID Connector is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Lesser General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* PAYONE OXID Connector is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public License
15+
* along with PAYONE OXID Connector. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
* @link http://www.payone.de
18+
* @copyright (C) Payone GmbH
19+
* @version OXID eShop CE
20+
*/
21+
322
class fcporedirecthelper extends fcpobasehelper
423
{
524
/**
@@ -103,26 +122,23 @@ public function getSuccessUrl($sRefNr = false, $sRedirectFunction = false, $sTok
103122
$sAddParams .= '&refnr=' . $sRefNr;
104123
}
105124

106-
if (!empty($sRedirectFunction)) {
107-
$sAddParams .= '&fnc='.$sRedirectFunction;
108-
} else {
109-
$sAddParams .= '&fnc=execute';
125+
if (empty($sRedirectFunction)) {
126+
$sRedirectFunction = "execute";
110127
}
128+
$sAddParams .= '&fnc='.$sRedirectFunction;
111129

112-
130+
if (empty($sDeliveryMD5) && $this->getMainHelper()->fcpoGetRequestParameter('sDeliveryAddressMD5')) {
131+
$sDeliveryMD5 = $this->getMainHelper()->fcpoGetRequestParameter('sDeliveryAddressMD5');
132+
}
113133
if (!empty($sDeliveryMD5)) {
114-
$sAddParams .= '&sDeliveryAddressMD5=' . $sDeliveryMD5;
115-
} elseif ($this->getMainHelper()->fcpoGetRequestParameter('sDeliveryAddressMD5')) {
116-
$sAddParams .= '&sDeliveryAddressMD5=' . $this->getMainHelper()->fcpoGetRequestParameter('sDeliveryAddressMD5');
134+
$sAddParams .= '&sDeliveryAddressMD5='.$sDeliveryMD5;
117135
}
118136

119-
$blDownloadableProductsAgreement = $this->getMainHelper()->fcpoGetRequestParameter('oxdownloadableproductsagreement');
120-
if ($blDownloadableProductsAgreement) {
137+
if ($this->getMainHelper()->fcpoGetRequestParameter('oxdownloadableproductsagreement')) {
121138
$sAddParams .= '&fcdpa=1'; // rewrite for oxdownloadableproductsagreement-param because of length-restriction
122139
}
123140

124-
$blServiceProductsAgreement = $this->getMainHelper()->fcpoGetRequestParameter('oxserviceproductsagreement');
125-
if ($blServiceProductsAgreement) {
141+
if ($this->getMainHelper()->fcpoGetRequestParameter('oxserviceproductsagreement')) {
126142
$sAddParams .= '&fcspa=1'; // rewrite for oxserviceproductsagreement-param because of length-restriction
127143
}
128144

application/views/admin/de/fcPayOne_lang.php

+2
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,9 @@
270270
'FCPO_EXPORT_CONFIG' => "Konfiguration exportieren",
271271

272272
'FCPO_PAYPAL_DELADDRESS' => 'Rechnungsadresse bei fehlender Lieferadresse als Lieferadresse &uuml;bergeben.',
273+
'FCPO_PAYPALV2_DELADDRESS' => 'Rechnungsadresse bei fehlender Lieferadresse als Lieferadresse &uuml;bergeben.',
273274
'FCPO_HELP_PAYPAL_DELADDRESS' => 'Wird f&uuml;r den PayPal Verk&auml;uferschutz ben&ouml;tigt.',
275+
'FCPO_HELP_PAYPALV2_DELADDRESS' => 'Wird f&uuml;r den PayPal Verk&auml;uferschutz ben&ouml;tigt.',
274276
'FCPO_PAYPAL_LOGOS' => 'Hier k&ouml;nnen Sie die verwendeten PayPal Express Logos hinterlegen.',
275277
'FCPO_PAYPAL_LOGOS_ACTIVE' => 'Aktiv',
276278
'FCPO_PAYPAL_LOGOS_LANG' => 'Sprache',

application/views/admin/en/fcPayOne_lang.php

+2
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,9 @@
335335
'FCPO_EXPORT_CONFIG' => "Export configuration",
336336

337337
'FCPO_PAYPAL_DELADDRESS' => 'Transmit the billing-address as delivery-address if delivery-address is missing.',
338+
'FCPO_PAYPALV2_DELADDRESS' => 'Transmit the billing-address as delivery-address if delivery-address is missing.',
338339
'FCPO_HELP_PAYPAL_DELADDRESS' => 'This is used for the PayPal seller protection.',
340+
'FCPO_HELP_PAYPALV2_DELADDRESS' => 'This is used for the PayPal seller protection.',
339341
'FCPO_PAYPAL_LOGOS' => 'You can upload the PayPal Express logos here.',
340342
'FCPO_PAYPAL_LOGOS_ACTIVE' => 'active',
341343
'FCPO_PAYPAL_LOGOS_LANG' => 'language',

application/views/admin/tpl/fcpayone_main.tpl

+11
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,17 @@
541541
<div class="groupExp">
542542
<div [{if $oView->fcpoIsLogoAdded()}] class="exp"[{/if}]>
543543
<a href="#" onclick="_groupExp(this);return false;" class="rc"><b>[{oxmultilang ident="FCPO_CONFIG_GROUP_PAYPALV2"}]</b></a>
544+
<dl>
545+
<dt>
546+
<input type="hidden" name="confbools[blFCPOPayPalV2DelAddress]" value="false">
547+
<input type="checkbox" name="confbools[blFCPOPayPalV2DelAddress]" value="true" [{if $oView->isPayPalV2DelAddressActive()}]checked[{/if}]>
548+
[{oxinputhelp ident="FCPO_HELP_PAYPALV2_DELADDRESS"}]
549+
</dt>
550+
<dd>
551+
[{oxmultilang ident="FCPO_PAYPALV2_DELADDRESS"}]
552+
</dd>
553+
<div class="spacer"></div>
554+
</dl>
544555
<dl>
545556
<dt>
546557
<input type="hidden" name="confbools[blFCPOPayPalV2BNPL]" value="false">

extend/application/controllers/fcPayOneOrderView.php

+18-12
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,15 @@ protected function _fcpoThrowException($sMessage)
520520
* @param void
521521
* @return void
522522
*/
523-
protected function _handlePayPalExpressCall($sPaymentId) {
523+
protected function _handlePayPalExpressCall($sPaymentId)
524+
{
525+
if ($this->_oFcpoHelper->fcpoGetSessionVariable('blFcpoPayonePayPalExpressRetry') === true && !empty($this->_oFcpoHelper->fcpoGetSessionVariable('blFcpoPayonePayPalSuccessUrl'))) {
526+
$this->_oFcpoHelper->fcpoDeleteSessionVariable('blFcpoPayonePayPalExpressRetry');
527+
$sRedirectUrl = $this->_oFcpoHelper->fcpoGetSessionVariable('blFcpoPayonePayPalSuccessUrl');
528+
$this->_oFcpoHelper->fcpoDeleteSessionVariable('blFcpoPayonePayPalSuccessUrl');
529+
$this->_oFcpoHelper->fcpoGetUtils()->redirect($sRedirectUrl, false);
530+
}
531+
524532
$sWorkorderId = $this->_oFcpoHelper->fcpoGetSessionVariable('fcpoWorkorderId');
525533
if ($sWorkorderId) {
526534
$oRequest = $this->_oFcpoHelper->getFactoryObject('fcporequest');
@@ -704,24 +712,22 @@ protected function _validateTermsAndConditions()
704712

705713
/**
706714
* Splits street and number from concatenated combofield
707-
*
715+
*
708716
* @param string $sPayPalStreet
709717
* @return array
710718
*/
711-
protected function _fcpoSplitAddress($sPayPalStreet)
719+
protected function _fcpoSplitAddress($sStreetAndStreetNr)
712720
{
713-
$sStreetNr = '';
714-
if(preg_match('/\s\d/', $sPayPalStreet, $match)) {
715-
$iEndOfStreetPos = strpos($sPayPalStreet, $match[0]);
716-
$iStartOfStreetNrPos = $iEndOfStreetPos +1; // skip space between street and street nr
717-
$sStreetNr = substr($sPayPalStreet, $iStartOfStreetNrPos);
718-
$sPayPalStreet = substr($sPayPalStreet, 0, $iEndOfStreetPos);
721+
preg_match('/^([^\d]*[^\d\s]) *(\d.*)$/', $sStreetAndStreetNr, $matches);
722+
$sStreet = $sStreetAndStreetNr; // fallback for when splitting doesnt deliver results
723+
$sStreetNr = "";
724+
if (is_array($matches) && count($matches) >= 2) {
725+
$sStreet = $matches[1];
726+
$sStreetNr = $matches[2];
719727
}
720-
721-
return array($sPayPalStreet, $sStreetNr);
728+
return array($sStreet, $sStreetNr);
722729
}
723730

724-
725731
/**
726732
* Searches an existing addressid by extracting response of payone
727733
*

extend/application/models/fcPayOneOrder.php

+26-6
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,6 @@ protected function _fcpoFinalizeOrder($oBasket, $oUser, $blRecalculatingOrder) {
493493
$this->_blFinishingSave = true;
494494
$this->save();
495495

496-
$this->_fcpoSaveAfterRedirect($blSaveAfterRedirect);
497-
498496
// deleting remark info only when order is finished
499497
$this->_oFcpoHelper->fcpoDeleteSessionVariable('ordrem');
500498
$this->_oFcpoHelper->fcpoDeleteSessionVariable('stsprotection');
@@ -526,6 +524,8 @@ protected function _fcpoFinalizeOrder($oBasket, $oUser, $blRecalculatingOrder) {
526524
oxNew(\OxidEsales\Eshop\Core\Counter::class)->update($this->_getCounterIdent(), $this->oxorder__oxordernr->value);
527525
}
528526

527+
$this->_fcpoSaveAfterRedirect($blSaveAfterRedirect);
528+
529529
$this->_oFcpoHelper->fcpoDeleteSessionVariable('fcpoordernotchecked');
530530
$this->_oFcpoHelper->fcpoDeleteSessionVariable('fcpoWorkorderId');
531531

@@ -960,10 +960,10 @@ protected function _fcpoFinishOrder($blRecalculatingOrder, $oUser, $oBasket, $oU
960960
* @param bool $blSaveAfterRedirect
961961
* @return void
962962
*/
963-
protected function _fcpoSaveAfterRedirect($blSaveAfterRedirect)
963+
protected function _fcpoSaveAfterRedirect($blSaveAfterRedirect)
964964
{
965-
if ($blSaveAfterRedirect === true) {
966-
$sQuery = "UPDATE fcpotransactionstatus SET fcpo_ordernr = '{$this->oxorder__oxordernr->value}' WHERE fcpo_txid = '" . $this->_oFcpoHelper->fcpoGetSessionVariable('fcpoTxid') . "'";
965+
if ($blSaveAfterRedirect === true && !empty($this->oxorder__fcpotxid->value)) {
966+
$sQuery = "UPDATE fcpotransactionstatus SET fcpo_ordernr = '{$this->oxorder__oxordernr->value}' WHERE fcpo_txid = '".$this->oxorder__fcpotxid->value."'";
967967
$this->_oFcpoDb->Execute($sQuery);
968968
}
969969
}
@@ -1665,8 +1665,24 @@ public function fcIsPayPalOrder()
16651665
$blReturn = false;
16661666
if (in_array($this->oxorder__oxpaymenttype->value, [
16671667
'fcpopaypal',
1668-
'fcpopaypalv2',
16691668
fcpopaypalhelper::PPE_EXPRESS,
1669+
])) {
1670+
$blReturn = true;
1671+
}
1672+
return $blReturn;
1673+
}
1674+
1675+
/**
1676+
* Method checks via current paymenttype is of payone paypal V2 type
1677+
*
1678+
* @param void
1679+
* @return boolean
1680+
*/
1681+
public function fcIsPayPalV2Order()
1682+
{
1683+
$blReturn = false;
1684+
if (in_array($this->oxorder__oxpaymenttype->value, [
1685+
'fcpopaypalv2',
16701686
fcpopaypalhelper::PPE_V2_EXPRESS,
16711687
])) {
16721688
$blReturn = true;
@@ -1860,6 +1876,10 @@ protected function _fcpoFlagOrderPaymentAsRedirect($blFlaggedAsRedirect = true)
18601876
*/
18611877
protected function _fcpoHandleAuthorizationRedirect($aResponse, $sRefNr, $sAuthorizationType, $sMode, $blReturnRedirectUrl)
18621878
{
1879+
if ($aResponse['status'] == 'REDIRECT' && in_array($this->oxorder__oxpaymenttype->value, [fcpopaypalhelper::PPE_EXPRESS, fcpopaypalhelper::PPE_V2_EXPRESS])) {
1880+
$this->_oFcpoHelper->fcpoSetSessionVariable('blFcpoPayonePayPalExpressRetry', true);
1881+
}
1882+
18631883
$this->_fcpoFlagOrderPaymentAsRedirect();
18641884
$oConfig = $this->_oFcpoHelper->fcpoGetConfig();
18651885
$oUtils = $this->_oFcpoHelper->fcpoGetUtils();

0 commit comments

Comments
 (0)