refactor(core): enhance SDK structure and documentation

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
2026-01-18 21:48:25 +03:00
parent 3da69c03e1
commit d214eecebe
378 changed files with 10514 additions and 496 deletions

49
examples/05_webhooks.php Normal file
View File

@@ -0,0 +1,49 @@
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use Apoloz\AlfaBank\AlfaBank;
use Apoloz\AlfaBank\Webhooks\WebhookFactory;
use Apoloz\AlfaBank\Requests\Webhooks\GetWebhooksRequest;
use Apoloz\AlfaBank\Requests\Webhooks\CreateWebhookRequest;
use Apoloz\AlfaBank\Data\Webhooks\Subscriptions\WebhookSubscriptionRequestData;
/**
* 1. Managing Webhooks (BaaS API)
*/
$baas = AlfaBank::baas('cert.pem', 'key.pem');
$baas->login('id', 'secret');
// List existing webhooks
$response = $baas->send(new GetWebhooksRequest());
$webhooks = $response->dto(); // DataCollection of WebhookSubscriptionData
foreach ($webhooks as $webhook) {
echo "Webhook ID: {$webhook->id}, URL: {$webhook->callbackUri}\n";
}
// Create new webhook
$data = new WebhookSubscriptionRequestData('https://your-app.com/webhooks/alfa', ['transactions']);
$baas->send(new CreateWebhookRequest($data));
/**
* 2. Parsing incoming webhook payload (Webhook Controller logic)
*/
$rawPayload = [
[
'actionType' => 'create',
'eventTime' => '2023-10-27T10:00:00Z',
'object' => 'ul_transaction_default',
'data' => [
'transactionId' => 'TX-12345',
'amount' => ['amount' => 100.50, 'currencyName' => 'RUR'],
'direction' => 'CREDIT',
'paymentPurpose' => 'Test payment'
]
]
];
// Use the factory to parse the payload into a DTO
$webhookDto = WebhookFactory::create($rawPayload);
echo "Received Webhook: {$webhookDto->object} ({$webhookDto->actionType})\n";