pedroquezado/braspress 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pedroquezado/braspress

最新稳定版本:1.0

Composer 安装命令:

composer require pedroquezado/braspress

包简介

API Client para integração com a Braspress.

README 文档

README

Maintainer Source Code PHP from Packagist Latest Version Software License Build Quality Score Total Downloads

This PHP client library allows you to interact with the Braspress API for freight quotation and tracking services. The library provides a convenient way to access Braspress's services, including calculating shipping costs and tracking shipments, with support for both rodoviário (road) and aéreo (air) modalities.

Installation

To install this library, you can use Composer:

composer require pedroquezado/braspress

Usage

Initialization

To start using the Braspress client, first, initialize the BraspressCliente class with your credentials.

require 'vendor/autoload.php';

use PedroQuezado\Code\Braspress\BraspressCliente;

$cliente = new BraspressCliente('your_braspress_username', 'your_braspress_password');

Adding Products

Before performing a freight quotation, you need to add products (volumes) to the client:

$cliente->inserirProduto(5.5, [
    'comprimento' => 0.67,
    'largura' => 0.67,
    'altura' => 0.46
]);

$cliente->inserirProduto(2.3, [
    'comprimento' => 0.45,
    'largura' => 0.30,
    'altura' => 0.20
]);

Each call to inserirProduto adds a new volume to the list of products to be included in the freight quotation.

Performing Freight Quotation

You can perform a freight quotation for either or both modalities (road and air):

try {
    $dadosCotacao = [
        'cnpjRemetente' => '12345678000100',
        'cnpjDestinatario' => '09876543210001',
        'tipoFrete' => '1', // 1 for CIF, 2 for FOB
        'cepOrigem' => '12345000',
        'cepDestino' => '54321000',
        'vlrMercadoria' => 500.00
    ];

    $resultados = $cliente->realizarCotacao($dadosCotacao, 'json', ['R', 'A']);

    print_r($resultados);
} catch (\PedroQuezado\Code\Braspress\BraspressClienteException $e) {
    echo 'Erro: ' . $e->getMessage();
}

The realizarCotacao method performs the freight quotation for the specified modality (R for road, A for air, or both). The results are returned as an associative array, separated by modality.

Example Response

Array
(
    [Rodoviario] => Array
        (
            [id] => 274407950
            [prazo] => 5
            [totalFrete] => 73.02
        )

    [Aereo] => Array
        (
            [id] => 274408248
            [prazo] => 2
            [totalFrete] => 631.38
        )
)

Error Handling

Errors are handled via exceptions. If an error occurs during the API request, a BraspressClienteException is thrown:

try {
    // API call
} catch (\PedroQuezado\Code\Braspress\BraspressClienteException $e) {
    echo "Erro: " . $e->getMessage();
}

Advanced Features

Setting Modalities

You can set the freight modalities when calling the realizarCotacao method. Pass an array with 'R' and/or 'A' to get quotes for road and/or air modalities.

Handling Responses

The realizarCotacao method returns the result as an associative array. The keys Rodoviario and Aereo contain the corresponding results.

Documentation

For more information, please refer to the official Braspress API documentation:

License

This library is open-source and available under the MIT license. See the LICENSE file for more information.

Contributions

Contributions are welcome! Please submit a pull request or open an issue to contribute to this project.

统计信息

  • 总下载量: 11
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-08-12