Skip to content

Commit

Permalink
Merge pull request #1 from Alexsisukin/beneficiaryV5
Browse files Browse the repository at this point in the history
Заполнение/чтение данных о рекламодателе api v5
  • Loading branch information
gladyshev authored Aug 20, 2023
2 parents 8a58c33 + 6324aef commit 2ddcd84
Show file tree
Hide file tree
Showing 12 changed files with 363 additions and 0 deletions.
13 changes: 13 additions & 0 deletions examples/get-campaigns-beneficiary.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

require '../vendor/autoload.php';

$client = new \Promopult\YandexBusinessApi\Client(
new \Promopult\YandexBusinessApi\Config(getenv('__ACCESS_TOKEN__')),
new \GuzzleHttp\Client()
);

$response = $client
->getCampaignBeneficiaryV5(getenv('__CAMPAIGN_ID__'));

var_dump($response);
42 changes: 42 additions & 0 deletions examples/set-campaigns-beneficiary.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

use Promopult\YandexBusinessApi\Dto\CampaignClient;
use Promopult\YandexBusinessApi\Dto\CampaignContract;
use Promopult\YandexBusinessApi\Dto\CampaignContractor;
use Promopult\YandexBusinessApi\Enum\CampaignClientTypeEnum;
use Promopult\YandexBusinessApi\Enum\CampaignContractorTypeEnum;
use Promopult\YandexBusinessApi\Enum\CampaignContractSubjectTypeEnum;

require '../vendor/autoload.php';

$client = new \Promopult\YandexBusinessApi\Client(
new \Promopult\YandexBusinessApi\Config(getenv('__ACCESS_TOKEN__')),
new \GuzzleHttp\Client()
);

$campaign_client = new CampaignClient(
type: CampaignClientTypeEnum::LEGAL,
name: 'Зимина Виктория Романовна',
okveds: ['47.91.2'],
inn: '7727563778'
);
$campaign_contractor = new CampaignContractor(
type: CampaignContractorTypeEnum::PHYSICAL,
name: 'Данилова Василиса Викторовна',
inn: '588093656296',
phoneNum: '+7 (911) 222 22 21'
);

$contract = new CampaignContract(
type: \Promopult\YandexBusinessApi\Enum\CampaignContractTypeEnum::CONTRACT,
number: '123456789',
date: '2023-07-17',
amount: '200000',
isVat: true,
subjectType: CampaignContractSubjectTypeEnum::DISTRIBUTION,
);

$response = $client
->setCampaignBeneficiaryV5(getenv('__CAMPAIGN_ID__'), $campaign_client, $campaign_contractor, $contract);

var_dump($response);
60 changes: 60 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
namespace Promopult\YandexBusinessApi;

use GuzzleHttp\Psr7\Request;
use Promopult\YandexBusinessApi\Dto\CampaignBeneficiary;
use Promopult\YandexBusinessApi\Dto\CampaignClient;
use Promopult\YandexBusinessApi\Dto\CampaignContract;
use Promopult\YandexBusinessApi\Dto\CampaignContractor;
use Promopult\YandexBusinessApi\Exception\BusinessErrorException;
use Promopult\YandexBusinessApi\Exception\ServerErrorException;
use Psr\Http\Client\ClientExceptionInterface;
Expand Down Expand Up @@ -239,6 +243,62 @@ public function setCampaignBeneficiaryV4(
return json_decode($response->getBody()->__toString(), true);
}

/**
* Заполнение данных о рекламодателе
*
* @param int $campaignId Id рекламной кампании
* @param CampaignClient $campaign_client Данные конечного рекламодателя
* @param CampaignContractor $campaign_contractor Посредник
* @param CampaignContract $campaign_contract Договор между клиентом и посредником, обязательно если
*
* @return array
*/
public function setCampaignBeneficiaryV5(
int $campaignId,
CampaignClient $campaign_client,
CampaignContractor $campaign_contractor,
CampaignContract $campaign_contract
): array {
$body =[
'campaignId' => $campaignId,
'beneficiary' => [
'client'=>$campaign_client->toArray(),
'contractor'=>$campaign_contractor->toArray(),
'contract'=>$campaign_contract->toArray()
]
];

$response = $this->requestApi(
'POST',
'/priority/v5/campaign-beneficiary',
$body
);

return json_decode($response->getBody()->__toString(), true);
}

/**
* Получение данных о рекламодателе
*
* @param int $campaign_id Id рекламной кампании
*
* @return CampaignBeneficiary|null
*/
public function getCampaignBeneficiaryV5(int $campaign_id): ?CampaignBeneficiary
{
$response = $this->requestApi(
'GET',
'/priority/v5/get-campaign-beneficiary?campaignId='.$campaign_id
);

$content = json_decode($response->getBody()->__toString(), true);
if (empty($content['data'])){
return null;
}

return CampaignBeneficiary::fromArray($content['data']);
}

