Skip to content

Latest commit

 

History

History
215 lines (159 loc) · 6.73 KB

locations.md

File metadata and controls

215 lines (159 loc) · 6.73 KB

Locations

$locationsApi = $client->getLocationsApi();

Class Name

LocationsApi

Methods

List Locations

Provides details about all of the seller's locations, including those with an inactive status. Locations are listed alphabetically by name.

function listLocations(): ApiResponse

Response Type

This method returns a Square\Utils\ApiResponse instance. The getResult() method on this instance returns the response data which is of type ListLocationsResponse.

Example Usage

$apiResponse = $locationsApi->listLocations();

if ($apiResponse->isSuccess()) {
    $listLocationsResponse = $apiResponse->getResult();
} else {
    $errors = $apiResponse->getErrors();
}

// Getting more response information
var_dump($apiResponse->getStatusCode());
var_dump($apiResponse->getHeaders());

Create Location

Creates a location. Creating new locations allows for separate configuration of receipt layouts, item prices, and sales reports. Developers can use locations to separate sales activity through applications that integrate with Square from sales activity elsewhere in a seller's account. Locations created programmatically with the Locations API last forever and are visible to the seller for their own management. Therefore, ensure that each location has a sensible and unique name.

function createLocation(CreateLocationRequest $body): ApiResponse

Parameters

Parameter Type Tags Description
body CreateLocationRequest Body, Required An object containing the fields to POST for the request.

See the corresponding object definition for field details.

Response Type

This method returns a Square\Utils\ApiResponse instance. The getResult() method on this instance returns the response data which is of type CreateLocationResponse.

Example Usage

$body = CreateLocationRequestBuilder::init()
    ->location(
        LocationBuilder::init()
            ->name('Midtown')
            ->address(
                AddressBuilder::init()
                    ->addressLine1('1234 Peachtree St. NE')
                    ->locality('Atlanta')
                    ->administrativeDistrictLevel1('GA')
                    ->postalCode('30309')
                    ->build()
            )
            ->description('Midtown Atlanta store')
            ->build()
    )
    ->build();

$apiResponse = $locationsApi->createLocation($body);

if ($apiResponse->isSuccess()) {
    $createLocationResponse = $apiResponse->getResult();
} else {
    $errors = $apiResponse->getErrors();
}

// Getting more response information
var_dump($apiResponse->getStatusCode());
var_dump($apiResponse->getHeaders());

Retrieve Location

Retrieves details of a single location. Specify "main" as the location ID to retrieve details of the main location.

function retrieveLocation(string $locationId): ApiResponse

Parameters

Parameter Type Tags Description
locationId string Template, Required The ID of the location to retrieve. Specify the string
"main" to return the main location.

Response Type

This method returns a Square\Utils\ApiResponse instance. The getResult() method on this instance returns the response data which is of type RetrieveLocationResponse.

Example Usage

$locationId = 'location_id4';

$apiResponse = $locationsApi->retrieveLocation($locationId);

if ($apiResponse->isSuccess()) {
    $retrieveLocationResponse = $apiResponse->getResult();
} else {
    $errors = $apiResponse->getErrors();
}

// Getting more response information
var_dump($apiResponse->getStatusCode());
var_dump($apiResponse->getHeaders());

Update Location

Updates a location.

function updateLocation(string $locationId, UpdateLocationRequest $body): ApiResponse

Parameters

Parameter Type Tags Description
locationId string Template, Required The ID of the location to update.
body UpdateLocationRequest Body, Required An object containing the fields to POST for the request.

See the corresponding object definition for field details.

Response Type

This method returns a Square\Utils\ApiResponse instance. The getResult() method on this instance returns the response data which is of type UpdateLocationResponse.

Example Usage

$locationId = 'location_id4';

$body = UpdateLocationRequestBuilder::init()
    ->location(
        LocationBuilder::init()
            ->businessHours(
                BusinessHoursBuilder::init()
                    ->periods(
                        [
                            BusinessHoursPeriodBuilder::init()
                                ->dayOfWeek(DayOfWeek::FRI)
                                ->startLocalTime('07:00')
                                ->endLocalTime('18:00')
                                ->build(),
                            BusinessHoursPeriodBuilder::init()
                                ->dayOfWeek(DayOfWeek::SAT)
                                ->startLocalTime('07:00')
                                ->endLocalTime('18:00')
                                ->build(),
                            BusinessHoursPeriodBuilder::init()
                                ->dayOfWeek(DayOfWeek::SUN)
                                ->startLocalTime('09:00')
                                ->endLocalTime('15:00')
                                ->build()
                        ]
                    )
                    ->build()
            )
            ->description('Midtown Atlanta store - Open weekends')
            ->build()
    )
    ->build();

$apiResponse = $locationsApi->updateLocation(
    $locationId,
    $body
);

if ($apiResponse->isSuccess()) {
    $updateLocationResponse = $apiResponse->getResult();
} else {
    $errors = $apiResponse->getErrors();
}

// Getting more response information
var_dump($apiResponse->getStatusCode());
var_dump($apiResponse->getHeaders());