PHP code example of victorycodedev / shipday

1. Go to this page and download the library: Download victorycodedev/shipday library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

victorycodedev / shipday example snippets


use Victorycodedev\Shipday\Shipday;
use Victorycodedev\Shipday\Enums\OrderStatus;

$shipday = Shipday::make('your-shipday-api-key');

$order = $shipday->orders()->create([
    'orderNumber' => 'A-1001',
    'customerName' => 'Ada Lovelace',
    'customerAddress' => '556 Crestlake Dr, San Francisco, CA 94132, USA',
    'customerPhoneNumber' => '+14152392212',
    'restaurantName' => 'Popeyes Louisiana Kitchen',
    'restaurantAddress' => '890 Geneva Ave, San Francisco, CA 94112, United States',
]);

$shipday = Shipday::make(
    apiKey: 'your-shipday-api-key',
    xApiKey: 'your-x-api-key',
);

$shipday = Shipday::make('your-shipday-api-key');

$shipday->orders()->active();
$shipday->orders()->find('ORDER_NUMBER');
$shipday->orders()->create([...]);
$shipday->orders()->update($orderId, [...]);
$shipday->orders()->delete($orderId);
$shipday->orders()->query([...]);
$shipday->orders()->assignDriver($orderId, $carrierId);
$shipday->orders()->unassignDriver($orderId);
$shipday->orders()->readyToPickup($orderId); // sends ["readyToPickup" => true]
$shipday->orders()->updateStatus($orderId, OrderStatus::Started);
// Raw strings are also accepted for forward compatibility:
$shipday->orders()->updateStatus($orderId, 'STARTED');

$shipday->pickupOrders()->create([...]);
$shipday->pickupOrders()->find($orderId);
$shipday->pickupOrders()->update($orderId, [...]);
$shipday->pickupOrders()->delete($orderId);

$shipday->carriers()->all();

$shipday->carriers()->create([
    'name' => 'Jane Driver',
    'email' => '[email protected]',
    'phoneNumber' => '+11234567890',
]);

$shipday->carriers()->delete($carrierId);

$shipday->tracking()->progress(
    trackingId: 'tracking-id',
    

$shipday->onDemand()->services();
$shipday->onDemand()->estimate($orderId);

$shipday->onDemand()->assign([
    'name' => 'DoorDash',
    'orderId' => $orderId,
    'tip' => 6.50,
    'estimateReference' => 'estimate-reference',
    'contactlessDelivery' => false,
    'podType' => 'PHOTO',
]);

$shipday->onDemand()->details($orderId);
$shipday->onDemand()->cancel($orderId);

$shipday->onDemand()->availability([
    'pickupAddress' => '1 Wall St, New York, NY 10005, USA',
    'deliveryAddress' => '1000 5th Ave, New York, NY 10028, USA',
]);

use Victorycodedev\Shipday\PartnerShipday;
use Victorycodedev\Shipday\Enums\PartnerOrderStatus;

$partner = PartnerShipday::make('your-partner-api-key');

$partner->orders()->query([
    'companyId' => '1234',
    'orderStatus' => PartnerOrderStatus::Active,
    'startCursor' => 1,
    'endCursor' => 25,
]);
$partner->orders()->completed($companyId);
$partner->members()->details();

use Victorycodedev\Shipday\Exceptions\ShipdayException;

try {
    $shipday->orders()->active();
} catch (ShipdayException $exception) {
    $exception->statusCode();
    $exception->response();
    $exception->headers();
    $exception->errorId();
    $exception->errorName();
    $exception->details();
    $exception->retryAfter();
}

use Victorycodedev\Shipday\Enums\OrderStatus;

$shipday->orders()->updateStatus($orderId, OrderStatus::Started);

OrderStatus::Started;
OrderStatus::PickedUp;
OrderStatus::ReadyToDeliver;
OrderStatus::AlreadyDelivered;
OrderStatus::Incomplete;
OrderStatus::FailedDelivery;

use Victorycodedev\Shipday\Enums\PartnerOrderStatus;

$partner->orders()->query([
    'companyId' => '1234',
    'orderStatus' => PartnerOrderStatus::Active,
]);

PartnerOrderStatus::Active;
PartnerOrderStatus::NotAssigned;
PartnerOrderStatus::NotAccepted;
PartnerOrderStatus::NotStartedYet;
PartnerOrderStatus::Started;
PartnerOrderStatus::PickedUp;
PartnerOrderStatus::ReadyToDeliver;
PartnerOrderStatus::AlreadyDelivered;
PartnerOrderStatus::FailedDelivery;
PartnerOrderStatus::Incomplete;

$event->event();
$event->eventType();

WebhookEventType::OrderAssigned;
WebhookEventType::OrderAcceptedAndStarted;
WebhookEventType::OrderOnTheWay;
WebhookEventType::OrderCompleted;
WebhookEventType::OrderFailed;
WebhookEventType::OrderIncomplete;
WebhookEventType::OrderDeleted;
WebhookEventType::OrderInserted;
WebhookEventType::OrderPickedUp;
WebhookEventType::OrderUnassigned;
WebhookEventType::OrderPickedUpRemoved;
WebhookEventType::OrderOnTheWayRemoved;
WebhookEventType::OrderPodUpload;
WebhookEventType::LocationUpdate;

$event->status();
$event->statusType();

WebhookOrderStatus::NotAssigned;
WebhookOrderStatus::NotAccepted;
WebhookOrderStatus::NotStartedYet;
WebhookOrderStatus::Started;
WebhookOrderStatus::PickedUp;
WebhookOrderStatus::ReadyToDeliver;
WebhookOrderStatus::AlreadyDelivered;
WebhookOrderStatus::Incomplete;
WebhookOrderStatus::FailedDelivery;

use Illuminate\Http\Request;
use Victorycodedev\Shipday\Enums\WebhookEventType;
use Victorycodedev\Shipday\Enums\WebhookOrderStatus;
use Victorycodedev\Shipday\Webhooks\DriverLocationUpdated;
use Victorycodedev\Shipday\Webhooks\OrderStatusUpdated;
use Victorycodedev\Shipday\Webhooks\ShipdayWebhook;

Route::post('/webhooks/shipday', function (Request $request) {
    $event = ShipdayWebhook::fromRequest(
        payload: $request->getContent(),
        headers: $request->headers->all(),
        token: config('services.shipday.webhook_token'),
    );

    if ($event instanceof OrderStatusUpdated) {
        $event->event();
        $event->eventType(); // WebhookEventType::OrderCompleted
        $event->status();
        $event->statusType(); // WebhookOrderStatus::AlreadyDelivered
        $event->orderId();
        $event->orderNumber();
        $event->order();
        $event->carrier();
    }

    if ($event instanceof DriverLocationUpdated) {
        $event->orderId();
        $event->companyId();
        $event->latitude();
        $event->longitude();
        $event->timestamp();
    }

    return response()->json(['received' => true]);
});

use Victorycodedev\Shipday\Webhooks\ShipdayWebhook;

$event = ShipdayWebhook::fromGlobals(
    token: $_ENV['SHIPDAY_WEBHOOK_TOKEN'] ?? null,
);

http_response_code(200);

$shipday = Shipday::make('your-shipday-api-key');

// v1
$delivery->insertOrder($payload);

// resource API
$shipday->orders()->create($payload);