fixed issue in creditcall payment processing where error description was not properly set
This commit is contained in:
+30
-48
@@ -218,63 +218,45 @@ func nullableFloatArg(nf sql.NullFloat64) interface{} {
|
||||
}
|
||||
|
||||
func BuildRedirectURL(result map[string]string) string {
|
||||
// 1) normalize the result code
|
||||
var msgType, description string
|
||||
q := url.Values{}
|
||||
|
||||
res := strings.ToLower(result["TRANSACTION_RESULT"])
|
||||
|
||||
// 2) pick base path and optional error params
|
||||
var basePath string
|
||||
var msgType, description string
|
||||
|
||||
switch res {
|
||||
case ResultApproved:
|
||||
basePath = CheckinSuccessfulEndpoint
|
||||
|
||||
case ResultDeclined:
|
||||
basePath = CheckinUnsuccessfulEndpoint
|
||||
msgType = "declined"
|
||||
description = "payment declined"
|
||||
|
||||
case ResultCancelled:
|
||||
basePath = CheckinUnsuccessfulEndpoint
|
||||
msgType = "cancelled"
|
||||
description = "payment cancelled by customer"
|
||||
|
||||
case ResultPending:
|
||||
// you could choose to treat pending as unsuccessful or special-case it
|
||||
basePath = CheckinUnsuccessfulEndpoint
|
||||
msgType = "pending"
|
||||
description = "payment pending"
|
||||
case ResultError:
|
||||
basePath = CheckinUnsuccessfulEndpoint
|
||||
msgType = "error"
|
||||
description = result["ERROR"]
|
||||
|
||||
default:
|
||||
basePath = CheckinUnsuccessfulEndpoint
|
||||
msgType = "error"
|
||||
description = "unknown transaction result"
|
||||
if res == ResultApproved {
|
||||
q.Set("TxnReference", result["REFERENCE"])
|
||||
q.Set("CardHash", hex.EncodeToString([]byte(result["CARD_HASH"])))
|
||||
q.Set("CardReference", hex.EncodeToString([]byte(result["CARD_REFERENCE"])))
|
||||
u := url.URL{
|
||||
Path: CheckinSuccessfulEndpoint,
|
||||
RawQuery: q.Encode(),
|
||||
}
|
||||
return u.String()
|
||||
}
|
||||
|
||||
if msgType != "" {
|
||||
log.Warnf("Transaction %s: %s - %s", res, msgType, description)
|
||||
msgType = ResultError
|
||||
if res != "" {
|
||||
msgType = res
|
||||
}
|
||||
|
||||
// 3) build query params
|
||||
q := url.Values{}
|
||||
q.Set("TxnReference", result["REFERENCE"])
|
||||
q.Set("CardHash", hex.EncodeToString([]byte(result["CARD_HASH"])))
|
||||
q.Set("CardReference", hex.EncodeToString([]byte(result["CARD_REFERENCE"])))
|
||||
|
||||
// only append these when non-approved
|
||||
if msgType != "" {
|
||||
q.Set("MsgType", msgType)
|
||||
q.Set("Description", description)
|
||||
errors, ok := result["ERRORS"]
|
||||
if ok && errors != "" {
|
||||
description = errors
|
||||
}
|
||||
errors, ok = result["ERROR"]
|
||||
if ok && errors != "" {
|
||||
description += " " + errors
|
||||
}
|
||||
if description == "" {
|
||||
description = "Transaction failed"
|
||||
}
|
||||
|
||||
// 4) assemble final URL
|
||||
// note: url.URL automatically escapes values in RawQuery
|
||||
log.Errorf("Transaction %s: %s", msgType, description)
|
||||
|
||||
q.Set("MsgType", msgType)
|
||||
q.Set("Description", description)
|
||||
u := url.URL{
|
||||
Path: basePath,
|
||||
Path: CheckinUnsuccessfulEndpoint,
|
||||
RawQuery: q.Encode(),
|
||||
}
|
||||
return u.String()
|
||||
|
||||
Reference in New Issue
Block a user