-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathTalerSandboxE2E.php
More file actions
81 lines (62 loc) · 2.94 KB
/
Copy pathTalerSandboxE2E.php
File metadata and controls
81 lines (62 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
namespace Fleetbase\Ledger\Console\Commands;
use Fleetbase\Ledger\Gateways\TalerDriver;
use Illuminate\Console\Command;
class TalerSandboxE2E extends Command
{
protected $signature = 'ledger:taler:e2e
{--amount=1 : Amount in the smallest currency unit}
{--currency=KUDOS : Taler sandbox currency}';
protected $description = 'Run the opt-in GNU Taler sandbox E2E bootstrap flow.';
public function handle(): int
{
if (!filter_var($this->environment('TALER_E2E_ENABLED', false), FILTER_VALIDATE_BOOLEAN)) {
$this->warn('[Ledger/Taler] E2E skipped. Set TALER_E2E_ENABLED=true to run against a live sandbox.');
return self::SUCCESS;
}
$backendUrl = $this->environment('TALER_E2E_BACKEND_URL');
$instanceId = $this->environment('TALER_E2E_INSTANCE_ID', 'default');
$apiToken = $this->environment('TALER_E2E_API_TOKEN');
if (!$backendUrl || !$apiToken) {
$this->error('[Ledger/Taler] TALER_E2E_BACKEND_URL and TALER_E2E_API_TOKEN are required.');
return self::FAILURE;
}
$driver = app(TalerDriver::class)->initialize([
'backend_url' => $backendUrl,
'instance_id' => $instanceId,
'api_token' => $apiToken,
], true);
$credentials = $driver->testCredentials();
if (!($credentials['ok'] ?? false)) {
$this->error('[Ledger/Taler] Credential check failed: ' . ($credentials['message'] ?? 'unknown error'));
return self::FAILURE;
}
$response = $driver->createTestOrder([
'amount' => (int) $this->option('amount'),
'currency' => strtoupper((string) $this->option('currency')),
'description' => 'Ledger GNU Taler sandbox E2E order',
'metadata' => [
'company_uuid' => $this->environment('TALER_E2E_COMPANY_UUID'),
'e2e' => true,
],
]);
if ($response->isFailed()) {
$this->error('[Ledger/Taler] Test order creation failed: ' . $response->message);
return self::FAILURE;
}
$this->info('[Ledger/Taler] Sandbox E2E test order created.');
$this->line('Order ID: ' . $response->gatewayTransactionId);
$this->line('Payment URI: ' . ($response->data['taler_pay_uri'] ?? 'n/a'));
$this->line('Next: complete the wallet payment, then run webhook/settlement verification and record the evidence in docs/taler/release-evidence.md.');
return self::SUCCESS;
}
/**
* Read opt-in E2E configuration without requiring Laravel's Dotenv
* repository to be bootstrapped by the console test harness.
*/
protected function environment(string $key, mixed $default = null): mixed
{
$value = $_ENV[$key] ?? $_SERVER[$key] ?? getenv($key);
return $value === false ? $default : $value;
}
}