PHP code example of diprotec-dev / sdk-frete-rapido-php

1. Go to this page and download the library: Download diprotec-dev/sdk-frete-rapido-php 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/ */

    

diprotec-dev / sdk-frete-rapido-php example snippets




use FreteRapido\Client;

$auth = [
    'remetente_cnpj' => '82193244000283',
    'token' => '1234567891012131415',
    'platform_code' => 'ABC123456'
];


$freteRapido = new Client($auth);

$args = [
    "expedidor" => [
        "cnpj" => "82193244000111",
        "endereco" => [
            "cep" => "80620010"
        ]
    ],
    "destinatario" => [
        "tipo_pessoa" => 1,
        "cnpj_cpf" => "12312312387",
        "inscricao_estadual" => "",
        "endereco" => [
            "cep" => "81710000"
        ]
    ],
    "volumes" => [
        [
            "tipo" => 999,
            "sku" => "ABC123",
            "tag" => "",
            "descricao" => "Produto descrição 01",
            "quantidade" => 1,
            "altura" => 0.250,
            "largura" => 0.080,
            "comprimento" => 0.150,
            "peso" => 0.500,
            "valor" => 9.90,
            "volumes_produto" => 1,
            "consolidar" => false,
            "sobreposto" => false,
            "tombar" => false
        ]
    ],
    "canal" => "",
    "cotacao_plataforma" => 0,
    "retornar_consolidacao" => true
];

$shipping_cost = $freteRapido->shippingCost()->calculate($args)->get();

echo $shipping_cost;




use FreteRapido\Client;

$auth = [
    'remetente_cnpj' => '82193244000281',
    'token' => '1234567891012131415',
    'platform_code' => 'ABC123456'
];

$freteRapido = new Client($auth);

$args = [
    "oferta" => [
        "id" => 1, //id da oferta
        "token" => "64b04f184817893724e94f01" //token_oferta
    ],
    "destinatario" => [
        "cnpj_cpf" => "12312312387",
        "nome" => "NOME PESSOA",
        "email" => "[email protected]",
        "telefone" => "4198765432",
        "endereco" => [
            "cep" => "81710000",
            "rua" => "Rua Fracisco Derosso",
            "numero" => "100",
            "bairro" => "Xaxim",
            "complemento" => "Bloco X - Apto 1",
            "cidade" => "Curitiba",
            "estado" => "PR"
        ]
    ],
    "numero_pedido" => "DEF2024",
    "data_pedido" => "2023-07-08 16:12:13",
    "data_faturamento" => "2023-08-10 16:12:13",
    "obs_cliente" => "",
    "valor_frete_cobrado" => 110
];


$args['expedidor'] = [
    "cnpj" => "82193244000110",
    "razao_social" => "DIPROTEC DISTRIBUIDORA DE PROD",
    "inscricao_estadual" => "123456",
    "endereco" => [
        "cep" => "80620010",
        "rua" => "AVENIDA REPÚBLICA ARGENTINA",
        "numero" => "4486",
        "bairro" => "VILA IZABEL",
        "complemento" => "DIPROTEC"
    ]
];
 
// $args['nota_fiscal'] = [
//     "numero" => "",
//     "serie" => "",
//     "quantidade_volumes" => "",
//     "chave_acesso" => "",
//     "valor" => 0.00,
//     "valor_itens" => 0.00,
//     "data_emissao" => "",
//     "tipo_operacao" => 0,
//     "tipo_emissao" => 0,
//     "protocolo_autorizacao" => ""
// ];

// $args['metadados'] = [[
//     "chave" => "",
//     "valor" => "",
// ]];


$contract_offer = $freteRapido->contractOffer()->execute($args)->get();

echo $contract_offer;




use FreteRapido\Client;

$auth = [
    'remetente_cnpj' => '82193244000281',
    'token' => '1234567891012131415',
    'platform_code' => 'ABC123456'
];

$freteRapido = new Client($auth);

$args = ["id_frete" => "FR230714O123"];

$quote = $freteRapido->quote()->execute($args)->get();

echo $quote;



use FreteRapido\Client;

$auth = [
    'remetente_cnpj' => '82193244000281',
    'token' => '1234567891012131415',
    'platform_code' => 'ABC123456'
];

$freteRapido = new Client($auth);

$args = [
    "id_frete" => "FR230714O123",
    "layout" => "3",
    "formato" => "pdf"
];

$label = $freteRapido->label()->execute($args)->get();

echo $label;



use FreteRapido\Client;

$auth = [
    'remetente_cnpj' => '82193244000281',
    'token' => '1234567891012131415',
    'platform_code' => 'ABC123456'
];

$freteRapido = new Client($auth);

$args = [
    "id_frete" => "FR231013RQW01", //id_frete recuperado na contratação
    "nota_fiscal" => [
    [
        "numero" => "28209",
        "serie" => "5",
        "cfop" => "",
        "chave_acesso" => "41230923200952100154550020000247161950519450",
        "quantidade_volumes" => "1",
        "valor" => 81.00,
        "valor_itens" => 81,00,
        "data_emissao" => "2019-10-06 13:40:00",
        "tipo_operacao" => 1,
        "tipo_emissao" => 1,
        "protocolo_autorizacao" => "333230109061"
    ]
]];

$send_invoice = $freteRapido->sendInvoice()->execute($args)->get();

echo $send_invoice;

 bash
$ composer