hospitable / avalara-sdk
Interact with Avalara API
Installs: 11 401
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Forks: 0
pkg:composer/hospitable/avalara-sdk
Requires
- php: ^8.2
- ext-json: *
- illuminate/collections: ^11.0 || ^12.0
- illuminate/support: ^11.0 || ^12.0
- nesbot/carbon: ^3.8.6
- saloonphp/laravel-plugin: ^3.0
- saloonphp/saloon: ^3.0
Requires (Dev)
- laravel/pint: ^1.21
- orchestra/testbench: ^9.0 || ^10.0
- pestphp/pest: ^3.0
- pestphp/pest-plugin-laravel: ^3.0
- rector/rector: ^2.0
README
Installation
composer require hospitable/avalara-sdk
Configuration
config/services.php
return [
    'avalara' => [
        'base_url' => env('AVALARA_SANBOX', true)
            ? 'https://sandbox-rest.avatax.com'
            : 'https://rest.avatax.com',
        'username' => env('AVALARA_USERNAME'),
        'password' => env('AVALARA_PASSWORD'),
    ],
];
.env
AVALARA_SANBOX=true
AVALARA_USERNAME=
AVALARA_PASSWORD=
Usage
$avalara = app(\Hospitable\Avalara\AvalaraConnector::class);
$avalara->transaction()->create(new CreateTransaction(
    companyCode: 'DEFAULT',
    date: CarbonImmutable::parse('2022-10-26'),
    customerCode: 'ABC',
    commit: false,
    currencyCode: 'USD',
    addresses: new Addresses(
        singleLocation: new AddressLocationInfo(
            line1: '5 W 8th St',
            city: 'New York',
            region: 'NY',
            postalCode: '10011',
            country: 'US',
        )
    ),
    lines: LineItemCollection::make([
        new LineItem(
            number: '1',
            quantity: 7,
            amount: 896,
            taxCode: 'SL090200',
            taxIncluded: false,
            description: 'Lodging accommodation',
        ),
        new LineItem(
            number: '2',
            quantity: 1,
            amount: 45,
            taxCode: 'OF090005',
            taxIncluded: false,
            description: 'mandatory cleaning fee',
        ),
    ]),
    parameters: ParameterCollection::make([
        new Parameter(
            name: 'EstablishmentType',
            value: 'ShortTermRental',
        ),
        new Parameter(
            name: 'NumberOfNights',
            value: 7,
            unit: 'Count',
        ),
        new Parameter(
            name: 'NumberOfRoomsInUnit',
            value: 3,
            unit: 'Count',
        ),
        new Parameter(
            name: 'NumberOfUnitsForRent',
            value: 1,
            unit: 'Count',
        ),
        new Parameter(
            name: 'AvgDailyRate',
            value: 128,
        ),
    ]),
));
Testing
Copy phpunit.xml.dist to phpunit.xml and customize the AVALARA_USERNAME and AVALARA_PASSWORD.