Skip to content

Commit

Permalink
add new trxId
Browse files Browse the repository at this point in the history
  • Loading branch information
idprm committed Oct 8, 2024
1 parent 3dc57df commit 3310671
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 15 deletions.
8 changes: 7 additions & 1 deletion internal/handler/mt_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
7 changes: 4 additions & 3 deletions internal/handler/renewal_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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())
Expand Down
13 changes: 7 additions & 6 deletions internal/handler/retry_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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())
Expand Down Expand Up @@ -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())
Expand All @@ -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())
Expand Down
4 changes: 2 additions & 2 deletions internal/handler/sms_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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())
Expand Down
10 changes: 9 additions & 1 deletion internal/providers/kannel/kannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,22 @@ type Kannel struct {
service *entity.Service
content *entity.Content
subscription *entity.Subscription
trxId string
}

func NewKannel(
logger *logger.Logger,
service *entity.Service,
content *entity.Content,
subscription *entity.Subscription,
trxId string,
) *Kannel {
return &Kannel{
logger: logger,
service: service,
content: content,
subscription: subscription,
trxId: trxId,
}
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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,
Expand Down
17 changes: 15 additions & 2 deletions internal/providers/telco/telco.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
Expand Down

0 comments on commit 3310671

Please sign in to comment.