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

PT-2286 #76

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "mondu/shopware6-payment",
"description": "Mondu payment for Shopware 6",
"version": "1.4.2",
"version": "1.4.3",
"type": "shopware-platform-plugin",
"license": "proprietary",
"authors": [
Expand Down
24 changes: 24 additions & 0 deletions src/Components/PluginConfig/Service/ConfigService.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,30 @@ public function setWebhooksSecret(string $secret = '')
return $this->systemConfigService->set('Mond1SW6.customConfig.webhooksSecret', $secret, $this->salesChannelId);
}

/**
* @param bool $requireInvoiceDocumentToShip
*
* @return void
*/
public function setRequireInvoiceDocumentToShip(bool $requireInvoiceDocumentToShip): void
{
$this->systemConfigService->set(
'Mond1SW6.customConfig.webhooksSecret',
$requireInvoiceDocumentToShip,
$this->salesChannelId
);
}

/**
* @return bool
*/
public function isRequireInvoiceDocumentToShipEnabled(): bool
{
$config = $this->getPluginConfiguration();

return isset($config['requireInvoiceDocumentToShip']) && $config['requireInvoiceDocumentToShip'];
}

/**
* @param bool $val
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ private function shipOrder(OrderEntity $order, Context $context, OrderDataEntity
return;
}

if ($this->configService->skipOrderStateValidation()) {
if (
$this->configService->skipOrderStateValidation() &&
!$this->configService->isRequireInvoiceDocumentToShipEnabled()
) {
return;
}

Expand Down
10 changes: 10 additions & 0 deletions src/Resources/config/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
<defaultValue>1</defaultValue>
</input-field>

<input-field type="bool">
<name>requireInvoiceDocumentToShip</name>
<label>Require SWR invoice document to ship</label>
<label lang="de-DE">Für den Versand ist ein SWR-Rechnungsdokument erforderlich</label>
<label lang="nl-NL">Vereist SWR-factuurdocument voor verzending</label>
<label lang="fr-FR">Exiger le document de facture SWR pour l'expédition</label>
<value>0</value>
<defaultValue>0</defaultValue>
</input-field>

<input-field type="password">
<name>apiToken</name>
<label>API Key</label>
Expand Down
11 changes: 9 additions & 2 deletions src/Services/InvoiceServices/InvoiceDataService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

namespace Mondu\MonduPayment\Services\InvoiceServices;

use Mondu\MonduPayment\Components\PluginConfig\Service\ConfigService;
use Shopware\Core\Checkout\Order\OrderEntity;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\Plugin\Exception\DecorationPatternException;

class InvoiceDataService extends AbstractInvoiceDataService
{
public function __construct(
private readonly ConfigService $configService
) {}

public function getDecorated(): AbstractInvoiceDataService
{
throw new DecorationPatternException(self::class);
Expand All @@ -17,10 +22,12 @@ public function getInvoiceData(OrderEntity $order, Context $context): array
{
[ $invoiceNumber, $invoiceUrl ] = $this->getInvoiceNumberAndUrl($order, $context);

$isRequireInvoiceDocumentToShipEnabled = $this->configService->isRequireInvoiceDocumentToShipEnabled();

return [
'currency' => $this->orderUtilsService->getOrderCurrency($order),
'external_reference_id' => $invoiceNumber,
'invoice_url' => $invoiceUrl,
'external_reference_id' => $isRequireInvoiceDocumentToShipEnabled ? $order->getId() : $invoiceNumber,
'invoice_url' => $isRequireInvoiceDocumentToShipEnabled ? '' : $invoiceUrl,
'gross_amount_cents' => $this->orderUtilsService->priceToCents($order->getPrice()->getTotalPrice()),
'discount_cents' => $this->orderDiscountService->getOrderDiscountCents($order, $context),
'shipping_price_cents' => $this->orderUtilsService->getShippingPriceCents($order),
Expand Down