Skip to content
This repository has been archived by the owner on Aug 20, 2024. It is now read-only.

budbee/budbee-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

[DEPRECATED] Budbee PHP Wrapper

Warning This project is deprecated and should not be used for integrating with Budbee API.


This repository is a PHP wrapper of the budbee Open API. The API is used to create Order bookings at budbee.

Installation

Add budbee-php to your composer.json file

{
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/budbee/budbee-php"
        }
    ],
    "require": {
        "budbee/api-client": "dev-master"
    }
}

Run php composer.phar install

Code Example

To create an Order a user needs to:

  1. Validate the delivery postalcode
  2. Request an available delivery interval.
  3. Post an Order with an accepted delivery postalcode and an acceptable delivery interval

Setup

Require the wrapper

<?php
  require_once('vendor/autoload.php');

  $apiKey = '<YOUR_API_KEY>';
  $apiSecret = '<YOUR_API_SECRET>';

  $client = new \Budbee\Client($apiKey, $apiSecret, Budbee\Client::$SANDBOX);
  $postalCodesAPI = new \Budbee\PostalcodesApi($client);
  $intervalAPI = new \Budbee\IntervalApi($client);
  $orderAPI = new \Budbee\OrderApi($client);
?>

Validate a postalcode

try {
    $possibleCollectionPoints = $postalCodesAPI->checkPostalCode('SE', '11453');
} catch (\Budbee\Exception\BudbeeException $e) {
    die('Budbee does not deliver to specified Postal Code');
}

Get upcoming delivery intervals

try {
    $intervalResponse = $intervalAPI->getIntervals($deliveryAddress->country, $deliveryAddress->postalCode, 2);
} catch (\Budbee\Exception\BudbeeException $e) {
    die('No upcoming delivery intervals');
}

$firstInterval = $intervalResponse[0];
$interval = new \Budbee\Model\OrderInterval($firstInterval->collection, $firstInterval->delivery);
$collectionPointId = $firstInterval->collectionPointId;

echo 'Budbee can deliver between: ' + $interval->delivery->start + ' and ' + $interval->delivery->stop;

Create an order

// Create Order Object
$order = new \Budbee\Model\OrderRequest();
$order->interval = $interval;
$order->collectionId = $collectionPointId;

// Create Cart Object
$cart = new \Budbee\Model\Cart();
$cart->cartId = '12345';

// Create an Article
$article = new \Budbee\Model\Article();
$article->name = 'T-Shirt';
$article->reference = '61252123';
$article->quantity = 1;
$article->unitPrice = 4900;
$article->discountRate = 0;
$article->taxRate = 2500;

$cart->articles = [$article];

$order->cart = $cart;

// Specify Delivery information
$deliveryContact = new \Budbee\Model\Contact();
$deliveryContact->name = 'John Doe';
$deliveryContact->telephoneNumber = '00 123 45 67';
$deliveryContact->email = '[email protected]';
$deliveryContact->doorCode = '0000';
$deliveryContact->outsideDoor = true;

$deliveryAddress = new \Budbee\Model\Address();
$deliveryAddress->street = 'Grevgatan 9';
$deliveryAddress->postalCode = '11453';
$deliveryAddress->city = 'Stockholm';
$deliveryAddress->country = 'SE';

$deliveryContact->address = $deliveryAddress;

$order->delivery = $deliveryContact;

$createdOrder = $orderAPI->createOrder($order);

echo 'Created Order';

Edit the delivery contact of an order

$order = $orderAPI->createOrder($data);
$deliveryContact = $order->delivery;
$deliveryContact->name = 'Jane Doe';

$updatedOrder = $orderAPI->editDeliveryContact($order->id, $deliveryContact);

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages