package trustpayments import ( "context" "encoding/json" "fmt" "io" "net/http" "strings" "testing" ) func TestLegacyTrustCurrencyDoesNotDetermineApproval(t *testing.T) { for _, providerCurrency := range []any{nil, "", "GBP", "EUR", "NOT-AN-ISO-CODE", 123, map[string]any{"unexpected": "value"}} { t.Run(fmt.Sprint("provider=", providerCurrency), func(t *testing.T) { cfg := fixtureConfig() cfg.Transport = transportFunc(func(r *http.Request) (*http.Response, error) { var input map[string]string if err := json.NewDecoder(r.Body).Decode(&input); err != nil { return nil, err } if _, exists := input["currency"]; exists { t.Error("TRU request gained a currency field") } body, _ := json.Marshal(map[string]any{"refid": "SYNTH-REF", "siteid": cfg.SiteID, "terminalserialnumber": cfg.Terminal, "type": "sale", "resultcode": "Approved", "amount": "25.00", "currency": providerCurrency}) return &http.Response{StatusCode: 200, Body: io.NopCloser(strings.NewReader(string(body)))}, nil }) client, err := New(cfg) if err != nil { t.Fatal(err) } op := Operation{RefID: "SYNTH-REF", TxnDate: "2026-11-03:12:00:00", Request: Request{Kind: "sale", Amount: 2500, Currency: "REQUEST-CURRENCY-IS-NOT-A-GATE"}} result, err := client.Execute(context.Background(), op, false) if err != nil || result.State != Approved || result.Amount != 2500 || result.Currency != cfg.Currency { t.Fatalf("Execute(provider currency %v)=%+v/%v, want approval and CMS bookkeeping only", providerCurrency, result, err) } }) } } func TestCMSCurrencyIsMetadataNotAClientValidationFlag(t *testing.T) { for _, currency := range []string{"", "GBP", "NOT-AN-ISO-CODE"} { cfg := fixtureConfig() cfg.Currency = currency client, err := New(cfg) if err != nil { t.Errorf("New(CMS currency %q)=%v, want no Trust currency gate", currency, err) continue } if !client.ValidRequest(Request{Kind: "preauth", Amount: 2500, Currency: "different"}) { t.Errorf("ValidRequest(CMS currency %q) imposed currency validation", currency) } } }