Skip to content

Commit

Permalink
Little reorganization
Browse files Browse the repository at this point in the history
  • Loading branch information
lashnev committed Sep 17, 2018
1 parent 8bd2288 commit f98dd73
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 134 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ composer.phar
# Netbeans project files
/nbproject/

# PhpStorm
.idea/

# Merchant settings for integration tests
/tests/integration/MerchantSettings.php
/tests/integration/merchant_data/*
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
"name": "payprocessing/starrys",
"description": "Starrys",
"require": {
"php": ">=5.3",
"psr/log": "1.0.2"
"php": ">=5.5",
"psr/log": "1.0.2",
"myclabs/php-enum": "^1.6"
},
"require-dev": {
"php": ">=5.6",
Expand Down
14 changes: 14 additions & 0 deletions src/handbooks/DocumentTypes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Platron\Starrys\handbooks;

use MyCLabs\Enum\Enum;

class DocumentTypes extends Enum
{
const
SELL = 0,
REFUND = 2,
BUY = 1,
BUY_REFUND = 3;
}
16 changes: 16 additions & 0 deletions src/handbooks/TaxModes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Platron\Starrys\handbooks;

use MyCLabs\Enum\Enum;

class TaxModes extends Enum
{
const
OSN = 1,
USN_INCOME = 2,
USN_INCOME_OUTCOME = 4,
ENDV = 8,
ESN = 16,
PATENT = 32;
}
197 changes: 74 additions & 123 deletions src/services/ComplexRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
namespace Platron\Starrys\services;

use Platron\Starrys\data_objects\Line;
use Platron\Starrys\handbooks\DocumentTypes;
use Platron\Starrys\handbooks\TaxModes;
use Platron\Starrys\SdkException;

class ComplexRequest extends BaseServiceRequest{

class ComplexRequest extends BaseServiceRequest
{

/** @var string */
protected $device = 'auto';
/** @var string */
Expand Down Expand Up @@ -39,190 +42,158 @@ class ComplexRequest extends BaseServiceRequest{
protected $credit;
/** @var float */
protected $consideration;

const
DOCUMENT_TYPE_SELL = 0, // Приход
DOCUMENT_TYPE_SELL_REFUND = 2, // Возврат прихода
DOCUMENT_TYPE_BUY = 1, // Расход
DOCUMENT_TYPE_BUY_REFUND = 3; // Возврат расхода

const
TAX_MODE_OSN = 1, // общая СН
TAX_MODE_USN_INCOME = 2, // упрощенная СН (доходы)
TAX_MODE_USN_INCOME_OUTCOME = 4, // упрощенная СН (доходы минус расходы)
TAX_MODE_ENDV = 8, // единый налог на вмененный доход
TAX_MODE_ESN = 16, // единый сельскохозяйственный налог
TAX_MODE_PATENT = 32; // патентная СН

/**
* @inheritdoc
*/
public function getUrlPath() {
return '/fr/api/v2/Complex';
}


/**
* @inheritdoc
*/
public function getUrlPath()
{
return '/fr/api/v2/Complex';
}

/**
* @param int $requestId id запроса
*/
public function __construct($requestId) {
public function __construct($requestId)
{
$this->requestId = $requestId;
}

/**
* Установить идентификатор предприятия. Передается в случае использования одного сертификата на несколько предприятий
* @param string $group
* return $this
*/
public function addGroup($group){
public function addGroup($group)
{
$this->group = $group;
return $this;
}

/**
* Установить тип чека
* @param string $documentType
* @return $this
* @param DocumentTypes $documentType
*/
public function addDocumentType($documentType){
if(!in_array($documentType, $this->getDocumentTypes())){
throw new SdkException('Wrong payment type');
}

$this->documentType = $documentType;
return $this;
public function addDocumentType(DocumentTypes $documentType)
{
$this->documentType = $documentType->getValue();
}

/**
* Установить режим налогообложения. Нужно если у организации существует более 1 системы налогообложения
* @param int $taxMode
* @return $this
* @param TaxModes $taxMode
*/
public function addTaxMode($taxMode){
if(!in_array($taxMode, $this->getTaxModes())){
throw new SdkException('Wrong tax mode');
}

$this->taxMode = $taxMode;
return $this;
public function addTaxMode(TaxModes $taxMode)
{
$this->taxMode = $taxMode->getValue();
}

/**
* Установить телефон покупателя
* @param int $phone
* @return $this
*/
public function addPhone($phone){
public function addPhone($phone)
{
$this->phone = $phone;
return $this;
}

/**
* Установить email покупателя
* @param string $email
* @return $this
*/
public function addEmail($email){
public function addEmail($email)
{
$this->email = $email;
return $this;
}

/**
* Сумма оплаты наличными. Если сумма равна нулю, то это поле можно опустить
* @param float $cash
* @return $this
*/
public function addCash($cash){
public function addCash($cash)
{
$this->cash = $cash;
return $this;
}

/**
* Массив из 3-ех элеметов с суммами оплат 3 различных типов. Обычно передается только первое значение
* @param int $firstAmount Сумма в копейках
* @param int $secondAmount Сумма в копейках
* @param int $thirdAmount Сумма в копейках
* @return $this
*/
public function addNonCash($firstAmount, $secondAmount = 0, $thirdAmount = 0){
public function addNonCash($firstAmount, $secondAmount = 0, $thirdAmount = 0)
{
$this->nonCash = [$firstAmount, $secondAmount, $thirdAmount];
return $this;
}

/**
* Сумма оплаты предоплатой. Поле не обязательное
* @param int $advancePayment Сумма в копейках
* @return $this
*/
public function addAdvancePayment($advancePayment){
public function addAdvancePayment($advancePayment)
{
$this->advancePayment = $advancePayment;
return $this;
}

/**
* Сумма оплаты постоплатой. Не обязательное
* @param int $credit Сумма в копейках
* @return $this
*/
public function addCredit($credit){
public function addCredit($credit)
{
$this->credit = $credit;
return $this;
}

/**
* Сумма оплаты встречным предоставлением. Не обязательное
* @param int $consideration Сумма в копейках
* @return $this
*/
public function addConsideration($consideration){
public function addConsideration($consideration)
{
$this->consideration = $consideration;
return $this;
}

/**
* Место расчетов. Можно указать адрес сайта
* @param string $place
* @return $this
*/
public function addPlace($place){
public function addPlace($place)
{
$this->place = $place;
return $this;
}

/**
* Добавить позицию в чек
* @param Line $line
* @return $this
*/
public function addLine(Line $line){
public function addLine(Line $line)
{
$this->lines[] = $line;
return $this;
}

/**
* Установить пароль. Не обязательно. Подробнее смотри в полной версии документации
* @param int $password
* @return $this
*/
public function addPassword($password){
public function addPassword($password)
{
$this->password = $password;
return $this;
}

/**
* {@inheritdoc}
* @return array
*/
public function getParameters() {
$lines = [];
foreach($this->lines as $line){
$lines[] = $line->getParameters();
}

$params = [
public function getParameters()
{
$lines = [];
foreach ($this->lines as $line) {
$lines[] = $line->getParameters();
}

$params = [
'Device' => $this->device,
'Group' => $this->group,
'Group' => $this->group,
'Password' => $this->password,
'RequestId' => (string)$this->requestId,
'Lines' => $lines,
'RequestId' => (string)$this->requestId,
'Lines' => $lines,
'Cash' => $this->cash,
'NonCash' => $this->nonCash,
'AdvancePayment' => $this->advancePayment,
Expand All @@ -232,28 +203,8 @@ public function getParameters() {
'PhoneOrEmail' => $this->email ? $this->email : $this->phone,
'Place' => $this->place,
'FullResponse' => $this->fullResponse,
];

return $params;
}

protected function getDocumentTypes(){
return [
self::DOCUMENT_TYPE_BUY,
self::DOCUMENT_TYPE_BUY_REFUND,
self::DOCUMENT_TYPE_SELL,
self::DOCUMENT_TYPE_SELL_REFUND,
];
}
];

protected function getTaxModes(){
return [
self::TAX_MODE_ENDV,
self::TAX_MODE_ESN,
self::TAX_MODE_OSN,
self::TAX_MODE_PATENT,
self::TAX_MODE_USN_INCOME,
self::TAX_MODE_USN_INCOME_OUTCOME,
];
}
return $params;
}
}
15 changes: 8 additions & 7 deletions tests/integration/ComplexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Platron\Starrys\clients\PostClient;
use Platron\Starrys\data_objects\Line;
use Platron\Starrys\handbooks\DocumentTypes;
use Platron\Starrys\services\ComplexRequest;
use Platron\Starrys\services\ComplexResponse;

Expand All @@ -14,13 +15,13 @@ public function testComplex(){
$line->addPayAttribute(Line::PAY_ATTRIBUTE_TYPE_FULL_PAID_WITH_GET_PRODUCT);

$complexServise = new ComplexRequest(time());
$complexServise->addDocumentType(ComplexRequest::DOCUMENT_TYPE_BUY)
->addEmail('[email protected]')
->addPhone('79050000000')
->addPlace('www.test.ru')
->addTaxMode($this->taxMode)
->addLine($line)
->addNonCash(10.00);
$complexServise->addDocumentType(new DocumentTypes(DocumentTypes::BUY));
$complexServise->addEmail('[email protected]');
$complexServise->addPhone('79050000000');
$complexServise->addPlace('www.test.ru');
$complexServise->addTaxMode(new TaxModes($this->taxMode));
$complexServise->addLine($line);
$complexServise->addNonCash(10.00);

$response = new ComplexResponse($client->sendRequest($complexServise));

Expand Down
1 change: 1 addition & 0 deletions tests/integration/IntegrationTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Platron\Starrys\tests\integration;

use Platron\Starrys\handbooks\TaxModes;
use Platron\Starrys\tests\integration\MerchantSettings;

class IntegrationTestBase extends \PHPUnit_Framework_TestCase {
Expand Down
Loading

0 comments on commit f98dd73

Please sign in to comment.