PHP code example of bosta / bosta-sdk

1. Go to this page and download the library: Download bosta/bosta-sdk 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/ */

    

bosta / bosta-sdk example snippets

 php
    $stgBaseUrl = 'https://stg-app.bosta.co';
    $prodBaseUrl = 'https://app.bosta.co';
    
    putenv("API_KEY=$your api key");
    putenv("BASE_URL=$your base url");
    
 php
     Bosta\Bosta;
    $bosta = new Bosta(getenv("API_KEY"), getenv("BASE_URL"));
    
 php
    use Bosta\Utils\ContactPerson;

    /**
    * List Pickup Request
    *
    * @param int $pageNumber = 0
    * @return \stdClass
    */
    try {
        $list = $bosta->pickup->list(0);
        echo "list: \n";
        var_dump($list);
        echo "------------------------------------------ \n";
    } catch (Exception $e) {
        echo 'Caught exception: ',  $e->getMessage(), "\n";
    }

    /**
    * Get Pickup Request
    *
    * @param string $pickupRequestId = 070000000386
    * @return \stdClass
    */
    try {
        $get = $bosta->pickup->get('070000000386');
        echo "get: \n";
        var_dump($get);
        echo "------------------------------------------ \n";
    } catch (Exception $e) {
        echo 'Caught exception: ',  $e->getMessage(), "\n";
    }

    /**
    * Delete Pickup Request
    *
    * @param string $pickupRequestId = 070000000386
    * @return string
    */
    try {
        $delete = $bosta->pickup->delete('070000000386');
        echo "delete: \n";
        var_dump($delete);
        echo "------------------------------------------ \n";
    } catch (Exception $e) {
        echo 'Caught exception: ',  $e->getMessage(), "\n";
    }

    /**
    * Create ContactPerson Instance
    *
    * @param string $name = aliaa123
    * @param string $phone = 01209847552
    * @param string $email = [email protected]
    */
    $contactPerson = new ContactPerson("aliaa123", "01209847552", '[email protected]');

    /**
    * Get Pickup Locations to use its id in create pickup Request
    */
    try {
        $listPickupLocations = $bosta->pickupLocation->list();
        echo "listPickupLocations: \n";
        var_dump($listPickupLocations);
        echo "------------------------------------------ \n";
    } catch (Exception $e) {
        echo 'Caught exception: ',  $e->getMessage(), "\n";
    }

    /**
    * Create Pickup Request
    *
    * @param string $scheduledDate = 2020-09-30 (YYYY-MM-DD)
    * @param string $scheduledTimeSlot = 10:00 to 13:00 || 13:00 to 16:00
    * @param \Bosta\Utils\ContactPerson $contactPerson
    * @param string $businessLocationId = SkIvXQn_a
    * @param string $notes = ''
    * @param int $noOfPackages = 0
    * @return \stdClass
    */
    try {
        $create = $bosta->pickup->create('2020-09-30', '10:00 to 13:00', $contactPerson, 'SkIvXQn_a', '', 0);
        echo "create: \n";
        var_dump($create);
        echo "------------------------------------------ \n";
    } catch (Exception $e) {
        echo 'Caught exception: ',  $e->getMessage(), "\n";
    }


    /**
    * Update Pickup Request
    *
    * @param string $pickupRequestId = 070000000386
    * @param string $scheduledDate = 2020-09-29 (YYYY-MM-DD)
    * @param string $scheduledTimeSlot = 10:00 to 13:00 || 13:00 to 16:00
    * @param \Bosta\Utils\ContactPerson $contactPerson
    * @param string $businessLocationId = SkIvXQn_a
    * @param string $notes = ''
    * @param int $noOfPackages = 0
    * @return string
    */
    try {
        $update = $bosta->pickup->update('070000000386', '2020-09-29', '10:00 to 13:00', $contactPerson, 'SkIvXQn_a', '', 0);
        echo "update: \n";
        var_dump($update);
        echo "------------------------------------------ \n";
    } catch (Exception $e) {
        echo 'Caught exception: ',  $e->getMessage(), "\n";
    }