Penambahan thema pada Menu Laporan per pintu pos

This commit is contained in:
pand03
2026-04-16 17:38:48 +07:00
parent 67f6604f89
commit c73adb3c6b
8 changed files with 652 additions and 118 deletions

View File

@@ -0,0 +1,69 @@
<?php
namespace App\Services;
use Illuminate\Support\Facades\Http;
class BcaService
{
protected $apiKey;
protected $apiSecret;
protected $baseUrl = 'https://sandbox.bca.co.id';
public function __construct()
{
$this->apiKey = env('BCA_API_KEY');
$this->apiSecret = env('BCA_API_SECRET');
}
public function getAccessToken()
{
$response = Http::asForm()
->withBasicAuth($this->apiKey, $this->apiSecret)
->post($this->baseUrl . '/api/oauth/token', [
'grant_type' => 'client_credentials'
]);
return $response->json()['access_token'];
}
private function generateSignature($method, $relativeUrl, $token, $body, $timestamp)
{
$bodyHash = hash('sha256', $body);
$stringToSign = strtoupper($method) . ':' .
$relativeUrl . ':' .
$token . ':' .
strtolower($bodyHash) . ':' .
$timestamp;
return hash_hmac('sha256', $stringToSign, $this->apiSecret);
}
public function getAccount($corporateId, $accountNumber)
{
$token = $this->getAccessToken();
$method = 'GET';
$relativeUrl = "/banking/v3/corporates/$corporateId/accounts/$accountNumber";
$timestamp = now()->format('Y-m-d\TH:i:s.vP');
$body = '';
$signature = $this->generateSignature(
$method,
$relativeUrl,
$token,
$body,
$timestamp
);
$response = Http::withHeaders([
'Authorization' => 'Bearer ' . $token,
'X-BCA-Key' => $this->apiKey,
'X-BCA-Timestamp' => $timestamp,
'X-BCA-Signature' => $signature,
])->get($this->baseUrl . $relativeUrl);
return $response->json();
}
}