feat(hardlink): unify kiosk payments and finalize legacy cleanup

This commit is contained in:
2026-11-04 17:43:10 +00:00
parent 568adc034b
commit 814d87768d
57 changed files with 3624 additions and 1762 deletions
+21 -12
View File
@@ -7,11 +7,13 @@ import (
"encoding/json"
"encoding/xml"
"errors"
"gitea.futuresens.co.uk/futuresens/hardlink/paymentapi"
"io"
"net/http"
"net/http/httptest"
"os"
"reflect"
"strconv"
"strings"
"sync/atomic"
"testing"
@@ -143,8 +145,8 @@ func TestCreditCallPreauthLegacyCharacterization(t *testing.T) {
t.Errorf("persisted=%v, want provider amount/reference", got)
}
departure := time.Date(2026, 9, 11, 0, 0, 0, 0, time.Local).UTC()
if got["DepartureDate"] != departure || got["ReleaseDate"] != departure.Add(48*time.Hour) {
t.Errorf("persisted dates=%v, want existing local midnight plus 48 hours", got)
if got["DepartureDate"] != departure || got["ReleaseDate"] != departure.Add(96*time.Hour) {
t.Errorf("persisted dates=%v, want existing local midnight plus 96 hours", got)
}
} else if c.count.Load() != 0 {
t.Error("non-persisting result inserted SQL")
@@ -154,7 +156,8 @@ func TestCreditCallPreauthLegacyCharacterization(t *testing.T) {
}
func preauthStreamRequest(amount, kind, checkout string) *http.Request {
body, _ := json.Marshal(creditCallPreauthRequest{Amount: amount, TransactionType: kind, CheckoutDate: checkout})
value, _ := strconv.ParseInt(amount, 10, 64)
body, _ := json.Marshal(paymentapi.Request{Amount: value, CheckoutDate: checkout})
r := httptest.NewRequest(http.MethodPost, "/api/payment/preauth", strings.NewReader(string(body)))
r.Header.Set("Content-Type", "application/json")
return r
@@ -214,7 +217,7 @@ func TestCreditCallPreauthStreamingParity(t *testing.T) {
}
recorder := httptest.NewRecorder()
if stream {
app.streamCreditCallPreauth(recorder, preauthStreamRequest(amount, kind, date))
app.preauthPayment(recorder, preauthStreamRequest(amount, kind, date))
frames := decodePaymentStream(t, recorder.Body)
var statuses []string
for _, frame := range frames {
@@ -230,7 +233,7 @@ func TestCreditCallPreauthStreamingParity(t *testing.T) {
if final == nil {
t.Fatal("missing structured final")
}
if (final.Outcome == "approved") != tc.approved || final.Status != legacy.Status || final.HTTPStatus != 200 {
if (final.Outcome == "approved") != tc.approved || final.HTTPStatus != 200 {
t.Errorf("stream final=%+v, legacy=%+v", final, legacy)
}
if tc.approved && (final.TransactionReference != "preauth-ref" || final.CardType != "Visa" || final.MaskedCardNumber != "************1133" || final.ExpiryDate != "1228" || final.CardHash != "hash" || final.CardReference != "cardref") {
@@ -296,9 +299,9 @@ func TestCreditCallInboundCancellationAfterDispatch(t *testing.T) {
go func() {
defer close(done)
if preauth {
app.streamCreditCallPreauth(recorder, preauthStreamRequest("12000", "Sale", "2026-09-11 00:00:00 +0000").WithContext(ctx))
app.preauthPayment(recorder, preauthStreamRequest("12000", "Sale", "2026-09-11 00:00:00 +0000").WithContext(ctx))
} else {
app.streamCreditCallSale(recorder, saleRequest(true).WithContext(ctx))
app.salePayment(recorder, saleRequest(true).WithContext(ctx))
}
}()
select {
@@ -342,9 +345,9 @@ func TestCreditCallPreauthMissingAmountNeverSynthesized(t *testing.T) {
c := preauthTestDatabase(t, app)
app.creditCallReceipt = func(string) {}
recorder := httptest.NewRecorder()
app.streamCreditCallPreauth(recorder, preauthStreamRequest("9999", "Sale", "2026-09-11 00:00:00 +0000"))
app.preauthPayment(recorder, preauthStreamRequest("9999", "Sale", "2026-09-11 00:00:00 +0000"))
frames := decodePaymentStream(t, recorder.Body)
if frames[0].Result.Outcome != "approved" {
if frames[0].Result.Outcome != "approved" || frames[0].Result.AmountMinor != 9999 {
t.Fatalf("missing amount changed approval: %+v", frames[0].Result)
}
deadline := time.Now().Add(3 * time.Second)
@@ -378,16 +381,22 @@ func TestCreditCallPreauthStreamFailureAndCancelledBeforeDispatch(t *testing.T)
app.creditCallTransport = creditCallRoundTrip(func(r *http.Request) (*http.Response, error) { calls++; return transport.RoundTrip(r) })
app.creditCallReceipt = func(string) { t.Error("malformed stream printed receipt") }
recorder := httptest.NewRecorder()
app.streamCreditCallPreauth(recorder, preauthStreamRequest("", "AccountVerification", ""))
app.preauthPayment(recorder, preauthStreamRequest("", "AccountVerification", ""))
frames := decodePaymentStream(t, recorder.Body)
if calls != 1 || len(frames) != 1 || frames[0].Result.Outcome != "error" || frames[0].Result.HTTPStatus != 502 {
if calls != 1 || len(frames) != 1 || frames[0].Result.Outcome != "unknown" || frames[0].Result.HTTPStatus != 502 {
t.Errorf("invalid stream %q: calls=%d frames=%+v", body, calls, frames)
}
ctx, cancel := context.WithCancel(context.Background())
cancel()
app.streamCreditCallPreauth(httptest.NewRecorder(), preauthStreamRequest("", "AccountVerification", "").WithContext(ctx))
app.preauthPayment(httptest.NewRecorder(), preauthStreamRequest("", "AccountVerification", "").WithContext(ctx))
if calls != 1 {
t.Error("already-cancelled request dispatched a transaction")
}
}
}
type creditCallPreauthRequest struct {
Amount string `json:"amount"`
TransactionType string `json:"transactionType"`
CheckoutDate string `json:"checkoutDate"`
}