valentinmari/glovo-api-php

0.0.1 2019-02-22 19:28 UTC

This package is auto-updated.

Last update: 2024-09-27 06:27:54 UTC


README

通过商务 API 创建、检索和跟踪您的 Glovo 订单。

要求

PHP 5.4.0 及以上版本。

Composer

您可以通过Composer安装绑定。运行以下命令

$ composer require valentinmari/glovo-api-php

要在项目中使用 Glovo API,请使用 Composer 的自动加载

require_once('vendor/autoload.php');

依赖项

为了正常工作,绑定需要以下扩展

  • curl,尽管您可以选择使用自己的非 cURL 客户端
  • json
  • mbstring(多字节字符串)

如果您使用 Composer,这些依赖项应该会自动处理。如果您手动安装,请确保这些扩展可用。

入门

在 Glovo 中创建一个账户(可以从应用中创建)。此 API 需要与您的账户关联的信用卡。您可以从应用中添加一张卡,并且它将被自动用于任何订单。为了获取您的 API 凭证,您应该在所需环境中登录并转到个人资料中的 凭据 部分。

示例 ApiKey & ApiSecret

$apiKey = '125238463972712';
$apiSecret = '081f8c9680d457a088b4413a62ddf84c';

简单用法如下

<?php

include 'vendor/autoload.php';

use Glovo\Api;
use Glovo\Model\Order;
use Glovo\Model\Address;


// get credentials on https://business.glovoapp.com/dashboard/profile or https://business.testglovo.com/dashboard/profile
$api = new Api( '125238463972712', '081f8c9680d457a088b4413a62ddf84c' );
$api->sandbox_mode( true );

$sourceDir = new Address( Address::TYPE_PICKUP, -34.919861, -57.919027, "Diag. 73 1234", "1st floor" );
$destDir = new Address( Address::TYPE_DELIVERY, -34.922945, -57.990177, "Diag. 73 75", "3A");

$order = new Order();
$order->setDescription( "1 big hammer" );
$order->setAddresses( [$sourceDir, $destDir] );
//$order->setScheduleTime( ( new \DateTime( '+1 hour' ) )->setTime( 19, 0 ) );

$orderEstimate = $api->estimateOrderPrice( $order );

echo "Estimate: {$orderEstimate['total']['amount']}{$orderEstimate['total']['currency']} \n";

$orderInfo = $api->createOrder( $order );

echo "Order created, ID: {$orderInfo['id']}, state: {$orderInfo['state']} \n";

example.php中查看完整示例

更新证书

要更新 CA 根证书,可以运行

$ chmod +x ./update_certs.php
$ ./update_certs.php

文档

您可以阅读 [Glovo B2B API 文档][https://api-docs.glovoapp.com/b2b/index.html#introduction]。