Просмотр исходного кода

chore: add mais logs para compra com cartao

Gustavo Mantovani 2 часов назад
Родитель
Сommit
3ae046353c
1 измененных файлов с 28 добавлено и 0 удалено
  1. 28 0
      app/Services/Pagarme/PagarmePaymentService.php

+ 28 - 0
app/Services/Pagarme/PagarmePaymentService.php

@@ -24,6 +24,7 @@ use App\Models\PaymentSplit;
 use App\Models\Schedule;
 use App\Services\Pagarme\Concerns\FormatsPagarmeData;
 use App\Services\Pagarme\Concerns\SendsPagarmeRequests;
+use Illuminate\Support\Facades\Log;
 use Illuminate\Support\Str;
 
 class PagarmePaymentService
@@ -106,6 +107,8 @@ class PagarmePaymentService
                 options:    $orderOptions,
             );
 
+            $this->logCreditCardOrderResult($payment, $result, 'create_order');
+
             $orderStatus = OrderResponseData::fromArray($result)->paymentStatus();
 
             if (! in_array($orderStatus, [PaymentStatusEnum::PAID, PaymentStatusEnum::AUTHORIZED], true)) {
@@ -235,6 +238,8 @@ class PagarmePaymentService
         if ($newStatus === PaymentStatusEnum::FAILED) {
             $failureCode    = $order->failureCode();
             $failureMessage = $order->failureMessage();
+
+            $this->logCreditCardOrderResult($payment, $orderResponse, 'webhook_failed');
         }
 
         $gatewayFeeCents = $order->lastTransaction()?->cost ?? 0;
@@ -367,6 +372,29 @@ class PagarmePaymentService
         )];
     }
 
+    private function logCreditCardOrderResult(Payment $payment, array $orderResponse, string $source): void
+    {
+        $order       = OrderResponseData::fromArray($orderResponse);
+        $charge      = $order->firstCharge();
+        $transaction = $order->lastTransaction();
+
+        Log::channel('pagarme')->info('Pagar.me credit card order result', [
+            'source'             => $source,
+            'payment_id'         => $payment->id,
+            'provider_id'        => $payment->provider_id,
+            'order_id'           => $order->id,
+            'order_status'       => $order->status,
+            'charge_id'          => $charge?->id,
+            'charge_status'      => $charge?->status,
+            'transaction_id'     => $transaction?->id,
+            'transaction_status' => $transaction?->status,
+            'failure_code'       => $order->failureCode(),
+            'failure_message'    => $order->failureMessage(),
+            'acquirer_message'   => $transaction?->acquirerMessage,
+            'gateway_response'   => $transaction?->gatewayResponse,
+        ]);
+    }
+
     private function buildPhonePayload(?string $phone): ?array
     {
         $digits = $this->digits($phone);