-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
159 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,62 @@ | ||
# php-dreamkas | ||
Фискализация чека для Дримкас-Ф на php | ||
Фискализация чека для Дримкас-Ф для PHP 7.2 | ||
|
||
Для более старых версий PHP придётся править код на предмет типов у функций. | ||
|
||
## Установка | ||
|
||
``` | ||
composer require devgroup/php-dreamkas | ||
``` | ||
|
||
## Пример кода | ||
|
||
```php | ||
<?php | ||
use DevGroup\Dreamkas\Api; | ||
use DevGroup\Dreamkas\CustomerAttributes; | ||
use DevGroup\Dreamkas\exceptions\ValidationException; | ||
use DevGroup\Dreamkas\Payment; | ||
use DevGroup\Dreamkas\Position; | ||
use DevGroup\Dreamkas\Receipt; | ||
use DevGroup\Dreamkas\TaxMode; | ||
use GuzzleHttp\Exception\ClientException; | ||
|
||
/*** | ||
* 123 - ID кассы | ||
* MODE_MOCK - режим, может быть MODE_MOCK, MODE_PRODUCTION, MODE_MODE_DEBUG | ||
*/ | ||
$api = new Api('ACCESS_TOKEN из профиля', 123, Api::MODE_MOCK); | ||
|
||
$receipt = new Receipt(); | ||
$receipt->taxMode = TaxMode::MODE_SIMPLE; | ||
$receipt->positions[] = new Position([ | ||
'name' => 'Билет - тест', | ||
'quantity' => 2, | ||
'price' => 210000, // цена в копейках за 1 шт. или 1 грамм | ||
]); | ||
$receipt->payments[] = new Payment([ | ||
'sum' => 420000, // стоимость оплаты по чеку | ||
]); | ||
$receipt->attributes = new CustomerAttributes([ | ||
'email' => '[email protected]', // почта покупателя | ||
'phone' => '74996776566', // телефон покупателя | ||
]); | ||
|
||
$receipt->calculateSum(); | ||
|
||
|
||
$response = []; | ||
try { | ||
$response = $api->postReceipt($receipt); | ||
} catch (ValidationException $e) { | ||
// Это исключение кидается, когда информация в чеке не правильная | ||
} catch (ClientException $e) { | ||
echo $e->getResponse()->getBody(); | ||
// Это исключение кидается, когда при передачи чека в Дрикас произошла ошибка. Лучше отправить чек ещё раз | ||
// Если будут дубли - потом отменяйте через $receipt->type = Receipt::TYPE_REFUND; | ||
} | ||
|
||
``` | ||
|
||
Made by DevGroup.ru - [Создание интернет-магазинов](https://devgroup.ru/services/internet-magazin). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
namespace DevGroup\Dreamkas\tests; | ||
|
||
use DevGroup\Dreamkas\Api; | ||
use DevGroup\Dreamkas\CustomerAttributes; | ||
use DevGroup\Dreamkas\exceptions\ValidationException; | ||
use DevGroup\Dreamkas\Payment; | ||
use DevGroup\Dreamkas\Position; | ||
use DevGroup\Dreamkas\Receipt; | ||
use DevGroup\Dreamkas\TaxMode; | ||
use GuzzleHttp\Exception\ClientException; | ||
|
||
|
||
/** | ||
* Class ApiTest | ||
*/ | ||
class ApiTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
|
||
public function testJson() | ||
{ | ||
$api = new Api('FAKE', 123, Api::MODE_MOCK); | ||
$result = $api->json('GET', 'products'); | ||
|
||
$this->assertSame([[]], $result); | ||
} | ||
|
||
public function testPostReceipt() | ||
{ | ||
|
||
$api = new Api('FAKE', 123, Api::MODE_MOCK); | ||
|
||
$receipt = new Receipt(); | ||
$receipt->taxMode = TaxMode::MODE_SIMPLE; | ||
$receipt->positions[] = new Position([ | ||
'name' => 'Билет - тест', | ||
'quantity' => 2, | ||
'price' => 210000, | ||
]); | ||
$receipt->payments[] = new Payment([ | ||
'sum' => 420000, | ||
]); | ||
$receipt->attributes = new CustomerAttributes([ | ||
'email' => '[email protected]', | ||
]); | ||
|
||
$receipt->calculateSum(); | ||
|
||
|
||
$response = []; | ||
try { | ||
$response = $api->postReceipt($receipt); | ||
} catch (ValidationException $e) { | ||
$this->assertFalse(true, 'Validation exception: ' . $e->getMessage()); | ||
} catch (ClientException $e) { | ||
echo $e->getResponse()->getBody(); | ||
$this->assertFalse(true, 'Client exception'); | ||
} | ||
$this->assertArrayHasKey('status', $response); | ||
$this->assertArrayHasKey('id', $response); | ||
$this->assertArrayHasKey('createdAt', $response); | ||
|
||
// | ||
$receipt->type = Receipt::TYPE_REFUND; | ||
$response = []; | ||
try { | ||
$response = $api->postReceipt($receipt); | ||
} catch (ValidationException $e) { | ||
$this->assertFalse(true, 'Validation exception: ' . $e->getMessage()); | ||
} catch (ClientException $e) { | ||
echo $e->getResponse()->getBody(); | ||
$this->assertFalse(true, 'Client exception'); | ||
} | ||
$this->assertArrayHasKey('status', $response); | ||
$this->assertArrayHasKey('id', $response); | ||
$this->assertArrayHasKey('createdAt', $response); | ||
|
||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?php |