From 331067110552c3f97ed916f028343a33f34002c7 Mon Sep 17 00:00:00 2001 From: Indra Pramana Date: Tue, 8 Oct 2024 16:11:50 +0700 Subject: [PATCH] add new trxId --- internal/handler/mt_handler.go | 8 +++++++- internal/handler/renewal_handler.go | 7 ++++--- internal/handler/retry_handler.go | 13 +++++++------ internal/handler/sms_handler.go | 4 ++-- internal/providers/kannel/kannel.go | 10 +++++++++- internal/providers/telco/telco.go | 17 +++++++++++++++-- 6 files changed, 44 insertions(+), 15 deletions(-) diff --git a/internal/handler/mt_handler.go b/internal/handler/mt_handler.go index daeadc9..b0a8db5 100644 --- a/internal/handler/mt_handler.go +++ b/internal/handler/mt_handler.go @@ -34,7 +34,13 @@ func NewMTHandler( } func (h *MTHandler) MessageTerminated() { - k := kannel.NewKannel(h.logger, h.req.Service, h.req.Content, h.req.Subscription) + k := kannel.NewKannel( + h.logger, + h.req.Service, + h.req.Content, + h.req.Subscription, + h.req.TrxId, + ) statusCode, sms, err := k.SMS(h.req.Smsc) if err != nil { log.Println(err.Error()) diff --git a/internal/handler/renewal_handler.go b/internal/handler/renewal_handler.go index 1f10d5e..6970276 100644 --- a/internal/handler/renewal_handler.go +++ b/internal/handler/renewal_handler.go @@ -50,6 +50,9 @@ func NewRenewalHandler( func (h *RenewalHandler) Dailypush() { if h.subscriptionService.IsActiveSubscription(h.sub.GetServiceId(), h.sub.GetMsisdn()) { + + trxId := utils.GenerateTrxId() + service, err := h.serviceService.GetById(h.sub.GetServiceId()) if err != nil { log.Println(err.Error()) @@ -60,14 +63,12 @@ func (h *RenewalHandler) Dailypush() { log.Println(err.Error()) } - trxId := utils.GenerateTrxId() - summary := &entity.Summary{ ServiceID: service.GetId(), CreatedAt: time.Now(), } - t := telco.NewTelco(h.logger, service, h.sub) + t := telco.NewTelco(h.logger, service, h.sub, trxId) resp, err := t.DeductFee() if err != nil { log.Println(err.Error()) diff --git a/internal/handler/retry_handler.go b/internal/handler/retry_handler.go index 6a43227..6461122 100644 --- a/internal/handler/retry_handler.go +++ b/internal/handler/retry_handler.go @@ -51,6 +51,9 @@ func NewRetryHandler( func (h *RetryHandler) Firstpush() { // check if active sub if h.subscriptionService.IsActiveSubscription(h.sub.GetServiceId(), h.sub.GetMsisdn()) { + + trxId := utils.GenerateTrxId() + service, err := h.serviceService.GetById(h.sub.GetServiceId()) if err != nil { log.Println(err.Error()) @@ -61,14 +64,12 @@ func (h *RetryHandler) Firstpush() { log.Println(err.Error()) } - trxId := utils.GenerateTrxId() - summary := &entity.Summary{ ServiceID: service.GetId(), CreatedAt: time.Now(), } - t := telco.NewTelco(h.logger, service, h.sub) + t := telco.NewTelco(h.logger, service, h.sub, trxId) resp, err := t.DeductFee() if err != nil { log.Println(err.Error()) @@ -144,6 +145,8 @@ func (h *RetryHandler) Dailypush() { // check if active sub if h.subscriptionService.IsActiveSubscription(h.sub.GetServiceId(), h.sub.GetMsisdn()) { + trxId := utils.GenerateTrxId() + service, err := h.serviceService.GetById(h.sub.GetServiceId()) if err != nil { log.Println(err.Error()) @@ -154,14 +157,12 @@ func (h *RetryHandler) Dailypush() { log.Println(err.Error()) } - trxId := utils.GenerateTrxId() - summary := &entity.Summary{ ServiceID: service.GetId(), CreatedAt: time.Now(), } - t := telco.NewTelco(h.logger, service, h.sub) + t := telco.NewTelco(h.logger, service, h.sub, trxId) resp, err := t.DeductFee() if err != nil { log.Println(err.Error()) diff --git a/internal/handler/sms_handler.go b/internal/handler/sms_handler.go index af25086..c6bb464 100644 --- a/internal/handler/sms_handler.go +++ b/internal/handler/sms_handler.go @@ -209,7 +209,7 @@ func (h *SMSHandler) Subscription(category string) { log.Println(err.Error()) } - t := telco.NewTelco(h.logger, service, subscription) + t := telco.NewTelco(h.logger, service, subscription, trxId) deductFee, err := t.DeductFee() if err != nil { @@ -560,7 +560,7 @@ func (h *SMSHandler) Firstpush() { log.Println(err.Error()) } - t := telco.NewTelco(h.logger, service, subscription) + t := telco.NewTelco(h.logger, service, subscription, trxId) profileBall, err := t.QueryProfileAndBal() if err != nil { log.Println(err.Error()) diff --git a/internal/providers/kannel/kannel.go b/internal/providers/kannel/kannel.go index 1641d10..cc1e3a7 100644 --- a/internal/providers/kannel/kannel.go +++ b/internal/providers/kannel/kannel.go @@ -15,6 +15,7 @@ type Kannel struct { service *entity.Service content *entity.Content subscription *entity.Subscription + trxId string } func NewKannel( @@ -22,12 +23,14 @@ func NewKannel( service *entity.Service, content *entity.Content, subscription *entity.Subscription, + trxId string, ) *Kannel { return &Kannel{ logger: logger, service: service, content: content, subscription: subscription, + trxId: trxId, } } @@ -65,7 +68,11 @@ func (p *Kannel) SMS(sc string) (int, []byte, error) { } p.logger.Writer(req) - l.WithFields(logrus.Fields{"request": req}).Info("SMS") + l.WithFields(logrus.Fields{ + "trx_id": p.trxId, + "msisdn": p.subscription.GetMsisdn(), + "request": p.service.GetUrlMT(), + }).Info("SMS") resp, err := client.Do(req) if err != nil { @@ -83,6 +90,7 @@ func (p *Kannel) SMS(sc string) (int, []byte, error) { duration := time.Since(start).Milliseconds() p.logger.Writer(string(body)) l.WithFields(logrus.Fields{ + "trx_id": p.trxId, "msisdn": p.subscription.GetMsisdn(), "response": string(body), "status_code": resp.StatusCode, diff --git a/internal/providers/telco/telco.go b/internal/providers/telco/telco.go index 268f78b..fd0d9d6 100644 --- a/internal/providers/telco/telco.go +++ b/internal/providers/telco/telco.go @@ -18,17 +18,20 @@ type Telco struct { logger *logger.Logger service *entity.Service subscription *entity.Subscription + trxId string } func NewTelco( logger *logger.Logger, service *entity.Service, subscription *entity.Subscription, + trxId string, ) *Telco { return &Telco{ logger: logger, service: service, subscription: subscription, + trxId: trxId, } } @@ -73,7 +76,11 @@ func (p *Telco) QueryProfileAndBal() ([]byte, error) { p.logger.Writer(req) - l.WithFields(logrus.Fields{"request": req}).Info("PROFILE_AND_BAL") + l.WithFields(logrus.Fields{ + "trx_id": p.trxId, + "request_url": p.service.GetUrlTelco(), + "request_body": req.Body, + }).Info("PROFILE_AND_BAL") resp, err := client.Do(req) if err != nil { @@ -91,6 +98,7 @@ func (p *Telco) QueryProfileAndBal() ([]byte, error) { l.WithFields( logrus.Fields{ + "trx_id": p.trxId, "msisdn": p.subscription.GetMsisdn(), "response": string(body), "status_code": resp.StatusCode, @@ -144,7 +152,11 @@ func (p *Telco) DeductFee() ([]byte, error) { p.logger.Writer(req) - l.WithFields(logrus.Fields{"request": req}).Info("DEDUCT_FEE") + l.WithFields(logrus.Fields{ + "trx_id": p.trxId, + "request_url": p.service.GetUrlTelco(), + "request_body": req.Body, + }).Info("DEDUCT_FEE") resp, err := client.Do(req) if err != nil { @@ -162,6 +174,7 @@ func (p *Telco) DeductFee() ([]byte, error) { l.WithFields( logrus.Fields{ + "trx_id": p.trxId, "msisdn": p.subscription.GetMsisdn(), "response": string(body), "status_code": resp.StatusCode,