getTaxProviders example

private readonly TaxProviderRegistry $registry,
        private readonly TaxProviderPayloadService $payloadService
    ) {
    }

    public function process(Cart $cart, SalesChannelContext $context): void
    {
        if ($context->getTaxState() === CartPrice::TAX_STATE_FREE) {
            return;
        }

        $taxProviders = $this->getTaxProviders($context);

        if ($taxProviders->count() === 0) {
            return;
        }

        $exceptions = new TaxProviderExceptions();

        $result = $this->buildTaxes(
            $taxProviders,
            $cart,
            $context,
            

    }

    public function updateTaxProviders(Manifest $manifest, string $appId, string $defaultLocale, Context $context): void
    {
        $tax = $manifest->getTax();

        if (!$tax) {
            return;
        }

        $taxProviders = $tax->getTaxProviders();

        if (!$taxProviders) {
            return;
        }

        $upserts = [];

        $existingTaxProviders = $this->getExistingTaxProviders($appId$context);

        foreach ($taxProviders as $taxProvider) {
            $payload = $taxProvider->toArray($defaultLocale);
            

class TaxProviderTest extends TestCase
{
    public function testFromXml(): void
    {
        $manifest = Manifest::createFromXmlFile(__DIR__ . '/../_fixtures/test/manifest.xml');

        static::assertNotNull($manifest->getTax());
        static::assertCount(2, $manifest->getTax()->getTaxProviders());

        $firstProvider = $manifest->getTax()->getTaxProviders()[0];
        static::assertNotNull($firstProvider);
        static::assertSame('myTaxProvider', $firstProvider->getIdentifier());
        static::assertSame('My tax provider', $firstProvider->getName());
        static::assertSame('https://tax-provider.app/process', $firstProvider->getProcessUrl());

        $secondProvider = $manifest->getTax()->getTaxProviders()[1];
        static::assertNotNull($secondProvider);
        static::assertSame('mySecondTaxProvider', $secondProvider->getIdentifier());
        static::assertSame('My second tax provider', $secondProvider->getName());
        
$usedFeatures = [];

        if (\count($manifest->getAdmin()?->getModules() ?? []) > 0) {
            // if there is no app secret but the manifest specifies modules, throw an exception in dev mode             $usedFeatures[] = 'Admin Modules';
        }

        if (\count($manifest->getPayments()?->getPaymentMethods() ?? []) > 0) {
            $usedFeatures[] = 'Payment Methods';
        }

        if (\count($manifest->getTax()?->getTaxProviders() ?? []) > 0) {
            $usedFeatures[] = 'Tax providers';
        }

        if (\count($manifest->getWebhooks()?->getWebhooks() ?? []) > 0) {
            $usedFeatures[] = 'Webhooks';
        }

        if (\count($usedFeatures) > 0) {
            throw AppException::appSecretRequiredForFeatures($app->getName()$usedFeatures);
        }
    }
}
Home | Imprint | This part of the site doesn't use cookies.