quesoft / ntak-php
易于使用的NTAK PHP API(适用于PHP 7.1)
Requires
- php: ^7.1
- gamegos/jws: ^1.0
- guzzlehttp/guzzle: *
- myclabs/php-enum: ^1.7.7
- nesbot/carbon: ^2.66
Requires (Dev)
- phpunit/phpunit: ^7.5.20
- ramsey/uuid: ^3.9.7
- symfony/var-dumper: ^4.4.47
- tightenco/collect: ^8.0.4
This package is auto-updated.
Last update: 2024-09-27 07:07:54 UTC
README
这是从https://github.com/Natsu007/ntak-php仓库的分支。我们希望扩展一些其他功能。希望它对其他人有帮助。Readme.md已维护。其他部分保持原始形式。我们将合并原始仓库的新发展。
原始仓库https://github.com/kiralyta/ntak-php,感谢分享解决方案
这可以帮助您像老板一样制作NTAK RMS请求。
目录
安装
composer require quesoft/ntak-php
用法
实例
创建API客户端实例
use QueSoft\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 QueSoft\Ntak\Enums\NTAKAmount; use QueSoft\Ntak\Enums\NTAKCategory; use QueSoft\Ntak\Enums\NTAKSubcategory; use QueSoft\Ntak\Enums\NTAKVat; use QueSoft\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 QueSoft\Ntak\Enums\NTAKPaymentType; use QueSoft\Ntak\Models\NTAKPayment; $payment = new NTAKPayment( paymentType: NTAKPaymentType::BANKKARTYA(), total: 2000 // Total payed with this method type );
创建订单实例
use Carbon\Carbon; use QueSoft\Ntak\Enums\NTAKOrderType; use QueSoft\Ntak\Enums\NTAKAggregateCause; use QueSoft\Ntak\Models\NTAKOrderItem; use QueSoft\Ntak\Models\NTAKOrder; use QueSoft\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', aggregated: false, // Is order aggregated aggregatedCause: NTAKAggregateCause::UZEMSZUNET_ARAMSZOLGALTATAS_TERVEZETT_KIMARADASA_MIATT(), // If aggregated, It's cause. Defaults to null tip_amount: 0, //added to order as BORRAVALO type. Calculation order is items total, then discount, then service fee + tip_amount );
当您更新/销毁订单时,您需要为每个请求提供(生成)一个新的
orderId
。在这些情况下,
ntakOrderId
始终是最后提供的orderId
。
消息(请求)
存储、更新、销毁订单(Rendelésösszesítő)
use Carbon\Carbon; use QueSoft\Ntak\Models\NTAKOrder; use QueSoft\Ntak\Models\NTAKPayment; use QueSoft\Ntak\NTAK; $processId = NTAK::message($client, Carbon::now()) ->handleOrder(new NTAKOrder(...));
返回NTAK进程ID字符串。
重发消息(Újraküldés - Rendelésösszesítők/Napzárás)
重发之前发送的消息。需要从之前发送请求的最后一条消息中解码数组内容。当您需要通过验证请求重发订单或关闭时很有用。重要的是在设置消息对象时,参数应与上一条消息的精确时间戳相同!
use Carbon\Carbon; use QueSoft\Ntak\NTAK; $processId = NTAK::message($client, Carbon::parse($lastSentRequestData["uzenetAdatok"]["uzenetKuldesIdeje"])) ->resendMessage(["zarasiInformaciok" => $lastSentRequestData["zarasiInformaciok"]], false); $processId = NTAK::message($client, Carbon::parse($lastSentRequestData["uzenetAdatok"]["uzenetKuldesIdeje"])) ->resendMessage(["zarasiInformaciok" => $lastSentRequestData["zarasiInformaciok"]]);
返回NTAK进程ID字符串。
每日结账(Napzárás)
use Carbon\Carbon; use QueSoft\Ntak\Enums\NTAKDayType; use QueSoft\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字符串。
验证(Ellenőrzés)
use Carbon\Carbon; use QueSoft\Ntak\Enums\NTAKDayType; use QueSoft\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 QueSoft\Ntak\Enums;
您可以在任何枚举上使用values()
静态方法,以获取可用值。
NTAKAmount
NTAKCategory
NTAKSubcategory
NTAKDayType
NTAKOrderType
NTAKPaymentType
NTAKVat
NTAKVerifyStatus
NTAKAggregateCause
贡献
git clone git@github.com:quesoft-it/ntak-php.git
cd ntak-php
composer install --dev
运行测试
将您的cer.cer
和pem.pem
文件放入./auth
目录,然后运行
vendor/bin/phpunit src/Tests