Code Monkey home page Code Monkey logo

bubb-correios's Introduction

bubb-correios

Com esta biblioteca você consegue calcular valores/prazos e rastrear objetos diretamente do webservice dos Correios.

Instalação via composer

Composer Setup

Adicione em seu composer.json

{
    "require": {
        "bubb/bubb-correios": "dev-master"
    }
}

Usage

Cotação
use BUBB\Correios\CorreiosQuote;
use BUBB\Correios\Exceptions\CorreiosQuoteException;

try
{
    $quotes = new CorreiosQuote();

    $quotes->setOriginZipcode('14940-000');
    $quotes->setDestinyZipcode('14900-000');
    $quotes->setWeight(2);
    $quotes->setWidth(15);
    $quotes->setHeight(10);
    $quotes->setLength(16);
    $quotes->setServicesCodes(['4014', '4510']);
    $quotes->setFormat('caixa');

    // Métodos opcionais
    $quotes->setCompanyCode('00000000'); // Código da empresa
    $quotes->setPassword('00000000'); // Senha webserivce
    $quotes->setDiameter(0);
    $quotes->setMaoPropria(true);
    $quotes->setValorDeclarado(12.0);

    echo '<pre>' . json_encode($quotes->get(), true) . '</pre>';

} catch ( CorreiosQuoteException $e )
{
    echo $e->getMessage();
}

Output:

[
    {
        "price": 29.2,
        "delivery_days": 2,
        "estimate_delivery_date": "2017-08-15",
        "code": 4014,
        "weight": 2,
        "service": {
            "name": "sedex",
            "optional_name": "Sedex"
        }
    },
    {
        "price": 25.8,
        "delivery_days": 5,
        "estimate_delivery_date": "2017-08-18",
        "code": 4510,
        "weight": 2,
        "service": {
            "name": "pac",
            "optional_name": "PAC"
        }
    }
]
Rastrear objetos
use BUBB\Correios\CorreiosTracking;
use BUBB\Correios\Exceptions\CorreiosTrackingException;

try
{
    $tracking = new CorreiosTracking('PO548836895BR');
    echo '<pre>' . json_encode($tracking->get(), true) . '</pre>';

} catch ( CorreiosTrackingException $e )
{
    echo $e->getMessage();
}

Output:

{
    "code": "PO548836895BR",
    "last_timestamp": 1502126880,
    "last_status": "Em trânsito para CTCE RIBEIRAO PRETO - RIBEIRAO PRETO/SP",
    "last_date": "2017-08-07 14:28",
    "last_locale": null,
    "delivered": false,
    "delivered_at": null,
    "tracking": [
        {
            "timestamp": 1502126880,
            "date": "2017-08-07 14:28",
            "place": "CTE VILA MARIA - SAO PAULO/SP Objeto encaminhado",
            "status": "Em trânsito para CTCE RIBEIRAO PRETO - RIBEIRAO PRETO/SP",
            "forwarded": null,
            "delivered": false
        },
        {
            "timestamp": 1502109900,
            "date": "2017-08-07 09:45",
            "place": "AGF JARDIM MARILIA - SAO PAULO/SP Objeto encaminhado",
            "status": "Em trânsito para CTE VILA MARIA - SAO PAULO/SP",
            "forwarded": null,
            "delivered": false
        },
        {
            "timestamp": 1501868640,
            "date": "2017-08-04 14:44",
            "place": "AGF JARDIM MARILIA - SAO PAULO/SP",
            "status": "Objeto postado",
            "forwarded": null,
            "delivered": false
        }
    ]
}

bubb-correios's People

Contributors

lucascolette avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.