heureka/hcapi

Heureka购物车API

v1.0.1 2018-11-16 12:06 UTC

This package is auto-updated.

Last update: 2024-09-24 19:45:48 UTC


README

Hcapi是一个创建于简化购物顾问Heureka.cz与想要使用这些服务和购物车的店铺之间连接的工具。

使用方法

通过Composer安装

composer require heureka/hcapi

实现

在本节中,您将找到hcapi实现到您项目的手册。

通过Callable连接

通过Callable callback连接您的店铺到HCAPI的第一种方式。

在您的代码中必须创建函数(对于所有服务),这些函数接收来自Heureka的数据(数组),处理它们,并返回所需的数据(数组)。所需数据的结构您可以在此处找到。

支付/状态函数示例

//PaymentStatus.php

public function setPaymentStatus($receiveData)
    {
        //set payment status for order

        return [
            'status' => false,
        ];
    }

第二步,您必须将这些函数与您的路由连接起来。您必须为API的每个方法使用特定的服务。例如 支付/状态

//Router.php

if ($_SERVER['REQUEST_URI'] === 'https://www.example.com/api/1/payment/status') {
            $service = new PaymentStatus();
            return $service->processData(
                [
                    'Hcapi\Example\CallableExample\PaymentStatus',
                    'setPaymentStatus',
                ],
                $receiveData);
        }

服务位于 /src/Services/。更多示例位于 /example/InterfaceExample/。

通过接口实现

通过接口连接您的店铺到HCAPI的另一种方式。在文件夹 /scr/Interfaces/ 中位于接口 IShopImplementation.php。您必须实现此接口以处理所有来自Heureka的数据的类。

示例

class OrderCancel implements IShopImplementation
{
    /**
     * @param array $receiveData
     *
     * @return array
     */
    public function getResponse($receiveData)
    {
        //Do something with receive data

        return [
            'status' => true,
        ];
    }

}

第二步,您必须将这些函数连接到您的路由。您必须为API的每个方法使用特定的服务。例如 订单/取消

if ($_SERVER['REQUEST_URI'] === 'https://www.example.com/api/1/order/cancel') {
    $service = new OrderCancel();
    $orderCancel = new \Hcapi\Example\InterfaceExample\OrderCancel();

    return $service->processData($orderCancel, $receiveData);
}

更多示例位于 /example/CallableExample/。