hospitable/avalara-sdk

Interact with Avalara API

0.5.0 2023-11-17 18:38 UTC

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.