Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ composer.phar
.phpunit.result.cache
test/unit/_html

PrivateKey.key
PrivateKey.key
BitPay.config.json
**/BitPay.config.json
BitPay.config.yml
**/BitPay.config.yml
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"ext-json": "*",
"ext-reflection": "*",
"bitpay/key-utils": "^2.1",
"guzzlehttp/guzzle": "^7.0",
"symfony/yaml": "^5.0 || ^6.0 || ^7.0",
"guzzlehttp/guzzle": "^7.9",
"symfony/yaml": "^5.4 || ^6.4 || ^7.0",
"netresearch/jsonmapper": "^5.0",
"symfony/console": "^4.4 || ^5.4 || ^6.0"
"symfony/console": "^4.4 || ^5.4 || ^6.4"
},
"authors": [
{
Expand All @@ -28,7 +28,8 @@
}
],
"require-dev": {
"phpunit/phpunit": "^10.5 || ^11.5 || ^12.0"
"phpunit/phpunit": "^10.5 || ^11.5 || ^12.0",
"squizlabs/php_codesniffer": "^3.13"
},
"scripts": {
"setup": [
Expand All @@ -47,4 +48,4 @@
"BitPaySDK\\Functional\\": "test/functional/BitPaySDK"
}
}
}
}
138 changes: 115 additions & 23 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
<ruleset name="BitPayStandard">
<description>BitPay coding standard, based on PSR-12, temporarily excluding some rules.</description>
<rule ref="PSR12"/>
<exclude-pattern>*/vendor/*</exclude-pattern>
<exclude-pattern>*/node_modules/*</exclude-pattern>
<exclude-pattern>*.css</exclude-pattern>
<exclude-pattern>*.js</exclude-pattern>
</ruleset>
23 changes: 23 additions & 0 deletions test/functional/BitPaySDK/AbstractClientTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,36 @@ abstract class AbstractClientTestCase extends TestCase
{
protected Client $client;

// Default delay in seconds between API calls
private const API_CALL_DELAY = 0.5;
private static $lastApiCallTime = 0;

/**
* @throws BitPayGenericException
*/
public function setUp(): void
{
// Add delay to respect rate limits
$this->respectRateLimit();

$this->client = Client::createWithFile(
Config::FUNCTIONAL_TEST_PATH . DIRECTORY_SEPARATOR . Config::BITPAY_CONFIG_FILE
);
}

/**
* Delays execution if needed to respect rate limits
*/
protected function respectRateLimit(): void
{
$currentTime = microtime(true);
$timeSinceLastCall = $currentTime - self::$lastApiCallTime;

if (self::$lastApiCallTime > 0 && $timeSinceLastCall < self::API_CALL_DELAY) {
$sleepTime = (self::API_CALL_DELAY - $timeSinceLastCall);
usleep((int)($sleepTime * 1000000)); // Convert to microseconds
}

self::$lastApiCallTime = microtime(true);
}
}
34 changes: 29 additions & 5 deletions test/functional/BitPaySDK/SettlementsClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ public function testGetSettlement(): void

$settlements = $this->client->getSettlements($currency, $dateStart, $dateEnd, $status);

// Skip test if no settlements exist
if (empty($settlements)) {
error_log(PHP_EOL . 'No settlements found in test account. ' .
'Skipping test. To test this functionality, ensure your test account has processed transactions.');
$this->markTestSkipped(
'No settlements found in test account. ' .
'To test this functionality, ensure your test account has processed transactions.'
);
return;
}

$settlement = $this->client->getSettlement($settlements[0]->getId());

self::assertNotNull($settlement);
Expand All @@ -50,12 +61,25 @@ public function testGetReconciliationReport(): void
$currency = 'USD';

$settlements = $this->client->getSettlements($currency, $dateStart, $dateEnd, $status);

if (empty($settlements)) {
error_log( PHP_EOL . 'No settlements found in test account. ' .
'Skipping test. To test this functionality, ensure your test account has processed transactions.
');
$this->markTestSkipped(
'No settlements found in test account. ' .
'To test this functionality, ensure your test account has processed transactions.'
);
return;
}

$settlement = $this->client->getSettlement($settlements[0]->getId());
$settlement = $this->client->getSettlementReconciliationReport($settlement);
$settlementId = $settlement->getId();
$token = $settlement->getToken();
$reconciliationReport = $this->client->getSettlementReconciliationReport($settlementId, $token);

self::assertEquals('processing', $settlement->getStatus());
self::assertNotNull($settlement);
self::assertEquals('USD', $settlement->getCurrency());
self::assertEquals($status, $settlement->getStatus());
self::assertNotNull($reconciliationReport);
self::assertEquals($currency, $reconciliationReport->getCurrency());
self::assertEquals($status, $reconciliationReport->getStatus());
}
}