<?php
namespace App\Application\Services;
use App\Models\ApiKey;
use App\Models\Merchant;
use Illuminate\Support\Str;
final class ApiCredentialService { public function issue(Merchant $merchant,string $environment,array $scopes):array { $public=($environment==='live'?'pk_live_':'pk_test_').Str::random(32); $secret=($environment==='live'?'sk_live_':'sk_test_').Str::random(48); $model=$merchant->apiKeys()->create(['key_prefix'=>substr($public,0,16),'public_key_hash'=>hash('sha256',$public),'secret_ciphertext'=>$secret,'secret_kid'=>env('AWS_KMS_KEY_ID','local-app-key'),'scopes'=>$scopes,'environment'=>$environment,'status'=>'active']); return ['api_key'=>$model,'public_key'=>$public,'secret'=>$secret]; } }
