Skip to content

Commit

Permalink
CustomId field backward compatibility support
Browse files Browse the repository at this point in the history
- added configuration for simple and structural custom id value
  • Loading branch information
Bartosz Sosnowski committed Dec 6, 2024
1 parent 83cdb35 commit 6ce8760
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 8 deletions.
6 changes: 6 additions & 0 deletions metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -570,5 +570,11 @@
'value' => 3.5,
'group' => null
],
[
'name' => 'oscPayPalUseStructuralCustomIdSchema',
'type' => 'bool',
'value' => false,
'group' => null
],
],
];
3 changes: 3 additions & 0 deletions src/Controller/Admin/PayPalConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ protected function handleSpecialFields(array $conf): array
$dAmount = (string) str_replace(',', '.', $conf['oscPayPalDefaultShippingPriceExpress']);
$conf['oscPayPalDefaultShippingPriceExpress'] = $dAmount;
}
if (!isset($conf['oscPayPalUseStructuralCustomIdSchema'])) {
$conf['oscPayPalUseStructuralCustomIdSchema'] = false;
}
return $conf;
}

Expand Down
5 changes: 5 additions & 0 deletions src/Core/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,11 @@ public function getStartTimeCleanUpOrders(): int
return $this->getServiceFromContainer(ModuleSettings::class)->getStartTimeCleanUpOrders();
}

public function isCustomIdSchemaStructural(): bool
{
return $this->getServiceFromContainer(ModuleSettings::class)->isCustomIdSchemaStructural();
}

public function tableExists(string $tableName = ''): bool
{
$exists = false;
Expand Down
6 changes: 6 additions & 0 deletions src/Service/ModuleSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -624,11 +624,17 @@ public function getIsVaultingActive(): bool
{
return (bool)$this->getSettingValue('oscPayPalSetVaulting');
}

public function getIsGooglePayDeliveryAddressActive(): bool
{
return (bool)$this->getSettingValue('oscPayPalUseGooglePayAddress');
}

public function isCustomIdSchemaStructural(): bool
{
return (bool)$this->getSettingValue('oscPayPalUseStructuralCustomIdSchema');
}

/**
* @return mixed
*/
Expand Down
24 changes: 16 additions & 8 deletions src/Service/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public function doCapturePayPalOrder(
$this->doPatchPayPalOrder(
Registry::getSession()->getBasket(),
$checkoutOrderId,
$this->getCustomIdParameterJSON($order)
$this->getCustomIdParameter($order)
);

/** @var $result ApiOrderModel */
Expand Down Expand Up @@ -812,16 +812,24 @@ private function displayErrorIfInstrumentDeclined(?string $issue): void
* @param \OxidEsales\Eshop\Application\Model\Order|null $order
* @return mixed|null
*/
public function getCustomIdParameterJSON(?EshopModelOrder $order)
public function getCustomIdParameter(?EshopModelOrder $order): string
{
/** @var ModuleSettingsService $moduleSettings */
$moduleSettings = $this->getServiceFromContainer(ModuleSettings::class);
$module = oxNew(\OxidEsales\Eshop\Core\Module\Module::class);
$module->load(Module::MODULE_ID);
$customID = [
'oxordernr' => $order instanceof EshopModelOrder ? $order->getFieldData('oxordernr') : null,
'moduleVersion' => $module->getInfo('version'),
'oxidVersion' => \OxidEsales\Eshop\Core\ShopVersion::getVersion()
];
$orderNumber = $order instanceof EshopModelOrder ? $order->getFieldData('oxordernr') : null;

if($moduleSettings->isCustomIdSchemaStructural()){
$customID = [
'oxordernr' => $orderNumber,
'moduleVersion' => $module->getInfo('version'),
'oxidVersion' => \OxidEsales\Eshop\Core\ShopVersion::getVersion()
];

return json_encode($customID);
}

return json_encode($customID);
return $orderNumber;
}
}
3 changes: 3 additions & 0 deletions views/admin/de/admin_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,7 @@

// PayPal Payment
'OSC_PAYPAL_PAYMENT_DEPRECATED' => 'Diese PayPal Zahlungsart kann nicht mehr aktiviert werden, da diese demnächst entfernt wird!',

'OSC_PAYPAL_CUSTOM_ID_CONTENTS_TITLE' => 'PayPal Inhalte des benutzerdefinierten ID-Feldes',
'OSC_PAYPAL_CUSTOM_ID_CONTENTS_DESC' => 'Das benutzerdefinierte PayPal-ID-Feld kann entweder nur den Bestellnummernwert oder ein JSON mit zusätzlichen Daten enthalten.',
];
3 changes: 3 additions & 0 deletions views/admin/en/admin_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,4 +290,7 @@

// PayPal Payment
'OSC_PAYPAL_PAYMENT_DEPRECATED' => 'This PayPal payment method can no longer be activated as it will be removed soon!',

'OSC_PAYPAL_CUSTOM_ID_CONTENTS_TITLE' => 'PayPal custom id field contents',
'OSC_PAYPAL_CUSTOM_ID_CONTENTS_DESC' => 'PayPal custom id field will be JSON encoded string with order number, shop version and the PayPal module version.',
];
22 changes: 22 additions & 0 deletions views/admin/tpl/oscpaypalconfig.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,28 @@
</div>
</div>
</div>

<div class="card">
<div class="card-header" id="heading11">
<h4 class="collapsed" data-toggle="collapse" data-target="#collapse11" aria-expanded="false" aria-controls="collapse11">
[{oxmultilang ident="OSC_PAYPAL_CUSTOM_ID_CONTENTS_TITLE"}]
</h4>
</div>
<div id="collapse11" class="collapse" aria-labelledby="heading11" data-parent="#accordion">
<div class="card-body">
<div class="form-group">
<div class="controls">
<div class="form-group">
<div class="controls">
<input type="checkbox" name="conf[oscPayPalUseStructuralCustomIdSchema]" value="1" [{if $config->isCustomIdSchemaStructural()}] checked[{/if}]>
<span class="help-block">[{oxmultilang ident="OSC_PAYPAL_CUSTOM_ID_CONTENTS_DESC"}]</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
[{*
<div class="card">
<div class="card-header" id="heading9">
Expand Down

0 comments on commit 6ce8760

Please sign in to comment.