Updates for piste

This commit is contained in:
David Bomba 2024-01-01 17:21:52 +11:00
parent da0117bfa9
commit f85ed1131c

View File

@ -26,7 +26,7 @@ class Piste
private bool $test_mode = false; private bool $test_mode = false;
public function __construct() public function __construct(private string $username, private string $password)
{ {
} }
@ -40,11 +40,11 @@ class Piste
private function oauthHeaders(): array private function oauthHeaders(): array
{ {
return [ return [
'grant_type' => 'client_credentials', 'grant_type' => 'client_credentials',
'client_id' => config('services.chorus.client_id'), 'client_id' => config('services.chorus.client_id'),
'client_secret' => config('services.chorus.secret'), 'client_secret' => config('services.chorus.secret'),
'scope' => 'openid' 'scope' => 'openid profile'
]; ];
} }
private function oauthUrl(): string private function oauthUrl(): string
@ -68,21 +68,29 @@ class Piste
return null; return null;
} }
public function startOauthFlow() public function execute(string $uri, array $data = [])
{ {
$access_token = $this->getOauthAccessToken(); $access_token = $this->getOauthAccessToken();
Http::withToken($access_token)->post($this->apiUrl() . '/cpro/factures/v1/deposer/flux', [ nlog($access_token);
nlog($this->username);
'base_uri' => $this->apiUrl(), nlog($this->password);
'allow_redirects' => true, nlog(base64_encode($this->username . ':' . $this->password));
'headers' => [
'cpro-account' => base64_encode($username . ':' . $password),
'Content-Type' => 'application/json;charset=utf-8',
'Accept' => 'application/json;charset=utf-8'
]
]);
$r = Http::withToken($access_token)
->withHeaders([
'cpro-account' => base64_encode($this->username . ':' . $this->password),
'Content-Type' => 'application/json;charset=utf-8',
'Accept' => 'application/json;charset=utf-8'
])
->post($this->apiUrl() . '/cpro/factures/'. $uri, $data);
nlog($r);
nlog($r->json());
nlog($r->successful());
nlog($r->body());
nlog($r->collect());
return $r;
} }
} }