Toku: Reset payments
This commit is contained in:
@ -135,14 +135,19 @@ abstract class AbstractEndPoint extends LoggerEnabled implements EndPoint
|
||||
* @param string $request_uri
|
||||
* @param array $validStatus
|
||||
* @param array $invalidStatus
|
||||
* @param array|null $data
|
||||
* @return void
|
||||
* @throws EmptyResponse
|
||||
*/
|
||||
protected function sendDelete(string $request_uri, array $validStatus, array $invalidStatus): void
|
||||
protected function sendDelete(string $request_uri, array $validStatus, array $invalidStatus, ?array $data = null): void
|
||||
{
|
||||
$this->logger->info('Send Delete', ['uri' => $request_uri]);
|
||||
try {
|
||||
$response = $this->client->delete($request_uri);
|
||||
$options = [];
|
||||
if ($data !== null) {
|
||||
$options = ['json' => $data];
|
||||
}
|
||||
$response = $this->client->delete($request_uri, $options);
|
||||
} catch (ClientExceptionInterface $exception) {
|
||||
throw new EmptyResponse($request_uri, $exception);
|
||||
}
|
||||
|
@ -267,6 +267,7 @@ class Toku extends Ideal\Service
|
||||
$output['customer'] = $this->customer->reset($skips['customer'] ?? []);
|
||||
$output['subscription'] = $this->subscription->reset($skips['subscription'] ?? []);
|
||||
$output['invoice'] = $this->invoice->reset($skips['invoice'] ?? []);
|
||||
$output['payments'] = $this->invoice->resetPayments();
|
||||
} catch (InvalidResult $exception) {
|
||||
$this->logger->warning($exception);
|
||||
return [];
|
||||
|
@ -13,6 +13,7 @@ use Incoviba\Repository;
|
||||
use Incoviba\Service\UF;
|
||||
use Incoviba\Service\Venta\MediosPago\AbstractEndPoint;
|
||||
use Incoviba\Service\Venta\Pago;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Invoice extends AbstractEndPoint
|
||||
{
|
||||
@ -73,6 +74,57 @@ class Invoice extends AbstractEndPoint
|
||||
}
|
||||
return $tokuIds;
|
||||
}
|
||||
public function resetPayments(): array
|
||||
{
|
||||
try {
|
||||
$request_uri = "/payments";
|
||||
$payments = $this->sendGet($request_uri, [200], [404, 422]);
|
||||
} catch (EmptyResponse $exception) {
|
||||
$this->logger->warning($exception, ['request_uri' => $request_uri]);
|
||||
return [];
|
||||
}
|
||||
$this->altLogger->info('Reset Payments', ['count' => count($payments), 'payments' => $payments]);
|
||||
$query = [];
|
||||
/*
|
||||
"id": "pay_79zh1OU1pVV5g0V0I6kShf5AF-I24cUn",
|
||||
"created_at": "2025-06-07T07:08:51+0000",
|
||||
"deleted_at": null,
|
||||
"invoice": "in_IhbKbT21x0ADlnKRCbV57sn2DDI8neq0",
|
||||
"customer": "cus_bTXPBVopZxKOqTOWzRZkhvDEM9XXtvWh",
|
||||
"government_id": "175181431",
|
||||
"name": "Augusto Felipe Schilfferli Rojas",
|
||||
"product_id": "1304-d1749582981383358",
|
||||
"due_date": "2024-11-01",
|
||||
"transaction_date": "2025-06-07T07:08:51+0000",
|
||||
"payment_amount": 14.4822,
|
||||
"buy_order": null,
|
||||
"processed_by_toku": false,
|
||||
"payment_method": null,
|
||||
"card_type": null,
|
||||
"card_number": null,
|
||||
"payment_type": null,
|
||||
"authorization_code": null,
|
||||
"mc_order_id": null,
|
||||
"amount_paid": 14.4822
|
||||
*/
|
||||
foreach ($payments as $payment) {
|
||||
$query[] = [
|
||||
'payment_amount' => $payment['payment_amount'],
|
||||
'payment_date' => $payment['transaction_date'],
|
||||
'payment_method' => $payment['payment_method'],
|
||||
'product_id' => $payment['product_id'],
|
||||
'due_date' => $payment['due_date'],
|
||||
];
|
||||
}
|
||||
try {
|
||||
$this->sendDelete($request_uri, [204], [404, 422], $query);
|
||||
} catch (EmptyResponse $exception) {
|
||||
$this->logger->warning($exception, ['request_uri' => $request_uri]);
|
||||
return [];
|
||||
}
|
||||
$this->altLogger->info('Reset Payments Payload', ['count' => count($payments), 'payments' => $query]);
|
||||
return $payments;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $customer_id
|
||||
@ -133,6 +185,14 @@ class Invoice extends AbstractEndPoint
|
||||
{
|
||||
return $this->doSave($this->invoiceRepository, $data);
|
||||
}
|
||||
|
||||
protected LoggerInterface $altLogger;
|
||||
public function setAltLogger(LoggerInterface $altLogger): self
|
||||
{
|
||||
$this->altLogger = $altLogger;
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function mapParams(array $data): array
|
||||
{
|
||||
$paramsMap = [
|
||||
|
Reference in New Issue
Block a user