Added logging

This commit is contained in:
Borna Rajković 2023-07-10 10:56:25 +02:00
parent 5dbf767863
commit 3de5c8b0f1
1 changed files with 16 additions and 0 deletions

16
main.go
View File

@ -106,6 +106,8 @@ func main() {
return return
} }
log.Printf("Created initial wspay form (ammount=%d)", amount)
form := wspay.WsPayForm{ form := wspay.WsPayForm{
ShopID: ShopId, ShopID: ShopId,
ShoppingCartID: entry.ShoppingCartID, ShoppingCartID: entry.ShoppingCartID,
@ -125,12 +127,16 @@ func main() {
c.AbortWithError(http.StatusInternalServerError, err) c.AbortWithError(http.StatusInternalServerError, err)
return return
} }
log.Printf("Received success response for transaction %s", response.ShoppingCartID)
entry, err := wspayService.FetchByShoppingCartID(response.ShoppingCartID) entry, err := wspayService.FetchByShoppingCartID(response.ShoppingCartID)
if err != nil { if err != nil {
log.Printf("Couldn't find payment info for transaction %s", response.ShoppingCartID)
c.AbortWithError(http.StatusInternalServerError, err) c.AbortWithError(http.StatusInternalServerError, err)
return return
} }
if err := wspay.CompareFormReturnSignature(response.Signature, ShopId, ShopSecret, response.ShoppingCartID, response.Success, response.ApprovalCode); err != nil { if err := wspay.CompareFormReturnSignature(response.Signature, ShopId, ShopSecret, response.ShoppingCartID, response.Success, response.ApprovalCode); err != nil {
log.Printf("Invalid signature for transaction %s", response.ShoppingCartID)
c.AbortWithError(http.StatusBadRequest, err) c.AbortWithError(http.StatusBadRequest, err)
return return
} }
@ -163,8 +169,10 @@ func main() {
} }
if c.Query("iframe") != "" { if c.Query("iframe") != "" {
log.Printf("Transaction %s received correctly, returning iframe response", response.ShoppingCartID)
c.HTML(200, "iframe_handler.gohtml", gin.H{}) c.HTML(200, "iframe_handler.gohtml", gin.H{})
} else { } else {
log.Printf("Transaction %s received correctly, returning redirect", response.ShoppingCartID)
c.Redirect(http.StatusTemporaryRedirect, "/") c.Redirect(http.StatusTemporaryRedirect, "/")
} }
}) })
@ -177,8 +185,10 @@ func main() {
c.AbortWithError(http.StatusInternalServerError, err) c.AbortWithError(http.StatusInternalServerError, err)
return return
} }
log.Printf("Received error response for transaction %s", response.ShoppingCartID)
entry, err := wspayService.FetchByShoppingCartID(response.ShoppingCartID) entry, err := wspayService.FetchByShoppingCartID(response.ShoppingCartID)
if err != nil { if err != nil {
log.Printf("Couldn't find payment info for transaction %s", response.ShoppingCartID)
c.AbortWithError(http.StatusInternalServerError, err) c.AbortWithError(http.StatusInternalServerError, err)
return return
} }
@ -210,8 +220,10 @@ func main() {
} }
if c.Query("iframe") != "" { if c.Query("iframe") != "" {
log.Printf("Transaction %s received correctly, returning iframe response", response.ShoppingCartID)
c.HTML(200, "iframe_handler.gohtml", gin.H{}) c.HTML(200, "iframe_handler.gohtml", gin.H{})
} else { } else {
log.Printf("Transaction %s received correctly, returning redirect", response.ShoppingCartID)
c.Redirect(http.StatusTemporaryRedirect, "/") c.Redirect(http.StatusTemporaryRedirect, "/")
} }
}) })
@ -230,8 +242,10 @@ func main() {
c.AbortWithError(http.StatusInternalServerError, err) c.AbortWithError(http.StatusInternalServerError, err)
return return
} }
log.Printf("Received error response for transaction %s", response.ShoppingCartID)
entry, err := wspayService.FetchByShoppingCartID(response.ShoppingCartID) entry, err := wspayService.FetchByShoppingCartID(response.ShoppingCartID)
if err != nil { if err != nil {
log.Printf("Couldn't find payment info for transaction %s", response.ShoppingCartID)
c.AbortWithError(http.StatusInternalServerError, err) c.AbortWithError(http.StatusInternalServerError, err)
return return
} }
@ -243,8 +257,10 @@ func main() {
} }
if c.Query("iframe") != "" { if c.Query("iframe") != "" {
log.Printf("Transaction %s received correctly, returning iframe response", response.ShoppingCartID)
c.HTML(200, "iframe_handler.gohtml", gin.H{}) c.HTML(200, "iframe_handler.gohtml", gin.H{})
} else { } else {
log.Printf("Transaction %s received correctly, returning redirect", response.ShoppingCartID)
c.Redirect(http.StatusTemporaryRedirect, "/") c.Redirect(http.StatusTemporaryRedirect, "/")
} }
}) })