siberfx/laravel-tryoto 问题修复 & 功能扩展

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

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

siberfx/laravel-tryoto

Composer 安装命令:

composer require siberfx/laravel-tryoto

包简介

tryoto.com unofficial api integration using laravel http client.

README 文档

README

v1.0

create your Controller and with a construct method inject our service as below;

class TryOtoController
{
    public $service;

    public function __construct()
    {
        $this->service = new TryotoService;
    }
    
    /// your code below

the constructed service will automatically generate for you the token instance and cache id for 58 minutes by default. the token is valid for only 1 hour in official documents, so I hardcoded that value for some certain reasons to 58 minutes fixed. you can change it from config file for your needs

Usage;

some set of samples of usages in controller, you can adjust them in the way of your needs;

 public function auth()
    {
        return $this->service->authorize();
    }

    public function cancelOrder($orderId = 'OID-60774-1001')
    {
        return $this->service->cancelOrder($orderId);
    }

    public function orderDetail($orderId = 'OID-60774-1001')
    {
        return $this->service->orderDetail($orderId);
    }

    public function orderList()
    {
        return $this->service->listOrders();
    }


    public function createOrder($order)
    {
        return $this->dataSet($order);
    }

    public function setWebhook()
    {
        return (new TryotoService)->setWebhook();
    }


    public function dataSet(array $order = [])
    {
        $siteTitle = 'Shop title';

        if (empty($order) || !is_array($order)) {
            $order = [
                'orderCode' => '1231223',
                'amount' => 5.00,
                'sub_total' => 5.00,
                'description' => 'test description',
                'orderDate' => Carbon::parse(Carbon::now())->format('d/m/y H:i'),
                'deliverySlotDate' => Carbon::parse(Carbon::now()->addDay())->format('d/m/y'), // next day date
                'customer_name' => 'John Doe',
                'customer_email' => 'john@doe.com',
                'customer_phone' => '123456789',
                'customer_address' => 'test address',
                'customer_state' => 'State',
                'customer_city' => 'City',
                'customer_country' => 'TR',
                'customer_zipcode' => '12345',
                'products' => [
                    [
                        "productId" => 1,
                        "name" => 'product name 1',
                        "price" => 5.00,
                        "rowTotal" => 5,
                        "quantity" => 1,
                        "serialnumber" => "",
                        "sku" => 'SKU-Code',
                        "image" => 'https://fullpath-to-image.jpg',
                    ],
                    [
                        "productId" => 2,
                        "name" => 'product name 2',
                        "price" => 5.00,
                        "taxAmount" => 0,
                        "quantity" => 1,
                        "serialnumber" => "",
                        "sku" => 'SKU-Code 2',
                        "image" => 'https://fullpath-to-image-2.jpg',
                    ]
                ]
            ];
        }

        $body = [
            "orderId" => $order['orderCode'], // check documentation for your needs
            "ref1" => "", // check documentation for your needs
            "pickupLocationCode" => "", // check documentation for your needs
//            "deliveryOptionId" => "", // check documentation for your needs
            "serviceType" => "",
            "createShipment" => false,
            "storeName" => $siteTitle,
            "payment_method" => "paid",
            "amount" => (double)$order['amount'],
            "amount_due" => 0,
            "customsValue" => "12",
            "customsCurrency" => "TRY",
            "shippingAmount" => 20,
            "subtotal" => (double)$order['sub_total'],
            "currency" => "TRY",
            "shippingNotes" => $order['description'],
            "packageSize" => "small",
            "packageCount" => (int)count($order['products']),
            "packageWeight" => 1,
            "boxWidth" => 10, // check documentation for your needs
            "boxLength" => 10, // check documentation for your needs
            "boxHeight" => 10, // check documentation for your needs
            "orderDate" => $order['orderDate'], // "30/12/2020 15:45",
            "deliverySlotDate" => $order['deliverySlotDate'], //"31/12/2020",
            "deliverySlotTo" => "12pm",
            "deliverySlotFrom" => "6:30pm",
            "senderName" => $siteTitle,
            "customer" => [
                "name" => $order['customer_name'],
                "email" => $order['customer_email'],
                "mobile" => $order['customer_phone'],
                "address" => $order['customer_address'],
                "district" => $order['customer_state'],
                "city" => $order['customer_city'],
                "country" => $order['customer_country'],
                "postcode" => $order['customer_zipcode'],
                "lat" => "",
                "lon" => "",
                "refID" => "",
                "W3WAddress" => ""
            ],
            "items" => $this->productsParser($order['products'])
        ];

        $this->service->createOrder($body);

        return $body;
    }

    public function productsParser(array $products)
    {
        $result = [];

        foreach ($products as $single) {
            $result[] = [
                "productId" => $single['productId'],
                "name" => $single['name'],
                "price" => $single['price'],
                "rowTotal" => (double)$single['price'] * $single['quantity'],
                "taxAmount" => $single['taxAmount'],
                "quantity" => $single['quantity'],
                "serialnumber" => $single['serialnumber'],
                "sku" => $single['sku'],
                "image" => $single['image'],
            ];
        }
        return $result;
    }


    public function listenWebhook(Request $request)
    {
        $orderId = $request->get('orderId');
        $statusCode = $request->get('status');

        $trackingNumber = $request->get('trackingNumber');
        $brandedTrackingURL = $request->get('brandedTrackingURL');
        $driverName = $request->get('driverName');
        $driverEmail = $request->get('driverEmail');
        $timestamp = $request->get('timestamp');


        if (!$statusCode || !$orderId) {
            return false;
        }

        // here is your code for handling the webhook response

    }

Credits

siberfx/laravel-tryoto 适用场景与选型建议

siberfx/laravel-tryoto 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 890 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 08 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「Siberfx」 「tryoto」 「cargo integration」 「shipment automation」 「shipment integration」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 siberfx/laravel-tryoto 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 siberfx/laravel-tryoto 我们能提供哪些服务?
定制开发 / 二次开发

基于 siberfx/laravel-tryoto 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

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