-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PHPSDK-94: Add support to list transactions (#291)
- Loading branch information
Showing
9 changed files
with
412 additions
and
0 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
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,66 @@ | ||
<?php declare(strict_types=1); | ||
/** | ||
* Copyright © 2022 MultiSafepay, Inc. All rights reserved. | ||
* See DISCLAIMER.md for disclaimer details. | ||
*/ | ||
|
||
namespace MultiSafepay\Api\Pager; | ||
|
||
/** | ||
* Class Cursor | ||
* | ||
* @package MultiSafepay\Api\Pager | ||
*/ | ||
class Cursor | ||
{ | ||
public const AFTER_NAME = 'after'; | ||
public const BEFORE_NAME = 'before'; | ||
|
||
/** | ||
* @var string|null | ||
*/ | ||
private $after; | ||
|
||
/** | ||
* @var string|null | ||
*/ | ||
private $before; | ||
|
||
/** | ||
* Pager constructor. | ||
* | ||
* @param array $data | ||
*/ | ||
public function __construct(array $data) | ||
{ | ||
$this->after = $data[self::AFTER_NAME] ?? null; | ||
$this->before = $data[self::BEFORE_NAME] ?? null; | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public function getData(): array | ||
{ | ||
return [ | ||
self::AFTER_NAME => $this->getAfter(), | ||
self::BEFORE_NAME => $this->getBefore(), | ||
]; | ||
} | ||
|
||
/** | ||
* @return string|null | ||
*/ | ||
public function getAfter() | ||
{ | ||
return $this->after; | ||
} | ||
|
||
/** | ||
* @return string|null | ||
*/ | ||
public function getBefore() | ||
{ | ||
return $this->before; | ||
} | ||
} |
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,98 @@ | ||
<?php declare(strict_types=1); | ||
/** | ||
* Copyright © 2022 MultiSafepay, Inc. All rights reserved. | ||
* See DISCLAIMER.md for disclaimer details. | ||
*/ | ||
|
||
namespace MultiSafepay\Api\Pager; | ||
|
||
/** | ||
* Class Pager | ||
* | ||
* @package MultiSafepay\Api\Pager | ||
*/ | ||
class Pager | ||
{ | ||
public const AFTER_NAME = 'after'; | ||
public const BEFORE_NAME = 'before'; | ||
public const LIMIT_NAME = 'limit'; | ||
public const CURSOR_NAME = 'cursor'; | ||
|
||
/** | ||
* @var string|null | ||
*/ | ||
private $after; | ||
|
||
/** | ||
* @var string|null | ||
*/ | ||
private $before; | ||
|
||
/** | ||
* @var int|null | ||
*/ | ||
private $limit; | ||
|
||
/** | ||
* @var Cursor | ||
*/ | ||
private $cursor; | ||
|
||
/** | ||
* Pager constructor. | ||
* | ||
* @param array $data | ||
*/ | ||
public function __construct(array $data) | ||
{ | ||
$this->after = $data[self::AFTER_NAME] ?? null; | ||
$this->before = $data[self::BEFORE_NAME] ?? null; | ||
$this->limit = $data[self::LIMIT_NAME] ?? null; | ||
$this->cursor = new Cursor($data[self::CURSOR_NAME] ?? []); | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public function getData(): array | ||
{ | ||
return [ | ||
self::AFTER_NAME => $this->getAfter(), | ||
self::BEFORE_NAME => $this->getBefore(), | ||
self::LIMIT_NAME => $this->getLimit(), | ||
self::CURSOR_NAME => $this->getCursor()->getData(), | ||
]; | ||
} | ||
|
||
/** | ||
* @return string|null | ||
*/ | ||
public function getAfter() | ||
{ | ||
return $this->after; | ||
} | ||
|
||
/** | ||
* @return string|null | ||
*/ | ||
public function getBefore() | ||
{ | ||
return $this->before; | ||
} | ||
|
||
/** | ||
* @return int|null | ||
*/ | ||
public function getLimit() | ||
{ | ||
return $this->limit; | ||
} | ||
|
||
/** | ||
* @return Cursor | ||
*/ | ||
public function getCursor(): Cursor | ||
{ | ||
return $this->cursor; | ||
} | ||
} |
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,54 @@ | ||
<?php declare(strict_types=1); | ||
/** | ||
* Copyright © 2019 MultiSafepay, Inc. All rights reserved. | ||
* See DISCLAIMER.md for disclaimer details. | ||
*/ | ||
|
||
namespace MultiSafepay\Api\Transactions; | ||
|
||
use MultiSafepay\Api\Pager\Pager; | ||
|
||
class TransactionListing | ||
{ | ||
/** @var array */ | ||
private $transactions; | ||
|
||
/** @var Pager */ | ||
private $pager; | ||
|
||
/** | ||
* TransactionListing constructor. | ||
* @param array $data | ||
* @param Pager|null $pager | ||
*/ | ||
public function __construct(array $data, Pager $pager = null) | ||
{ | ||
$transactions = []; | ||
if (!empty($data)) { | ||
foreach ($data as $transactionData) { | ||
$transactions[] = new TransactionResponse($transactionData, json_encode($transactionData)); | ||
} | ||
} | ||
$this->transactions = $transactions; | ||
|
||
if (isset($pager)) { | ||
$this->pager = $pager; | ||
} | ||
} | ||
|
||
/** | ||
* @return TransactionResponse[] | ||
*/ | ||
public function getTransactions(): array | ||
{ | ||
return $this->transactions; | ||
} | ||
|
||
/** | ||
* @return Pager|null | ||
*/ | ||
public function getPager(): ?Pager | ||
{ | ||
return $this->pager ?? null; | ||
} | ||
} |
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,31 @@ | ||
<?php declare(strict_types=1); | ||
/** | ||
* Copyright © 2022 MultiSafepay, Inc. All rights reserved. | ||
* See DISCLAIMER.md for disclaimer details. | ||
*/ | ||
|
||
namespace MultiSafepay\Tests\Unit\Api\Pager; | ||
|
||
use MultiSafepay\Api\Pager\Cursor; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class CursorTest extends TestCase | ||
{ | ||
/** | ||
* Test whether the after string could be fetched | ||
*/ | ||
public function testGetAfter(): void | ||
{ | ||
$testCursor = new Cursor(['after' => '12345', 'before' => '54321']); | ||
$this->assertEquals('12345', $testCursor->getAfter()); | ||
} | ||
|
||
/** | ||
* Test whether the before string could be fetched | ||
*/ | ||
public function testGetBefore(): void | ||
{ | ||
$testCursor = new Cursor(['after' => '12345', 'before' => '54321']); | ||
$this->assertEquals('54321', $testCursor->getBefore()); | ||
} | ||
} |
Oops, something went wrong.