@@ -135,6 +135,11 @@ protected function setupService(Order $orderInput): array
135135
136136 public function startPaymentIntent (Payments $ payment ): array
137137 {
138+ $ payment ->addLog ('payment_initiated ' , [
139+ 'order_id ' => $ payment ->order ->id ,
140+ 'amount ' => $ payment ->amount ,
141+ ]);
142+
138143 $ merchantAuthentication = $ this ->setupMerchantAuthentication ($ payment , $ payment ->order );
139144 $ payerAuthentication = $ this ->client ->setupPayer (
140145 $ payment ->order ->id ,
@@ -399,6 +404,13 @@ public function processPayment(Payments $payment, ConsumerAuthentication $consum
399404 $ transactionId = (string ) $ paymentResponse ['data ' ]['processorInformation ' ]['transactionId ' ];
400405 $ intentId = (string ) $ paymentResponse ['data ' ]['id ' ];
401406
407+ $ payment ->addLog ('payment_authorized ' , [
408+ 'transaction_id ' => $ transactionId ,
409+ 'intent_id ' => $ intentId ,
410+ 'order_id ' => $ order ->id ,
411+ 'amount ' => $ order ->getTotalAmount (),
412+ ]);
413+
402414 $ payment ->status = PaymentStatusEnum::AUTHORIZED ;
403415 $ payment ->addMetadata ([
404416 'data ' => [
@@ -427,6 +439,11 @@ public function processPayment(Payments $payment, ConsumerAuthentication $consum
427439
428440 private function processPaymentCall (Payments $ payment , ConsumerAuthentication $ consumerData , Order $ order ): array
429441 {
442+ $ payment ->addLog ('payment_processing ' , [
443+ 'order_id ' => $ order ->id ,
444+ 'amount ' => $ order ->getTotalAmount (),
445+ ]);
446+
430447 $ referenceId = $ order ->get ('auth_session_id ' );
431448 $ merchantAuthentication = $ this ->setupMerchantAuthentication ($ payment , $ order , includeDetails: true );
432449 $ paymentData = PaymentDetail::from ([
@@ -465,6 +482,13 @@ private function processPaymentCall(Payments $payment, ConsumerAuthentication $c
465482 $ errorMessage = $ e ->getMessage ();
466483 $ errorBody = $ e ->getErrorBody ();
467484
485+ $ payment ->addLog ('payment_error ' , [
486+ 'error_type ' => 'EchoPayException ' ,
487+ 'error_message ' => $ errorMessage ,
488+ 'error_body ' => $ errorBody ,
489+ 'order_id ' => $ order ->id ,
490+ ]);
491+
468492 $ payment ->status = PaymentStatusEnum::FAILED ->value ;
469493 $ order ->updateQuietly ([
470494 'payment_status ' => PaymentStatusEnum::FAILED ->value ,
@@ -504,6 +528,12 @@ private function processPaymentCall(Payments $payment, ConsumerAuthentication $c
504528 $ messageBody = [];
505529 }
506530
531+ $ payment ->addLog ('payment_error ' , [
532+ 'error_type ' => get_class ($ e ),
533+ 'error_message ' => $ errorMessage ,
534+ 'order_id ' => $ order ->id ,
535+ ]);
536+
507537 $ payment ->status = PaymentStatusEnum::FAILED ->value ;
508538 $ order ->updateQuietly ([
509539 'payment_status ' => PaymentStatusEnum::FAILED ->value ,
@@ -548,6 +578,12 @@ public function capturePayment(Payments $payment, Order $order, string $transact
548578 $ merchantAuthentication
549579 );
550580
581+ $ payment ->addLog ('payment_captured ' , [
582+ 'order_id ' => $ order ->id ,
583+ 'transaction_id ' => $ transactionId ,
584+ 'amount ' => $ order ->getTotalAmount (),
585+ ]);
586+
551587 $ payment ->status = PaymentStatusEnum::PAID ;
552588 $ order ->updateQuietly ([
553589 'payment_status ' => PaymentStatusEnum::PAID ->value ,
@@ -569,6 +605,14 @@ public function capturePayment(Payments $payment, Order $order, string $transact
569605 } catch (EchoPayException $ e ) {
570606 report ($ e );
571607
608+ $ payment ->addLog ('payment_error ' , [
609+ 'error_type ' => 'EchoPayException ' ,
610+ 'error_message ' => $ e ->getMessage (),
611+ 'error_body ' => $ e ->getErrorBody (),
612+ 'order_id ' => $ order ->id ,
613+ 'context ' => 'capture_payment ' ,
614+ ]);
615+
572616 return [
573617 'status ' => 'error ' ,
574618 'message ' => $ e ->getMessage (),
@@ -577,6 +621,13 @@ public function capturePayment(Payments $payment, Order $order, string $transact
577621 } catch (Throwable $ e ) {
578622 report ($ e );
579623
624+ $ payment ->addLog ('payment_error ' , [
625+ 'error_type ' => get_class ($ e ),
626+ 'error_message ' => $ e ->getMessage (),
627+ 'order_id ' => $ order ->id ,
628+ 'context ' => 'capture_payment ' ,
629+ ]);
630+
580631 return [
581632 'status ' => 'error ' ,
582633 'message ' => $ e ->getMessage (),
@@ -601,6 +652,13 @@ public function reversePayment(Payments $payment, Order $order, string $transact
601652 $ reason
602653 );
603654
655+ $ payment ->addLog ('payment_reversed ' , [
656+ 'transaction_id ' => $ transactionId ,
657+ 'reason ' => $ reason ,
658+ 'order_id ' => $ order ->id ,
659+ 'amount ' => $ order ->getTotalAmount (),
660+ ]);
661+
604662 $ payment ->status = PaymentStatusEnum::REVERSED ->value ;
605663 $ order ->updateQuietly ([
606664 'payment_status ' => PaymentStatusEnum::REVERSED ->value ,
@@ -624,6 +682,16 @@ public function reversePayment(Payments $payment, Order $order, string $transact
624682 } catch (EchoPayException $ e ) {
625683 report ($ e );
626684
685+ $ payment ->addLog ('payment_error ' , [
686+ 'error_type ' => 'EchoPayException ' ,
687+ 'error_message ' => $ e ->getMessage (),
688+ 'error_body ' => $ e ->getErrorBody (),
689+ 'transaction_id ' => $ transactionId ,
690+ 'reason ' => $ reason ,
691+ 'order_id ' => $ order ->id ,
692+ 'context ' => 'reverse_payment ' ,
693+ ]);
694+
627695 return [
628696 'status ' => 'error ' ,
629697 'message ' => $ e ->getMessage (),
@@ -632,6 +700,15 @@ public function reversePayment(Payments $payment, Order $order, string $transact
632700 } catch (Throwable $ e ) {
633701 report ($ e );
634702
703+ $ payment ->addLog ('payment_error ' , [
704+ 'error_type ' => get_class ($ e ),
705+ 'error_message ' => $ e ->getMessage (),
706+ 'transaction_id ' => $ transactionId ,
707+ 'reason ' => $ reason ,
708+ 'order_id ' => $ order ->id ,
709+ 'context ' => 'reverse_payment ' ,
710+ ]);
711+
635712 return [
636713 'status ' => 'error ' ,
637714 'message ' => $ e ->getMessage (),
0 commit comments