61 lines
2.1 KiB
PHP
61 lines
2.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require_once __DIR__ . '/vendor/autoload.php';
|
|
|
|
use Apoloz\AlfaBank\AlfaBank;
|
|
use Apoloz\AlfaBank\Requests\Auth\RefreshClientSecretRequest;
|
|
use Apoloz\AlfaBank\Enums\Environment;
|
|
|
|
/**
|
|
* UTILITY SCRIPT: Generate a Client Secret using your TLS certificates.
|
|
*
|
|
* Run this ONCE when setting up the project or if you lose your secret.
|
|
*
|
|
* Requirements:
|
|
* 1. You have the `client_id` (Found in Developer Portal -> App Settings URL or Overview).
|
|
* 2. You have the TLS certificates (.pem/.key) authorized by the bank.
|
|
* - Prod: You sent CSR to bank, they enabled integration and sent .cer back.
|
|
* - Sandbox: You downloaded them from the email/portal.
|
|
*/
|
|
|
|
// 1. Configuration
|
|
$certPath = __DIR__ . '/certs/transport.crt'; // Your mTLS certificate
|
|
$keyPath = __DIR__ . '/certs/transport.key'; // Your mTLS private key
|
|
$clientId = 'YOUR_CLIENT_ID_UUID'; // E.g. '0cee0683-85ae-...'
|
|
|
|
// 2. Initialize Connector (No Login required yet)
|
|
$baas = AlfaBank::baas(
|
|
certificatePath: $certPath,
|
|
privateKeyPath: $keyPath,
|
|
environment: Environment::SANDBOX // Change to PRODUCTION for real usage
|
|
);
|
|
|
|
try {
|
|
echo "Requesting new Client Secret for Client ID: {$clientId}...\n";
|
|
|
|
// 3. Send Request
|
|
$request = new RefreshClientSecretRequest($clientId);
|
|
$response = $baas->send($request);
|
|
|
|
// 4. Output Result
|
|
$data = $response->dto(); // Returns ClientSecretData
|
|
|
|
echo "\n-------------------------------------------------------\n";
|
|
echo "SUCCESS! New Client Secret Generated:\n";
|
|
echo "-------------------------------------------------------\n";
|
|
echo "Client ID: " . $data->clientId . "\n";
|
|
echo "Client Secret: " . $data->clientSecret . "\n";
|
|
echo "-------------------------------------------------------\n";
|
|
echo "IMPORTANT: Save this to your .env file immediately.\n";
|
|
echo "It will not be shown again.\n";
|
|
|
|
} catch (\Exception $e) {
|
|
echo "\nERROR: Could not generate secret.\n";
|
|
echo "Message: " . $e->getMessage() . "\n";
|
|
if (method_exists($e, 'getResponse')) {
|
|
echo "Response: " . $e->getResponse()->body() . "\n";
|
|
}
|
|
}
|