From 112d5377885a1807b30a4f6ed093d8b53beadd13 Mon Sep 17 00:00:00 2001 From: rebilly-machine-user Date: Fri, 24 Nov 2023 15:31:53 +0000 Subject: [PATCH] update SDK from api-definitions --- .changeset/fluffy-hotels-worry.md | 5 ++ src/Api/ReportsApi.php | 29 ++++++ src/Model/ReportDeclinedTransactions.php | 84 +++++++++++++++++ src/Model/ReportDeclinedTransactionsData.php | 95 ++++++++++++++++++++ 4 files changed, 213 insertions(+) create mode 100644 .changeset/fluffy-hotels-worry.md create mode 100644 src/Model/ReportDeclinedTransactions.php create mode 100644 src/Model/ReportDeclinedTransactionsData.php diff --git a/.changeset/fluffy-hotels-worry.md b/.changeset/fluffy-hotels-worry.md new file mode 100644 index 000000000..f137615d9 --- /dev/null +++ b/.changeset/fluffy-hotels-worry.md @@ -0,0 +1,5 @@ +--- +"@rebilly/client-php": patch +--- + +feat(experimental): Add declined transactions report Rebilly/api-definitions#1570 diff --git a/src/Api/ReportsApi.php b/src/Api/ReportsApi.php index 3b767d04e..4576be76f 100644 --- a/src/Api/ReportsApi.php +++ b/src/Api/ReportsApi.php @@ -25,6 +25,7 @@ use Rebilly\Sdk\Model\FutureRenewals; use Rebilly\Sdk\Model\GetKycAcceptanceSummaryResponse; use Rebilly\Sdk\Model\RenewalSales; +use Rebilly\Sdk\Model\ReportDeclinedTransactions; use Rebilly\Sdk\Model\ReportDisputeDelays; use Rebilly\Sdk\Model\ReportDisputes; use Rebilly\Sdk\Model\ReportEventsTriggeredSummary; @@ -154,6 +155,34 @@ public function getDccMarkup( return DccMarkup::from($data); } + /** + * @return ReportDeclinedTransactions + */ + public function getDeclinedTransactions( + string $aggregationField, + DateTimeImmutable $periodStart, + DateTimeImmutable $periodEnd, + ?int $limit = null, + ?int $offset = null, + ?string $filter = null, + ): ReportDeclinedTransactions { + $queryParams = [ + 'aggregationField' => $aggregationField, + 'periodStart' => $periodStart->format('Y-m-d\TH:i:s\Z'), + 'periodEnd' => $periodEnd->format('Y-m-d\TH:i:s\Z'), + 'limit' => $limit, + 'offset' => $offset, + 'filter' => $filter, + ]; + $uri = '/experimental/reports/declined-transactions?' . http_build_query($queryParams); + + $request = new Request('GET', $uri); + $response = $this->client->send($request); + $data = Utils::jsonDecode((string) $response->getBody(), true); + + return ReportDeclinedTransactions::from($data); + } + /** * @return ReportDisputes */ diff --git a/src/Model/ReportDeclinedTransactions.php b/src/Model/ReportDeclinedTransactions.php new file mode 100644 index 000000000..226bc0ac6 --- /dev/null +++ b/src/Model/ReportDeclinedTransactions.php @@ -0,0 +1,84 @@ +setTotalCount($data['totalCount']); + } + if (array_key_exists('data', $data)) { + $this->setData($data['data']); + } + } + + public static function from(array $data = []): self + { + return new self($data); + } + + public function getTotalCount(): ?int + { + return $this->fields['totalCount'] ?? null; + } + + public function setTotalCount(null|int $totalCount): static + { + $this->fields['totalCount'] = $totalCount; + + return $this; + } + + /** + * @return null|ReportDeclinedTransactionsData[] + */ + public function getData(): ?array + { + return $this->fields['data'] ?? null; + } + + /** + * @param null|array[]|ReportDeclinedTransactionsData[] $data + */ + public function setData(null|array $data): static + { + $data = $data !== null ? array_map( + fn ($value) => $value !== null ? ($value instanceof ReportDeclinedTransactionsData ? $value : ReportDeclinedTransactionsData::from($value)) : null, + $data, + ) : null; + + $this->fields['data'] = $data; + + return $this; + } + + public function jsonSerialize(): array + { + $data = []; + if (array_key_exists('totalCount', $this->fields)) { + $data['totalCount'] = $this->fields['totalCount']; + } + if (array_key_exists('data', $this->fields)) { + $data['data'] = $this->fields['data']; + } + + return $data; + } +} diff --git a/src/Model/ReportDeclinedTransactionsData.php b/src/Model/ReportDeclinedTransactionsData.php new file mode 100644 index 000000000..82b2dfff6 --- /dev/null +++ b/src/Model/ReportDeclinedTransactionsData.php @@ -0,0 +1,95 @@ +setMessage($data['message']); + } + if (array_key_exists('count', $data)) { + $this->setCount($data['count']); + } + if (array_key_exists('percentage', $data)) { + $this->setPercentage($data['percentage']); + } + } + + public static function from(array $data = []): self + { + return new self($data); + } + + public function getMessage(): ?string + { + return $this->fields['message'] ?? null; + } + + public function setMessage(null|string $message): static + { + $this->fields['message'] = $message; + + return $this; + } + + public function getCount(): ?int + { + return $this->fields['count'] ?? null; + } + + public function setCount(null|int $count): static + { + $this->fields['count'] = $count; + + return $this; + } + + public function getPercentage(): ?float + { + return $this->fields['percentage'] ?? null; + } + + public function setPercentage(null|float|string $percentage): static + { + if (is_string($percentage)) { + $percentage = (float) $percentage; + } + + $this->fields['percentage'] = $percentage; + + return $this; + } + + public function jsonSerialize(): array + { + $data = []; + if (array_key_exists('message', $this->fields)) { + $data['message'] = $this->fields['message']; + } + if (array_key_exists('count', $this->fields)) { + $data['count'] = $this->fields['count']; + } + if (array_key_exists('percentage', $this->fields)) { + $data['percentage'] = $this->fields['percentage']; + } + + return $data; + } +}