feat: enhance Telepagos integration with token refresh handling and refactor CheckoutService to use updateOrCreate for purchases
This commit is contained in:
@@ -106,6 +106,29 @@ class TelepagosIntegrationService extends BaseIntegrationService
|
||||
return $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a request to Telepagos, handling 401 Unauthorized for token refresh.
|
||||
*
|
||||
* @param string $method
|
||||
* @param string $endpoint
|
||||
* @param array $data
|
||||
* @return \Illuminate\Http\Client\Response
|
||||
*/
|
||||
protected function sendRequest(string $method, string $endpoint, array $data = []): \Illuminate\Http\Client\Response
|
||||
{
|
||||
$response = $this->client()->$method($endpoint, $data);
|
||||
|
||||
if ($response->status() === 401) {
|
||||
Log::info("Telepagos 401 Unauthorized. Refreshing token and retrying...");
|
||||
|
||||
$this->clearToken();
|
||||
|
||||
$response = $this->client()->$method($endpoint, $data);
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a QR code for cash-in.
|
||||
*
|
||||
@@ -117,17 +140,15 @@ class TelepagosIntegrationService extends BaseIntegrationService
|
||||
*/
|
||||
public function generateQr(float $amount, string $concept, string $description): array
|
||||
{
|
||||
$response = $this->client()->post('/v2/payment/cashin/qr/generate', [
|
||||
$payload = [
|
||||
'amount' => $amount,
|
||||
'concept' => $concept,
|
||||
'description' => $description,
|
||||
]);
|
||||
];
|
||||
|
||||
return $this->handleResponse($response, 'QR generation', [
|
||||
'amount' => $amount,
|
||||
'concept' => $concept,
|
||||
'description' => $description,
|
||||
]);
|
||||
$response = $this->sendRequest('post', '/v2/payment/cashin/qr/generate', $payload);
|
||||
|
||||
return $this->handleResponse($response, 'QR generation', $payload);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -139,7 +160,7 @@ class TelepagosIntegrationService extends BaseIntegrationService
|
||||
*/
|
||||
public function getCashinDetails(int $cashinId): array
|
||||
{
|
||||
$response = $this->client()->get("/v2/payment/cashin/{$cashinId}");
|
||||
$response = $this->sendRequest('get', "/v2/payment/cashin/{$cashinId}");
|
||||
|
||||
return $this->handleResponse($response, 'get cash-in details', [
|
||||
'cashin_id' => $cashinId,
|
||||
|
||||
Reference in New Issue
Block a user