Added payment terminal status streaming
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
// Package paymentstatus defines progress codes emitted by Hardlink's
|
||||
// POST /api/payment/sale stream. These codes are not authoritative final
|
||||
// transaction decisions: clients may continue check-in only after receiving a
|
||||
// final result frame whose response.data begins with /successful.
|
||||
package paymentstatus
|
||||
|
||||
const (
|
||||
Starting = "PAYMENT_STARTING"
|
||||
Started = "PAYMENT_STARTED"
|
||||
RequestSent = "PAYMENT_REQUEST_SENT"
|
||||
Accepted = "PAYMENT_ACCEPTED"
|
||||
PresentCard = "PAYMENT_PRESENT_CARD"
|
||||
InsertCard = "PAYMENT_INSERT_CARD"
|
||||
SwipeCard = "PAYMENT_SWIPE_CARD"
|
||||
EnterPIN = "PAYMENT_ENTER_PIN"
|
||||
EnterPINAgain = "PAYMENT_ENTER_PIN_AGAIN"
|
||||
PleaseWait = "PAYMENT_PLEASE_WAIT"
|
||||
DoNotRemoveCard = "PAYMENT_DO_NOT_REMOVE_CARD"
|
||||
RemoveCard = "PAYMENT_REMOVE_CARD"
|
||||
TryAnotherInterface = "PAYMENT_TRY_ANOTHER_INTERFACE"
|
||||
Processing = "PAYMENT_PROCESSING"
|
||||
Authorized = "PAYMENT_AUTHORIZED"
|
||||
Approved = "PAYMENT_APPROVED"
|
||||
Cancelling = "PAYMENT_CANCELLING"
|
||||
Cancelled = "PAYMENT_CANCELLED"
|
||||
Declined = "PAYMENT_DECLINED"
|
||||
Expired = "PAYMENT_EXPIRED"
|
||||
Timeout = "PAYMENT_TIMEOUT"
|
||||
SignatureRequired = "PAYMENT_SIGNATURE_REQUIRED"
|
||||
SignatureRejecting = "PAYMENT_SIGNATURE_REJECTING"
|
||||
SignatureRejected = "PAYMENT_SIGNATURE_REJECTED"
|
||||
Voided = "PAYMENT_VOIDED"
|
||||
DailyLimitExceeded = "PAYMENT_DAILY_LIMIT_EXCEEDED"
|
||||
VoidFailed = "PAYMENT_VOID_FAILED"
|
||||
LimitValidationError = "PAYMENT_LIMIT_VALIDATION_ERROR"
|
||||
Error = "PAYMENT_ERROR"
|
||||
|
||||
DojoNotificationPrefix = "PAYMENT_DOJO_NOTIFICATION_"
|
||||
DojoStatusPrefix = "PAYMENT_DOJO_STATUS_"
|
||||
)
|
||||
@@ -0,0 +1,83 @@
|
||||
package paymentstatus_test
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.futuresens.co.uk/futuresens/hardlink/paymentstatus"
|
||||
)
|
||||
|
||||
func TestFixedStatusValues(t *testing.T) {
|
||||
statuses := []struct {
|
||||
name string
|
||||
value string
|
||||
want string
|
||||
}{
|
||||
{"Starting", paymentstatus.Starting, "PAYMENT_STARTING"},
|
||||
{"Started", paymentstatus.Started, "PAYMENT_STARTED"},
|
||||
{"RequestSent", paymentstatus.RequestSent, "PAYMENT_REQUEST_SENT"},
|
||||
{"Accepted", paymentstatus.Accepted, "PAYMENT_ACCEPTED"},
|
||||
{"PresentCard", paymentstatus.PresentCard, "PAYMENT_PRESENT_CARD"},
|
||||
{"InsertCard", paymentstatus.InsertCard, "PAYMENT_INSERT_CARD"},
|
||||
{"SwipeCard", paymentstatus.SwipeCard, "PAYMENT_SWIPE_CARD"},
|
||||
{"EnterPIN", paymentstatus.EnterPIN, "PAYMENT_ENTER_PIN"},
|
||||
{"EnterPINAgain", paymentstatus.EnterPINAgain, "PAYMENT_ENTER_PIN_AGAIN"},
|
||||
{"PleaseWait", paymentstatus.PleaseWait, "PAYMENT_PLEASE_WAIT"},
|
||||
{"DoNotRemoveCard", paymentstatus.DoNotRemoveCard, "PAYMENT_DO_NOT_REMOVE_CARD"},
|
||||
{"RemoveCard", paymentstatus.RemoveCard, "PAYMENT_REMOVE_CARD"},
|
||||
{"TryAnotherInterface", paymentstatus.TryAnotherInterface, "PAYMENT_TRY_ANOTHER_INTERFACE"},
|
||||
{"Processing", paymentstatus.Processing, "PAYMENT_PROCESSING"},
|
||||
{"Authorized", paymentstatus.Authorized, "PAYMENT_AUTHORIZED"},
|
||||
{"Approved", paymentstatus.Approved, "PAYMENT_APPROVED"},
|
||||
{"Cancelling", paymentstatus.Cancelling, "PAYMENT_CANCELLING"},
|
||||
{"Cancelled", paymentstatus.Cancelled, "PAYMENT_CANCELLED"},
|
||||
{"Declined", paymentstatus.Declined, "PAYMENT_DECLINED"},
|
||||
{"Expired", paymentstatus.Expired, "PAYMENT_EXPIRED"},
|
||||
{"Timeout", paymentstatus.Timeout, "PAYMENT_TIMEOUT"},
|
||||
{"SignatureRequired", paymentstatus.SignatureRequired, "PAYMENT_SIGNATURE_REQUIRED"},
|
||||
{"SignatureRejecting", paymentstatus.SignatureRejecting, "PAYMENT_SIGNATURE_REJECTING"},
|
||||
{"SignatureRejected", paymentstatus.SignatureRejected, "PAYMENT_SIGNATURE_REJECTED"},
|
||||
{"Voided", paymentstatus.Voided, "PAYMENT_VOIDED"},
|
||||
{"DailyLimitExceeded", paymentstatus.DailyLimitExceeded, "PAYMENT_DAILY_LIMIT_EXCEEDED"},
|
||||
{"VoidFailed", paymentstatus.VoidFailed, "PAYMENT_VOID_FAILED"},
|
||||
{"LimitValidationError", paymentstatus.LimitValidationError, "PAYMENT_LIMIT_VALIDATION_ERROR"},
|
||||
{"Error", paymentstatus.Error, "PAYMENT_ERROR"},
|
||||
}
|
||||
|
||||
seen := make(map[string]string, len(statuses))
|
||||
for _, status := range statuses {
|
||||
t.Run(status.name, func(t *testing.T) {
|
||||
if status.value != status.want {
|
||||
t.Fatalf("got %q, want %q", status.value, status.want)
|
||||
}
|
||||
if !strings.HasPrefix(status.value, "PAYMENT_") {
|
||||
t.Fatalf("status %q does not have PAYMENT_ prefix", status.value)
|
||||
}
|
||||
})
|
||||
|
||||
if previous, exists := seen[status.value]; exists {
|
||||
t.Errorf("%s and %s have duplicate value %q", previous, status.name, status.value)
|
||||
}
|
||||
seen[status.value] = status.name
|
||||
}
|
||||
}
|
||||
|
||||
func TestDojoPrefixes(t *testing.T) {
|
||||
if paymentstatus.DojoNotificationPrefix != "PAYMENT_DOJO_NOTIFICATION_" {
|
||||
t.Fatalf(
|
||||
"DojoNotificationPrefix = %q, want %q",
|
||||
paymentstatus.DojoNotificationPrefix,
|
||||
"PAYMENT_DOJO_NOTIFICATION_",
|
||||
)
|
||||
}
|
||||
if paymentstatus.DojoStatusPrefix != "PAYMENT_DOJO_STATUS_" {
|
||||
t.Fatalf(
|
||||
"DojoStatusPrefix = %q, want %q",
|
||||
paymentstatus.DojoStatusPrefix,
|
||||
"PAYMENT_DOJO_STATUS_",
|
||||
)
|
||||
}
|
||||
if paymentstatus.DojoNotificationPrefix == paymentstatus.DojoStatusPrefix {
|
||||
t.Fatal("Dojo prefixes must differ")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user