natsu007/ntak-php

易于使用的NTAK PHP Api(适用于PHP 7.1)

1.2.0 2023-06-30 09:55 UTC

This package is auto-updated.

Last update: 2024-09-30 02:10:47 UTC


README

这是一个从https://github.com/kiralyta/ntak-php仓库的分支,因此我可以使用PHP 7.1中的API。我希望它能帮助那些因为其他依赖而无法使用最新版PHP的用户。Remdme.md已部分重写,以符合PHP 7.1。其他部分保持原样。

更新:我创建了一个开发分支,我正在不断从"kiralyta / ntak-php"同步最新更新。如果需要,我将重写更新后的代码,使其在PHP 7.1中运行。每次更新都会执行单元测试。每个更新都有一个标签。

欢迎来到我的小包,它可以帮助您像老板一样进行NTAK RMS请求。

目录

安装

composer require natsu007/ntak-php

使用方法

实例

创建API客户端实例

use Natsu007\Ntak\NTAKClient;

$client = new NTAKClient(
    taxNumber:         'NTAK client tax nr',         // without `-` chars
    regNumber:         'NTAK client registration nr',
    softwareRegNumber: 'NTAK RMS registration id',
    version:           'NTAK RMS version',
    certPath:          '/path/to/your.pem',
    testing:           false                         // whether to hit the test NTAK API
);

您的 .pem 文件基本上是您的 .cer.key 文件的连接文件。

建议在一个请求周期内使用单例 NTAKClient 实例。这意味着,您可以使用单个 NTAKClient 实例创建多个请求。

您可以从客户端获取最后的请求、响应和响应时间(以毫秒为单位)。

$client->lastRequest();     // Returns an array
$client->lastResponse();    // Returns an array
$client->lastRequestTime(); // Returns an integer

创建订单项目实例

use Carbon\Carbon;
use Natsu007\Ntak\Enums\NTAKAmount;
use Natsu007\Ntak\Enums\NTAKCategory;
use Natsu007\Ntak\Enums\NTAKSubcategory;
use Natsu007\Ntak\Enums\NTAKVat;
use Natsu007\Ntak\Models\NTAKOrderItem;

$orderItem = new NTAKOrderItem(
    name:            'Absolut Vodka',               // Any kind of string
    category:        NTAKCategory::ALKOHOLOSITAL(), // Main category
    subcategory:     NTAKSubcategory::PARLAT(),     // Subcategory
    vat:             NTAKVat::C_27(),
    price:           1000,
    amountType:      NTAKAmount::LITER(),
    amount:          0.04,
    quantity:        2,
    when:            Carbon::now()
);

创建支付实例

use Natsu007\Ntak\Enums\NTAKPaymentType;
use Natsu007\Ntak\Models\NTAKPayment;

$payment = new NTAKPayment(
    paymentType:     NTAKPaymentType::BANKKARTYA(),
    total:           2000 // Total payed with this method type
);

创建订单实例

use Carbon\Carbon;
use Natsu007\Ntak\Enums\NTAKOrderType;
use Natsu007\Ntak\Models\NTAKOrderItem;
use Natsu007\Ntak\Models\NTAKOrder;
use Natsu007\Ntak\Models\NTAKPayment;

$order = new NTAKOrder(
    orderType:   NTAKOrderType::NORMAL(),       // You can control whether to store, update, or destroy an order
    orderId:     'your-rms-order-id',           // RMS Order ID
    orderItems:  [new NTAKOrderItem(...)],      // Array of the order items
    start:       Carbon::now()->addMinutes(-7), // Start of the order
    end:         Carbon::now(),                 // End of the order
    payments:    [new NTAKPayment(...)],        // Array of the payments

    // Take away handled automatically
    // Vat changed to 27 in all OrderItems that have a category "Helyben készített alkoholmentes ital" in case of isAtTheSpot is false
    isAtTheSpot: true,

    // Discount and service fee are automatically managed by the package
    // You don't have to manually add the OrderItem(s) with "KEDVEZMENY" / "SZERVIZDIJ" subcategories
    // Vats are handled automatically as well
    // If both discount and service fee are provided, the service fee will be calculated from the discounted total
    // The following means 20% discount (defaults to 0) and 10% service fee (defaults to 0)
    discount:    20,
    serviceFee:  10,

    // Only on update / destroy
    ntakOrderId: 'your-previous-order-id'
);

在更新/删除订单时,您需要为每个请求(生成)一个新的 orderId

在这些情况下,ntakOrderId 始终是最后提供的 orderId

消息(请求)

存储、更新、删除订单(订单汇总)

use Carbon\Carbon;
use Natsu007\Ntak\Models\NTAKOrder;
use Natsu007\Ntak\Models\NTAKPayment;
use Natsu007\Ntak\NTAK;

$processId = NTAK::message($client, Carbon::now())
    ->handleOrder(new NTAKOrder(...));

返回NTAK进程ID字符串。

每日关闭

use Carbon\Carbon;
use Natsu007\Ntak\Enums\NTAKDayType;
use Natsu007\Ntak\NTAK;

$processId = NTAK::message($client, Carbon::now())
    ->closeDay(
        start:   Carbon::now()->addHours(-10), // Opening time (nullable)
        end:     Carbon::now(),                // Closing time (nullable)
        dayType: NTAKDayType::NORMAL_NAP(),      // Day type
        tips:    1000                          // Tips (default 0)
    );

返回NTAK进程ID字符串。

验证

use Carbon\Carbon;
use Natsu007\Ntak\Enums\NTAKDayType;
use Natsu007\Ntak\NTAK;

$response = NTAK::message($client, Carbon::now())
    ->verify(
        processId: 'NTAK Process ID'
    );

返回一个 NTAKVerifyResponse 实例

$response->successful();         // Check whether our message was processed successfully
$response->unsuccessful();       // Check whether our message was processed unsuccessfully
$response->status;               // Returns an NTAKVerifyStatus
$response->successfulMessages;   // Returns an array of the successful messages
$response->unsuccessfulMessages; // Returns an array of the unsuccessful messages
$response->headerErrors;         // Returns an array of the header errors

如果您遇到失败的消息,应进一步检查NTAKVerifyStatus。建议在第一次尝试验证进程ID之前至少等待60秒。

枚举

枚举的命名空间

namespace Natsu007\Ntak\Enums;

您可以在任何枚举上使用 values() 静态方法,以获取可用的值。

NTAKAmount

NTAKCategory

NTAKSubcategory

NTAKDayType

NTAKOrderType

NTAKPaymentType

NTAKVat

NTAKVerifyStatus

贡献

git clone git@github.com:natsu007/ntak-php.git
cd ntak-php
composer install --dev

运行测试

将您的 cer.cerpem.pem 文件放入 ./auth 目录,然后运行

vendor/bin/phpunit src/Tests