commerceguys / tax

A PHP 5.5+ tax library.
MIT License
276 stars 39 forks source link

Basic Usage #77

Closed FractalMind closed 3 months ago

FractalMind commented 4 years ago

What am I doing wrong?

            $taxTypeRepository = new TaxTypeRepository();
            $chainTaxTypeResolver = new ChainTaxTypeResolver();
            $chainTaxTypeResolver->addResolver(new CanadaTaxTypeResolver($taxTypeRepository));
            $chainTaxTypeResolver->addResolver(new EuTaxTypeResolver($taxTypeRepository));
            $chainTaxTypeResolver->addResolver(new DefaultTaxTypeResolver($taxTypeRepository));
            $chainTaxRateResolver = new ChainTaxRateResolver();
            $chainTaxRateResolver->addResolver(new DefaultTaxRateResolver());
            $resolver = new TaxResolver($chainTaxTypeResolver, $chainTaxRateResolver);

            $from = new Address();
            $from->countryCode          = 'CA';
            $from->administrativeArea   = 'Quebec';
            $from->locality             = 'Montreal';
            $from->dependentLocality;
            $from->postalCode           = 'H2G1A7';
            $from->sortingCode;
            $from->addressLine1         = '1452 Rue Bélanger, Montréal, QC H2G 1A7';
            $from->addressLine2;
            $from->organization;
            $from->givenName            = 'Espace Plomberium';
            $from->additionalName;
            $from->familyName;
            $from->locale;

            $to = new Address();
            $to->countryCode          = 'CA';
            $to->administrativeArea   = 'British Columbia';
            $to->locality             = 'Vancouver';
            $to->dependentLocality;
            $to->postalCode           = 'V5P3W7';
            $to->sortingCode;
            $to->addressLine1         = '5786 Victoria Dr, Vancouver, BC, V5P3W7';
            $to->addressLine2;
            $to->organization;
            $to->givenName            = 'LifeLabs Medical Laboratory Services';
            $to->additionalName;
            $to->familyName;
            $to->locale;

            $taxable = new Taxable();
            $taxable->isPhysical = true;

            $context = new Context($from, $to);

            $amounts = $resolver->resolveAmounts($taxable, $context);
            // More rarely, if only the types or rates are needed:
            $rates = $resolver->resolveRates($taxable, $context);
            $types = $resolver->resolveTypes($taxable, $context);

            var_dump($amounts); // outputs: [] 
            var_dump($rates);       // outputs: [] 
            var_dump($types);      // outputs: [] 

[$amounts, $rates, $types] return empty arrays!?

Did I miss something?

Thank you for your time :smile:

FractalMind commented 4 years ago
            $from = new \CommerceGuys\Addressing\Address();
            $from->withCountryCode('CA');
            $from->withAdditionalName('Quebec');
            $from->withLocality('Montreal');
            $from->withPostalCode('H2G1A7');
            $from->withAddressLine1('1452 Rue Bélanger, Montréal, QC H2G 1A7');
            $from->withOrganization('Espace Plomberium');

This gives me the same result with the class you provide.

faustbrian commented 3 years ago

@FractalMind probably too late to be of any help but Address is immutable so you'll have to either reassign the $from and $to variables after setting a value or use method chaining.