feat: stream CreditCall payment progress and results
This commit is contained in:
@@ -168,9 +168,7 @@ func BuildSuccessURL(result map[string]string) string {
|
||||
|
||||
func BuildFailureURL(msgType, description string) string {
|
||||
q := url.Values{}
|
||||
if msgType != "" {
|
||||
description = fmt.Sprintf("Transaction %s", strings.ToLower(msgType))
|
||||
}
|
||||
description = FailureDescription(msgType, description)
|
||||
if description != "" {
|
||||
msgType = types.ResultError
|
||||
}
|
||||
@@ -185,3 +183,12 @@ func BuildFailureURL(msgType, description string) string {
|
||||
RawQuery: q.Encode(),
|
||||
}).String()
|
||||
}
|
||||
|
||||
// FailureDescription preserves the description used by the legacy payment flow
|
||||
// without requiring structured consumers to construct a redirect URL.
|
||||
func FailureDescription(msgType, description string) string {
|
||||
if msgType != "" {
|
||||
return fmt.Sprintf("Transaction %s", strings.ToLower(msgType))
|
||||
}
|
||||
return description
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package creditcall
|
||||
|
||||
import "gitea.futuresens.co.uk/futuresens/hardlink/paymentstatus"
|
||||
|
||||
// ProgressStatus maps informational SDK events, never financial decisions.
|
||||
func ProgressStatus(source, value string) string {
|
||||
switch source {
|
||||
case "UPDATE":
|
||||
switch value {
|
||||
case "CardRequested", "ProvideCard", "InsertOrSwipeCard", "InsertOrContactless":
|
||||
return paymentstatus.PresentCard
|
||||
case "InsertCard":
|
||||
return paymentstatus.InsertCard
|
||||
case "SwipeCard":
|
||||
return paymentstatus.SwipeCard
|
||||
case "CardRemovalRequested", "CardRemovalEnforced":
|
||||
return paymentstatus.RemoveCard
|
||||
case "PinEntryStarted", "PinEntryPrompt", "PinEntryInProgress":
|
||||
return paymentstatus.EnterPIN
|
||||
case "PinEntryFailed":
|
||||
return paymentstatus.EnterPINAgain
|
||||
case "PinEntrySuccessful", "TransactionStarted", "OnlineAuthRequested", "OnlineAuthorizeRequest":
|
||||
return paymentstatus.Processing
|
||||
case "OnlineAuthCompleted":
|
||||
return paymentstatus.PleaseWait
|
||||
}
|
||||
case "CARD_STATUS":
|
||||
switch value {
|
||||
case "Inserted":
|
||||
return paymentstatus.DoNotRemoveCard
|
||||
case "Tapped", "Swiped":
|
||||
return paymentstatus.Processing
|
||||
}
|
||||
case "SIGNATURE":
|
||||
if value == "Requested" {
|
||||
return paymentstatus.SignatureRequired
|
||||
}
|
||||
case "PAUSE":
|
||||
if value == "Paused" {
|
||||
return paymentstatus.PleaseWait
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// MaskedCardNumber excludes unmasked or unexpected SDK data from the new wire contract.
|
||||
func MaskedCardNumber(value string) string {
|
||||
digits, masks := 0, 0
|
||||
for _, ch := range value {
|
||||
switch {
|
||||
case ch >= '0' && ch <= '9':
|
||||
digits++
|
||||
case ch == '*' || ch == 'x' || ch == 'X':
|
||||
masks++
|
||||
case ch == ' ' || ch == '-':
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
if masks < 4 || digits > 10 {
|
||||
return ""
|
||||
}
|
||||
return value
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package creditcall
|
||||
|
||||
import (
|
||||
"gitea.futuresens.co.uk/futuresens/hardlink/paymentstatus"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestProgressStatus(t *testing.T) {
|
||||
for _, test := range []struct{ source, value, want string }{
|
||||
{"UPDATE", "CardRequested", paymentstatus.PresentCard},
|
||||
{"UPDATE", "ProvideCard", paymentstatus.PresentCard},
|
||||
{"UPDATE", "InsertOrSwipeCard", paymentstatus.PresentCard},
|
||||
{"UPDATE", "InsertOrContactless", paymentstatus.PresentCard},
|
||||
{"UPDATE", "InsertCard", paymentstatus.InsertCard},
|
||||
{"UPDATE", "SwipeCard", paymentstatus.SwipeCard},
|
||||
{"UPDATE", "CardRemovalRequested", paymentstatus.RemoveCard},
|
||||
{"UPDATE", "CardRemovalEnforced", paymentstatus.RemoveCard},
|
||||
{"UPDATE", "PinEntryStarted", paymentstatus.EnterPIN},
|
||||
{"UPDATE", "PinEntryPrompt", paymentstatus.EnterPIN},
|
||||
{"UPDATE", "PinEntryInProgress", paymentstatus.EnterPIN},
|
||||
{"UPDATE", "PinEntryFailed", paymentstatus.EnterPINAgain},
|
||||
{"UPDATE", "PinEntrySuccessful", paymentstatus.Processing},
|
||||
{"UPDATE", "TransactionStarted", paymentstatus.Processing},
|
||||
{"UPDATE", "OnlineAuthRequested", paymentstatus.Processing},
|
||||
{"UPDATE", "OnlineAuthorizeRequest", paymentstatus.Processing},
|
||||
{"UPDATE", "OnlineAuthCompleted", paymentstatus.PleaseWait},
|
||||
{"CARD_STATUS", "Inserted", paymentstatus.DoNotRemoveCard},
|
||||
{"CARD_STATUS", "Tapped", paymentstatus.Processing},
|
||||
{"CARD_STATUS", "Swiped", paymentstatus.Processing},
|
||||
{"CARD_STATUS", "Removed", ""},
|
||||
{"SIGNATURE", "Requested", paymentstatus.SignatureRequired},
|
||||
{"PAUSE", "Paused", paymentstatus.PleaseWait},
|
||||
{"UPDATE", "Approved", ""}, {"UPDATE", "Declined", ""},
|
||||
{"UPDATE", "unknown", ""}, {"PAN", "CardRequested", ""},
|
||||
} {
|
||||
if got := ProgressStatus(test.source, test.value); got != test.want {
|
||||
t.Errorf("ProgressStatus(%q, %q) = %q, want %q", test.source, test.value, got, test.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMaskedCardNumber(t *testing.T) {
|
||||
for _, test := range []struct{ value, want string }{
|
||||
{"123456******1234", "123456******1234"}, {"************1234", "************1234"},
|
||||
{"1234567890123456", ""}, {"1234567890123456****", ""}, {"3132333435363738", ""},
|
||||
{"%B1234567890123456^NAME", ""}, {"", ""},
|
||||
} {
|
||||
if got := MaskedCardNumber(test.value); got != test.want {
|
||||
t.Errorf("MaskedCardNumber(%q) = %q, want %q", test.value, got, test.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user