natsu007 / ntak-php
An easy to use NTAK PHP Api (for 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: 2025-03-29 01:07:00 UTC
README
This is a fork from https://github.com/kiralyta/ntak-php repostitory, so I can use API in php 7.1. I hope it helps others who cannot use the latest version of php due to other dependencies. Remdme.md has been partially rewritten to comply with php 7.1. I left the other parts in their original form.
Update: I have created a development branch into which I am constantly synchronizing the latest updates from "kiralyta / ntak-php". I will rewrite the updated code if necessary so that it runs in php 7.1. Unit tests are performed on every update. Each update gets a tag.
Welcome to my little package, that helps you make NTAK RMS requests like a boss.
Table of Contents:
Installation
composer require natsu007/ntak-php
Usage
Instances
Create an API Client Instance
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 );
Your
.pem
file is basically a concatenated file of your.cer
and.key
files.It is recommended to have a singleton
NTAKClient
instance during one request cycle. This means, you can create multiple requests with a singleNTAKClient
instance.
You can get the last request, response and respone time (in milliseconds) from the client.
$client->lastRequest(); // Returns an array $client->lastResponse(); // Returns an array $client->lastRequestTime(); // Returns an integer
Create an Order Item Instance
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() );
Create a Payment Instance
use Natsu007\Ntak\Enums\NTAKPaymentType; use Natsu007\Ntak\Models\NTAKPayment; $payment = new NTAKPayment( paymentType: NTAKPaymentType::BANKKARTYA(), total: 2000 // Total payed with this method type );
Create an Order Instance
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' );
When you are updating / destroying an order, you need to provide (generate) a new
orderId
with each requests.In these cases, the
ntakOrderId
is always the last providedorderId
.
Messages (Requests)
Store, Update, Destroy Order (Rendelésösszesítő)
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(...));
Returns the NTAK process ID string.
Close Day (Napzárás)
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) );
Returns the NTAK process ID string.
Verify (Ellenőrzés)
use Carbon\Carbon; use Natsu007\Ntak\Enums\NTAKDayType; use Natsu007\Ntak\NTAK; $response = NTAK::message($client, Carbon::now()) ->verify( processId: 'NTAK Process ID' );
Returns an
NTAKVerifyResponse
instance
$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
If you encounter an unsuccessful message, you should further examine NTAKVerifyStatus. It's recommended to wait at least 60 seconds before the first verification attempt of a processs ID.
Enums
Namespace of the enums:
namespace Natsu007\Ntak\Enums;
You can use the values()
static method on any of the enums, in order to get the available values.
NTAKAmount
name | value string |
---|---|
DARAB | darab |
LITER | liter |
KILOGRAMM | kilogramm |
EGYSEG | egyseg |
NTAKCategory
name | value string |
---|---|
ETEL | Étel |
ALKMENTESITAL_HELYBEN | Helyben készített alkoholmentes ital |
ALKMENTESITAL_NEM_HELYBEN | Nem helyben készített alkoholmentes ital |
ALKOHOLOSITAL | Alkoholos Ital |
EGYEB | Egyéb |
NTAKSubcategory
name | value string |
---|---|
REGGELI | reggeli |
SZENDVICS | szendvics |
ELOETEL | előétel |
LEVES | leves |
FOETEL | főétel |
KORET | köret |
SAVANYUSAG_SALATA | savanyúság/saláta |
KOSTOLO | kóstolóétel, kóstolófalat |
PEKSUTEMENY | péksütemény, pékáru |
DESSZERT | desszert |
SNACK | snack |
FOETEL_KORETTEL | főétel körettel |
ETELCSOMAG | ételcsomag |
EGYEB | egyéb |
VIZ | víz |
LIMONADE_SZORP_FACSART | limonádé / szörp / frissen facsart ital |
ALKOHOLMENTES_KOKTEL | alkoholmentes koktél, alkoholmentes kevert ital |
TEA_FORROCSOKOLADE | tea, forrócsoki és egyéb tejalapú italok |
ITALCSOMAG | italcsomag |
KAVE | kávé |
ROSTOS_UDITO | rostos üdítő |
SZENSAVAS_UDITO | szénsavas üdítő |
SZENSAVMENTES_UDITO | szénsavmentes üdítő |
KOKTEL | koktél, kevert ital |
LIKOR | likőr |
PARLAT | párlat |
SOR | sör |
BOR | bor |
PEZSGO | pezsgő |
SZERVIZDIJ | szervizdíj |
BORRAVALO | borravaló |
KISZALLITASI_DIJ | kiszállítási díj |
NEM_VENDEGLATAS | nem vendéglátás |
KORNYEZETBARAT_CSOMAGOLAS | környezetbarát csomagolás |
MUANYAG_CSOMAGOLAS | műanyag csomagolás |
KEDVEZMENY | kedvezmény |
NTAKDayType
name | value string |
---|---|
ADOTT_NAPON_ZARVA | Adott napon zárva |
FORGALOM_NELKULI_NAP | Forgalom nélküli nap |
NORMAL_NAP | Normál nap |
NTAKOrderType
name | value string |
---|---|
NORMAL | Normál |
SZTORNO | Storno |
HELYESBITO | Helyesbítő |
NTAKPaymentType
name | value string |
---|---|
KESZPENZHUF | Készpénz huf |
KESZPENZEUR | Készpénz eur |
SZEPKARTYA | Szépkártya |
BANKKARTYA | Bankkártya |
ATUTALAS | Átutalás |
EGYEB | Egyéb |
VOUCHER | Voucher |
SZOBAHITEL | Szobahitel |
KEREKITES | Kerekítés |
NTAKVat
name | value string |
---|---|
A_5 | 5% |
B_18 | 18% |
C_27 | 27% |
D_AJT | Ajt |
E_0 | 0% |
NTAKVerifyStatus
name | value string |
---|---|
BEFOGADVA | BEFOGADVA |
TELJESEN_HIBAS | TELJESEN_HIBAS |
RESZBEN_SIKERES | RESZBEN_SIKERES |
TELJESEN_SIKERES | TELJESEN_SIKERES |
UJRA_KULDENDO | UJRA_KULDENDO |
Contribution
git clone git@github.com:natsu007/ntak-php.git
cd ntak-php
composer install --dev
Run Tests
Put your cer.cer
and pem.pem
files in ./auth
directory, then run:
vendor/bin/phpunit src/Tests