Skip to content

Commit

Permalink
Add wallet history request
Browse files Browse the repository at this point in the history
  • Loading branch information
devkassacom committed Jan 15, 2025
1 parent b8739c4 commit eda41f1
Show file tree
Hide file tree
Showing 5 changed files with 222 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.9.4 - January 2025

- Add wallet history request

## 1.9.3 - July 2024

- Add `sbp_oper_id` for payout method response
Expand Down
33 changes: 31 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
use KassaCom\SDK\Model\Request\Reports\PayoutsReportRequest;
use KassaCom\SDK\Model\Request\Reports\PayoutsReportSerializer;
use KassaCom\SDK\Model\Request\Reports\PayoutsReportTransport;
use KassaCom\SDK\Model\Request\Reports\WalletHistoryReportRequest;
use KassaCom\SDK\Model\Request\Reports\WalletHistoryReportSerializer;
use KassaCom\SDK\Model\Request\Reports\WalletHistoryReportTransport;
use KassaCom\SDK\Model\Request\Subscription\GetSubscriptionRequest;
use KassaCom\SDK\Model\Request\Subscription\GetSubscriptionSerializer;
use KassaCom\SDK\Model\Request\Subscription\GetSubscriptionTransport;
Expand All @@ -92,7 +95,7 @@

class Client
{
const VERSION = '1.9.3';
const VERSION = '1.9.4';

/** @var AbstractApiTransport */
private $apiTransport;
Expand Down Expand Up @@ -431,7 +434,7 @@ public function getPayoutsReport($payoutsReport)
$payoutsReportTransport = new PayoutsReportTransport($payoutsReportSerializer);

$filename = [];
$filename[] = '$payouts_report';
$filename[] = 'payouts_report';
$filename[] = $payoutsReport->getDatetimeFrom()->format('Y-m-d-H-i-s');
$filename[] = '_';
$filename[] = $payoutsReport->getDatetimeTo()->format('Y-m-d-H-i-s');
Expand All @@ -440,6 +443,32 @@ public function getPayoutsReport($payoutsReport)
return $this->download($payoutsReportTransport, join($filename));
}

/**
* @param array|WalletHistoryReportRequest $walletHistoryReport
*
* @return Psr7\MessageTrait
* @throws TransportException
*/
public function getWalletHistoryReport($walletHistoryReport)
{
if (!($walletHistoryReport instanceof WalletHistoryReportRequest)) {
$walletHistoryReport = RequestCreator::create(WalletHistoryReportRequest::class, $walletHistoryReport);
}

ObjectRecursiveValidator::validate($walletHistoryReport);
$walletHistorySerializer = new WalletHistoryReportSerializer($walletHistoryReport);
$walletHistoryTransport = new WalletHistoryReportTransport($walletHistorySerializer);

$filename = [];
$filename[] = 'wallet_history_report';
$filename[] = $walletHistoryReport->getDatetimeFrom()->format('Y-m-d-H-i-s');
$filename[] = '_';
$filename[] = $walletHistoryReport->getDatetimeTo()->format('Y-m-d-H-i-s');
$filename[] = '.csv';

return $this->download($walletHistoryTransport, join($filename));
}

/**
* @param string|WalletRequest $walletRequest
*
Expand Down
126 changes: 126 additions & 0 deletions src/Model/Request/Reports/WalletHistoryReportRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?php

namespace KassaCom\SDK\Model\Request\Reports;


use KassaCom\SDK\Model\Request\AbstractRequest;
use KassaCom\SDK\Model\Traits\RecursiveRestoreTrait;

class WalletHistoryReportRequest extends AbstractRequest
{
use RecursiveRestoreTrait;

/**
* Начала периода, в формате datetime
*
* @var \DateTime
*/
private $datetimeFrom;

/**
* Завершение периода, в формате datetime
*
* @var \DateTime
*/
private $datetimeTo;

/**
* Идентификатор кошелька
*
* @var integer
*/
private $walletId;

/**
* Фильтр по типам записей в истории.
*
* @var array|null
*/
private $operationType;

/**
* @return \DateTime
*/
public function getDatetimeFrom()
{
return $this->datetimeFrom;
}

/**
* @param \DateTime $datetimeFrom
*/
public function setDatetimeFrom($datetimeFrom)
{
$this->datetimeFrom = $datetimeFrom;
}

/**
* @return \DateTime
*/
public function getDatetimeTo()
{
return $this->datetimeTo;
}

/**
* @param \DateTime $datetimeTo
*/
public function setDatetimeTo($datetimeTo)
{
$this->datetimeTo = $datetimeTo;
}

/**
* @return int
*/
public function getWalletId()
{
return $this->walletId;
}

/**
* @param int $walletId
*/
public function setWalletId($walletId)
{
$this->walletId = $walletId;
}

/**
* @return array|null
*/
public function getOperationType()
{
return $this->operationType;
}

/**
* @param array|null $operationType
*/
public function setOperationType($operationType)
{
$this->operationType = $operationType;
}

/**
* @inheritDoc
*/
public function getRequiredFields()
{
return [
'datetime_from' => self::TYPE_DATE,
'datetime_to' => self::TYPE_DATE,
'wallet_id' => self::TYPE_INTEGER,
];
}

/**
* @inheritDoc
*/
public function getOptionalFields()
{
return [
'operation_type' => [self::TYPE_STRING],
];
}
}
29 changes: 29 additions & 0 deletions src/Model/Request/Reports/WalletHistoryReportSerializer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace KassaCom\SDK\Model\Request\Reports;

use KassaCom\SDK\Model\Request\AbstractRequestSerializer;

class WalletHistoryReportSerializer extends AbstractRequestSerializer
{
/**
* @inheritDoc
*/
public function getSerializedData()
{
/** @var WalletHistoryReportRequest $request */
$request = $this->request;

$data = [
'datetime_from' => $request->getDatetimeFrom()->format('c'),
'datetime_to' => $request->getDatetimeTo()->format('c'),
'wallet_id' => $request->getWalletId(),
];

if ($request->getOperationType() !== null) {
$data['operation_type'] = $request->getOperationType();
}

return $data;
}
}
32 changes: 32 additions & 0 deletions src/Model/Request/Reports/WalletHistoryReportTransport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace KassaCom\SDK\Model\Request\Reports;

use KassaCom\SDK\Model\Request\AbstractRequestTransport;
use KassaCom\SDK\Transport\AbstractApiTransport;

class WalletHistoryReportTransport extends AbstractRequestTransport
{
const PATH = 'report/wallet/registry.csv';

/**
* @inheritDoc
*/
public function getPath()
{
return self::PATH;
}

/**
* @inheritDoc
*/
public function getMethod()
{
return AbstractApiTransport::METHOD_GET;
}

public function getBodyForRequest()
{
return $this->getBody();
}
}

0 comments on commit eda41f1

Please sign in to comment.