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