/**
* Бюджетный расчет
*
Expand Down
22 changes: 22 additions & 0 deletions src/Dto/CampaignBeneficiary.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Promopult\YandexBusinessApi\Dto;

class CampaignBeneficiary
{
public function __construct(
public CampaignClient $client,
public CampaignContractor $contractor,
public CampaignContract $contract
) {
}

public static function fromArray(array $data): self
{
return new self(
client: CampaignClient::fromArray($data['client']),
contractor: CampaignContractor::fromArray($data['contractor']),
contract: CampaignContract::fromArray($data['contract']),
);
}
}
39 changes: 39 additions & 0 deletions src/Dto/CampaignClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Promopult\YandexBusinessApi\Dto;

class CampaignClient
{
public function __construct(
public string $type,
public string $name,
public array $okveds,
public ?string $inn = null,
public ?string $phoneNum = null,
public ?string $epayNumber = null,
public ?string $oksmNumber = null,
public ?string $vat = null,
public ?string $regNumber = null,
) {
}

public static function fromArray(array $data): self
{
return new self(
type: $data['type'],
name: $data['name'],
okveds: $data['okveds'],
inn: $data['inn'] ?? null,
phoneNum: $data['phoneNum'] ?? null,
epayNumber: $data['epayNumber'] ?? null,
oksmNumber: $data['oksmNumber'] ?? null,
vat: $data['vat'] ?? null,
regNumber: $data['regNumber'] ?? null,
);
}

public function toArray(): array
{
return array_filter((array) $this);
}
}
35 changes: 35 additions & 0 deletions src/Dto/CampaignContract.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Promopult\YandexBusinessApi\Dto;

class CampaignContract
{
public function __construct(
public string $type,
public string $number,
public string $date,
public float $amount,
public bool $isVat,
public ?string $actionType = null,
public ?string $subjectType = null,
) {
}

public static function fromArray(array $data): self
{
return new self(
type: $data['type'],
number: $data['number'],
date: $data['date'],
amount: $data['amount'],
isVat: $data['isVat'],
actionType: $data['actionType'] ?? null,
subjectType: $data['subjectType'] ?? null,
);
}

public function toArray(): array
{
return array_filter((array) $this);
}
}
37 changes: 37 additions & 0 deletions src/Dto/CampaignContractor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Promopult\YandexBusinessApi\Dto;

class CampaignContractor
{
public function __construct(
public string $type,
public string $name,
public ?string $inn = null,
public ?string $phoneNum = null,
public ?string $epayNumber = null,
public ?string $oksmNumber = null,
public ?string $vat = null,
public ?string $regNumber = null,
) {
}

public static function fromArray(array $data): self
{
return new self(
type: $data['type'],
name: $data['name'],
inn: $data['inn'] ?? null,
phoneNum: $data['phoneNum'] ?? null,
epayNumber: $data['epayNumber'] ?? null,
oksmNumber: $data['oksmNumber'] ?? null,
vat: $data['vat'] ?? null,
regNumber: $data['regNumber'] ?? null,
);
}

public function toArray(): array
{
return array_filter((array) $this);
}
}
27 changes: 27 additions & 0 deletions src/Enum/CampaignClientTypeEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Promopult\YandexBusinessApi\Enum;

class CampaignClientTypeEnum
{
/**
* Иностранное юридическое лицо
*/
public const FOREIGN_LEGAL = 'FOREIGN_LEGAL';
/**
* Иностранное физическое лицо
*/
public const FOREIGN_PHYSICAL = 'FOREIGN_PHYSICAL';
/**
* ИП
*/
public const INDIVIDUAL = 'INDIVIDUAL';
/**
* Юридическое лицо
*/
public const LEGAL = 'LEGAL';
/**
* Физическое лицо
*/
public const PHYSICAL = 'PHYSICAL';
}
23 changes: 23 additions & 0 deletions src/Enum/CampaignContractActionTypeEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Promopult\YandexBusinessApi\Enum;

class CampaignContractActionTypeEnum
{
/**
* Действия в целях распространения рекламы
*/
public const DISTRIBUTION = 'distribution';
/**
* Заключение договоров
*/
public const CONCLUDE = 'conclude';
/**
* Коммерческое представительство
*/
public const COMMERCIAL = 'commercial';
/**
* Иное
*/
public const OTHER = 'other';
}
23 changes: 23 additions & 0 deletions src/Enum/CampaignContractSubjectTypeEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Promopult\YandexBusinessApi\Enum;

class CampaignContractSubjectTypeEnum
{
/**
* Договор на организацию распространения рекламы
*/
public const ORG_DISTRIBUTION = 'org-distribution';
/**
* Посредничество
*/
public const MEDIATION = 'mediation';
/**
* Договор на распространение рекламы
*/
public const DISTRIBUTION = 'distribution';
/**
* Иное
*/
public const OTHER = 'other';
}
15 changes: 15 additions & 0 deletions src/Enum/CampaignContractTypeEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Promopult\YandexBusinessApi\Enum;

class CampaignContractTypeEnum
{
/**
* Договор оказания услуг
*/
public const CONTRACT = 'contract';
/**
* Посреднический договор
*/
public const INTERMEDIARY_CONTRACT = 'intermediary-contract';
}
27 changes: 27 additions & 0 deletions src/Enum/CampaignContractorTypeEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Promopult\YandexBusinessApi\Enum;

class CampaignContractorTypeEnum
{
/**
* Иностранное юридическое лицо
*/
public const FOREIGN_LEGAL = 'FOREIGN_LEGAL';
/**
* Иностранное физическое лицо
*/
public const FOREIGN_PHYSICAL = 'FOREIGN_PHYSICAL';
/**
* ИП
*/
public const INDIVIDUAL = 'INDIVIDUAL';
/**
* Юридическое лицо
*/
public const LEGAL = 'LEGAL';
/**
* Физическое лицо
*/
public const PHYSICAL = 'PHYSICAL';
}

0 comments on commit 2ddcd84

Please sign in to comment.