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

Custom id passed to PayPal as JSON with additional versioning data O7 twig #365

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,5 +469,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 @@ -280,6 +280,9 @@ protected function handleSpecialFields(array $conf): array
$dAmount = (float) 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 @@ -322,6 +322,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
5 changes: 5 additions & 0 deletions src/Service/ModuleSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,11 @@ public function getIsVaultingActive(): bool
return (bool)$this->getSettingValue('oscPayPalSetVaulting');
}

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

/**
* @throws ModuleSettingNotFountException
*/
Expand Down
26 changes: 25 additions & 1 deletion src/Service/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use OxidSolutionCatalysts\PayPal\Exception\PayPalException;
use OxidSolutionCatalysts\PayPal\Exception\UserPhone as UserPhoneException;
use OxidSolutionCatalysts\PayPal\Model\PayPalOrder as PayPalOrderModel;
use OxidSolutionCatalysts\PayPal\Module;
use OxidSolutionCatalysts\PayPal\Service\ModuleSettings as ModuleSettingsService;
use OxidSolutionCatalysts\PayPalApi\Exception\ApiException;
use OxidSolutionCatalysts\PayPalApi\Model\Orders\AuthorizationWithAdditionalData;
Expand Down Expand Up @@ -126,7 +127,7 @@ public function doCreatePayPalOrder(
$basket,
$intent,
$userAction,
$order instanceof EshopModelOrder ? $order->getFieldData('oxordernr') : null,
$this->getCustomIdParameter($order),
$processingInstruction,
$paymentSource,
null,
Expand Down Expand Up @@ -800,4 +801,27 @@ private function displayErrorIfInstrumentDeclined(?string $issue): void
);
}
}

/**
* @param \OxidEsales\Eshop\Application\Model\Order|null $order
* @return mixed|null
*/
public function getCustomIdParameter(?EshopModelOrder $order): string
{
$module = oxNew(\OxidEsales\Eshop\Core\Module\Module::class);
$module->load(Module::MODULE_ID);
$orderNumber = $order instanceof EshopModelOrder ? $order->getFieldData('oxordernr') : null;

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

return json_encode($customID);
}

return $orderNumber;
}
}
3 changes: 3 additions & 0 deletions views/de/admin_translations.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,7 @@
eine höhere Checkout-Conversion bedeuten.',

'OSC_PAYPAL_INSTALLPROCESS_FAILED' => 'Da das Modul nicht korrekt per Composer installiert ist, sind Fehler bei der (De-)Aktivierung des Moduls aufgetreten. Bitte installieren Sie das Modul via Composer frisch und wiederholen den Vorgang.',

'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/en/admin_translations.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,7 @@
mean higher checkout conversion.',

'OSC_PAYPAL_INSTALLPROCESS_FAILED' => 'Because the module was not installed correctly via Composer, errors occurred during the (de)activation of the module. Please reinstall the module via composer and repeat the process.',

'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.',
];
26 changes: 26 additions & 0 deletions views/twig/admin/oscpaypalconfig.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,32 @@
</div>
</div>
</div>

<div class="card">
<div class="card-header" id="heading10">
<h4 class="collapsed" data-toggle="collapse" data-target="#collapse10" aria-expanded="false" aria-controls="collapse10">
{{ translate({ ident: "OSC_PAYPAL_CUSTOM_ID_CONTENTS_TITLE" }) }}
</h4>
</div>

<div id="collapse10" class="collapse" aria-labelledby="heading10" data-parent="#accordion">
<div class="card-body">
<div class="form-group">
<div class="controls">
<div class="controls">
<div class="checkbox">
<label>
<input type="checkbox" name="conf[oscPayPalUseStructuralCustomIdSchema]" {% if config.isCustomIdSchemaStructural() %}checked{% endif %} value="1">
{{ translate({ ident: "OSC_PAYPAL_CUSTOM_ID_CONTENTS_DESC" }) }}
</label>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

</div>
<button type="submit" class="btn btn-primary bottom-space">{{ translate({ ident: "GENERAL_SAVE" }) }}</button>
</form>
Expand Down
Loading