fix(creditcall): require fresh confirmation approval for sale
This commit is contained in:
@@ -33,7 +33,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
buildVersion = "v2.2.3"
|
||||
buildVersion = "v2.2.4"
|
||||
serviceName = "hardlink"
|
||||
pollingFrequency = 8 * time.Second
|
||||
)
|
||||
|
||||
@@ -41,6 +41,8 @@ type creditCallDiagnosticFixture struct {
|
||||
initial, confirmation map[string]string
|
||||
startFailure, confirmFailure string
|
||||
confirmationXML string
|
||||
emptyConfirmation bool
|
||||
correctedConfirmation bool
|
||||
recoverConfirmation bool
|
||||
zero bool
|
||||
reason, message string
|
||||
@@ -150,18 +152,61 @@ func creditCallDiagnosticFixtures() []creditCallDiagnosticFixture {
|
||||
fixtures = append(fixtures, creditCallDiagnosticFixture{name: "sale/confirmation_recovers/" + failure, operation: "sale",
|
||||
initial: creditCallDiagnosticFields("APPROVED", ""), confirmFailure: failure, recoverConfirmation: true, message: "Payment approved"})
|
||||
}
|
||||
for _, response := range []struct{ name, xml, reason, cause string }{
|
||||
{"omitted", "<TransactionResult/>", "", ""},
|
||||
{"malformed_retains_approval", "<TransactionResult><Entry>", "", ""},
|
||||
const approvedEntry = "<Entry><Key>TRANSACTION_RESULT</Key><Value>APPROVED</Value></Entry>"
|
||||
const declinedEntry = "<Entry><Key>TRANSACTION_RESULT</Key><Value>DECLINED</Value></Entry>"
|
||||
const errorEntry = "<Entry><Key>TRANSACTION_RESULT</Key><Value>ERROR</Value></Entry>"
|
||||
const emptyEntry = "<Entry><Key>TRANSACTION_RESULT</Key><Value></Value></Entry>"
|
||||
for _, response := range []struct {
|
||||
name, xml, reason, cause string
|
||||
corrected bool
|
||||
}{
|
||||
{"mixed_case", "<TransactionResult><Entry><Key>TRANSACTION_RESULT</Key><Value>aPpRoVeD</Value></Entry></TransactionResult>", "", "", false},
|
||||
{"omitted", "<TransactionResult/>", "confirmation_result_unknown", "ConfirmTransaction result unknown", true},
|
||||
{"empty_body", "", "confirmation_invalid_response", "ConfirmTransaction response is invalid", true},
|
||||
{"whitespace_body", " \r\n\t", "confirmation_invalid_response", "ConfirmTransaction response is invalid", true},
|
||||
{"malformed_retains_approval", "<TransactionResult><Entry>", "confirmation_invalid_response", "ConfirmTransaction response is invalid", true},
|
||||
{"malformed_after_approved", "<TransactionResult>" + approvedEntry + "<Entry>", "confirmation_invalid_response", "ConfirmTransaction response is invalid", true},
|
||||
{"malformed_after_error", "<TransactionResult><Entry><Key>TRANSACTION_RESULT</Key><Value>ERROR</Value></Entry><Entry>",
|
||||
"confirmation_invalid_response", "ConfirmTransaction response is invalid"},
|
||||
"confirmation_invalid_response", "ConfirmTransaction response is invalid", false},
|
||||
{"malformed_after_declined", "<TransactionResult>" + declinedEntry + "<Entry>", "confirmation_invalid_response", "ConfirmTransaction response is invalid", false},
|
||||
{"wrong_root", "<Unexpected/>", "confirmation_invalid_response", "ConfirmTransaction response is invalid", true},
|
||||
{"sdk_only_disconnected", "<TransactionResult><Entry><Key>ERRORS</Key><Value>ClientNotConnectedToServer</Value></Entry></TransactionResult>",
|
||||
"confirmation_sdk_ClientNotConnectedToServer", "ConfirmTransaction: ClientNotConnectedToServer", true},
|
||||
{"sdk_only_not_found", "<TransactionResult><Entry><Key>ERRORS</Key><Value>TransactionNotFound</Value></Entry></TransactionResult>",
|
||||
"confirmation_sdk_TransactionNotFound", "ConfirmTransaction: TransactionNotFound", true},
|
||||
{"duplicate_approved_declined", "<TransactionResult>" + approvedEntry + declinedEntry + "</TransactionResult>",
|
||||
"confirmation_result_declined", "ConfirmTransaction result declined", false},
|
||||
{"duplicate_declined_approved", "<TransactionResult>" + declinedEntry + approvedEntry + "</TransactionResult>", "", "", false},
|
||||
{"duplicate_error_approved", "<TransactionResult>" + errorEntry + approvedEntry + "</TransactionResult>", "", "", false},
|
||||
{"duplicate_approved_empty", "<TransactionResult>" + approvedEntry + emptyEntry + "</TransactionResult>",
|
||||
"confirmation_result_unknown", "ConfirmTransaction result unknown", false},
|
||||
{"duplicate_empty_approved", "<TransactionResult>" + emptyEntry + approvedEntry + "</TransactionResult>", "", "", false},
|
||||
{"duplicate_approved_error", "<TransactionResult>" + approvedEntry + errorEntry + "</TransactionResult>",
|
||||
"confirmation_result_error", "ConfirmTransaction result error", false},
|
||||
} {
|
||||
message := "Payment approved"
|
||||
if response.reason != "" {
|
||||
message = "Payment outcome uncertain: " + response.cause + "; contact reception"
|
||||
}
|
||||
fixtures = append(fixtures, creditCallDiagnosticFixture{name: "sale/confirmation_xml/" + response.name, operation: "sale",
|
||||
initial: creditCallDiagnosticFields("APPROVED", "ChipCardRemoved"), confirmationXML: response.xml, reason: response.reason, message: message})
|
||||
initial: creditCallDiagnosticFields("APPROVED", "ChipCardRemoved"), confirmationXML: response.xml,
|
||||
emptyConfirmation: response.xml == "", correctedConfirmation: response.corrected, reason: response.reason, message: message})
|
||||
}
|
||||
for _, metadata := range []string{"returned_amount", "overrides", "empty_overrides"} {
|
||||
fields := creditCallDiagnosticFields("APPROVED", "")
|
||||
fields[types.TotalAmount] = "3100"
|
||||
confirmation := map[string]string{types.TransactionResult: "APPROVED"}
|
||||
if metadata == "overrides" {
|
||||
confirmation[types.Reference], confirmation[types.TotalAmount] = "SYNTH-CONFIRMATION", "2500"
|
||||
confirmation[types.CardType], confirmation[types.PanMasked] = "Mastercard", "************7788"
|
||||
confirmation[types.ExpiryDate], confirmation[types.CardReference] = "1231", "synthetic-confirmation-card"
|
||||
confirmation[types.ReceiptDataCardholder] = "synthetic confirmation receipt"
|
||||
}
|
||||
if metadata == "empty_overrides" {
|
||||
confirmation[types.ExpiryDate], confirmation[types.CardHash], confirmation[types.ReceiptDataCardholder] = "", "", ""
|
||||
}
|
||||
fixtures = append(fixtures, creditCallDiagnosticFixture{name: "sale/confirmation_metadata/" + metadata, operation: "sale",
|
||||
initial: fields, confirmation: confirmation, message: "Payment approved"})
|
||||
}
|
||||
for _, code := range []string{"ConfirmTransaction failed: SYNTHETIC-SECRET PAN=4111111111111111", "ChipCardRemoved,SYNTHETIC-SECRET", "500005", "chipcardremoved"} {
|
||||
reason, cause := "confirmation_result_error", "ConfirmTransaction result error"
|
||||
@@ -274,7 +319,7 @@ func captureCreditCallDiagnostic(t *testing.T, fixture creditCallDiagnosticFixtu
|
||||
fields = map[string]string{types.TransactionResult: "APPROVED", types.ReceiptDataCardholder: "synthetic confirmation receipt"}
|
||||
}
|
||||
xmlBody := fixture.confirmationXML
|
||||
if xmlBody == "" {
|
||||
if xmlBody == "" && !fixture.emptyConfirmation {
|
||||
xmlBody = chipDNAFixture(t, fields)
|
||||
}
|
||||
body.Reader = strings.NewReader(xmlBody)
|
||||
@@ -380,12 +425,17 @@ func captureCreditCallDiagnostic(t *testing.T, fixture creditCallDiagnosticFixtu
|
||||
// the captured unmodified production source and the diagnostic implementation.
|
||||
func TestCreditCallDiagnosticParityCapture(t *testing.T) {
|
||||
observations := map[string]creditCallDiagnosticObservation{}
|
||||
corrections := map[string]creditCallDiagnosticFixture{}
|
||||
for _, fixture := range creditCallDiagnosticFixtures() {
|
||||
if fixture.correctedConfirmation {
|
||||
corrections[fixture.name] = fixture
|
||||
corrections["legacy/"+fixture.name] = fixture
|
||||
}
|
||||
t.Run(fixture.name, func(t *testing.T) {
|
||||
observations[fixture.name] = captureCreditCallDiagnostic(t, fixture, false)
|
||||
})
|
||||
}
|
||||
// Legacy responses and side effects must remain exactly unchanged too.
|
||||
// Legacy observations use the same explicitly allowed correction cases.
|
||||
for _, fixture := range creditCallDiagnosticFixtures() {
|
||||
if fixture.startFailure != "" || fixture.zero || fixture.confirmFailure != "" {
|
||||
continue
|
||||
@@ -421,9 +471,20 @@ func TestCreditCallDiagnosticParityCapture(t *testing.T) {
|
||||
t.Errorf("missing baseline fixture %q", name)
|
||||
continue
|
||||
}
|
||||
if want.Final != nil && got.Final != nil {
|
||||
want.Final.Reason, want.Final.Message = "", ""
|
||||
got.Final.Reason, got.Final.Message = "", ""
|
||||
if fixture, corrected := corrections[name]; corrected {
|
||||
if want.Final != nil {
|
||||
if want.Final.Outcome != "approved" || want.Final.Retryable {
|
||||
t.Fatalf("%s baseline=%+v, want the specifically identified false approval", name, want.Final)
|
||||
}
|
||||
want.Final = &paymentapi.Result{Outcome: "unknown", HTTPStatus: http.StatusOK, Provider: "creditcall",
|
||||
AmountMinor: 1234, CurrencyCode: "GBP", Reason: fixture.reason, Message: fixture.message}
|
||||
} else {
|
||||
if !strings.HasPrefix(want.Legacy.Data, "/successful?") {
|
||||
t.Fatalf("%s baseline=%+v, want the specifically identified false success redirect", name, want.Legacy)
|
||||
}
|
||||
want.Legacy = &cmstypes.ResponseRec{Status: cmstypes.StatusRec{Code: http.StatusOK, Message: "unknown"},
|
||||
Data: "/unsuccessful?Description=Transaction+unknown&MsgType=error"}
|
||||
}
|
||||
}
|
||||
// SQL generates the transaction timestamp during each run. Its type,
|
||||
// UTC location and range are asserted above; retain raw values in captures.
|
||||
@@ -431,7 +492,7 @@ func TestCreditCallDiagnosticParityCapture(t *testing.T) {
|
||||
want.Persistence["TxnDateTime"], got.Persistence["TxnDateTime"] = "validated current UTC time", "validated current UTC time"
|
||||
}
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("%s changed beyond diagnostic fields: got %+v, want %+v", name, got, want)
|
||||
t.Errorf("%s changed beyond the exact approved correction: got %+v, want %+v", name, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -489,12 +550,12 @@ func TestCreditCallDiagnosticEntryOrderAndOwnership(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreditCallConfirmationSDKErrorWithoutResultKeepsLegacyApproval(t *testing.T) {
|
||||
func TestCreditCallConfirmationSDKErrorWithoutResultRemainsUncertain(t *testing.T) {
|
||||
fixture := creditCallDiagnosticFixture{name: "sale/confirmation_sdk_without_result", operation: "sale",
|
||||
initial: creditCallDiagnosticFields("APPROVED", ""), confirmation: map[string]string{types.Errors: "TransactionNotFound"}}
|
||||
initial: creditCallDiagnosticFields("APPROVED", ""), confirmation: map[string]string{types.Errors: "ClientNotConnectedToServer"}}
|
||||
got := captureCreditCallDiagnostic(t, fixture, false)
|
||||
if got.Final.Outcome != "approved" || got.Final.Reason != "" || got.Final.TransactionReference != "SYNTH-STAGE2" || got.Final.AmountMinor != 1234 {
|
||||
t.Errorf("confirmation SDK error without TRANSACTION_RESULT final=%+v, want unchanged inherited approval and metadata", got.Final)
|
||||
if got.Final.Outcome != "unknown" || got.Final.Retryable || got.Final.Reason != "confirmation_sdk_ClientNotConnectedToServer" || got.Final.TransactionReference != "" || got.Final.AmountMinor != 1234 {
|
||||
t.Errorf("confirmation SDK error without TRANSACTION_RESULT final=%+v, want nonretryable uncertainty without approved-only metadata", got.Final)
|
||||
}
|
||||
if len(got.Requests) != 2 || !reflect.DeepEqual(got.Receipts, []string{"synthetic initial receipt"}) {
|
||||
t.Errorf("confirmation SDK error without TRANSACTION_RESULT requests/receipts=%v/%v, want one start, one confirmation and inherited receipt", got.Requests, got.Receipts)
|
||||
|
||||
@@ -90,8 +90,8 @@ func (app *App) executeCreditCallSale(
|
||||
return outcome
|
||||
}
|
||||
|
||||
// Intentionally reuse both records: XML appends confirmation entries, and
|
||||
// missing confirmation fields/receipts retain their existing legacy behavior.
|
||||
// Reuse both records to preserve metadata and receipt merging. Only fresh
|
||||
// confirmation entries can establish completion approval.
|
||||
initialEntryCount := len(trResult.Entries)
|
||||
parseErr := trResult.ParseTransactionResult(body)
|
||||
if parseErr != nil {
|
||||
@@ -99,7 +99,21 @@ func (app *App) executeCreditCallSale(
|
||||
}
|
||||
result.FillFromTransactionResult(trResult)
|
||||
res = result.Fields[types.TransactionResult]
|
||||
if !strings.EqualFold(res, types.ResultApproved) {
|
||||
confirmationEntries := trResult.Entries[initialEntryCount:]
|
||||
var confirmationResult string
|
||||
for _, entry := range confirmationEntries {
|
||||
if entry.Key == types.TransactionResult {
|
||||
confirmationResult = entry.Value
|
||||
}
|
||||
}
|
||||
confirmationApproved := false
|
||||
if parseErr == nil {
|
||||
confirmationApproved = strings.EqualFold(confirmationResult, types.ResultApproved)
|
||||
}
|
||||
if !confirmationApproved {
|
||||
if strings.EqualFold(res, types.ResultApproved) {
|
||||
res = "unknown"
|
||||
}
|
||||
app.printCreditCallReceipt(result.CardholderReceipt)
|
||||
desc := result.Fields[types.ErrorDescription]
|
||||
if desc == "" {
|
||||
@@ -109,10 +123,11 @@ func (app *App) executeCreditCallSale(
|
||||
mail.SendEmailOnError(app.cfg.Hotel, app.cfg.Kiosk, "Payment confirmation failed", "Reference: "+ref+", Confirm result: "+res+" Description: "+desc)
|
||||
outcome.HTTPStatus = http.StatusOK
|
||||
outcome.Status = result.Status
|
||||
outcome.Status.Message = res
|
||||
outcome.Payment = result
|
||||
outcome.FailureType = res
|
||||
outcome.FailureDescription = result.Fields[types.Errors]
|
||||
outcome.confirmationDiagnostic = creditCallConfirmationResultDiagnostic(trResult.Entries[initialEntryCount:], parseErr != nil)
|
||||
outcome.confirmationDiagnostic = creditCallConfirmationResultDiagnostic(confirmationEntries, parseErr != nil)
|
||||
return outcome
|
||||
}
|
||||
|
||||
|
||||
@@ -219,8 +219,8 @@ func TestCreditCallLegacyAndStreamingSaleParity(t *testing.T) {
|
||||
{"cancelled", "Cancelled", "", 0, false, "start receipt"},
|
||||
{"timeout", "TIMEOUT", "", 0, false, "start receipt"},
|
||||
{"confirmation declined", "Approved", "Declined", 1, false, "confirm receipt"},
|
||||
{"confirmation omissions", "Approved", "omitted", 1, true, "start receipt"},
|
||||
{"malformed confirmation", "Approved", "malformed", 1, true, "start receipt"},
|
||||
{"confirmation omissions", "Approved", "omitted", 1, false, "start receipt"},
|
||||
{"malformed confirmation", "Approved", "malformed", 1, false, "start receipt"},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
fields := map[string]string{types.TransactionResult: test.startResult, types.Reference: "native-ref",
|
||||
@@ -314,6 +314,160 @@ func TestCreditCallLegacyAndStreamingSaleParity(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreditCallFreshConfirmationResults(t *testing.T) {
|
||||
fixtures := map[string]creditCallDiagnosticFixture{}
|
||||
for _, fixture := range creditCallDiagnosticFixtures() {
|
||||
fixtures[fixture.name] = fixture
|
||||
}
|
||||
for _, tc := range []struct {
|
||||
name, outcome string
|
||||
amount int64
|
||||
}{
|
||||
{"confirmation_xml/mixed_case", "approved", 1234},
|
||||
{"confirmation_xml/omitted", "unknown", 1234},
|
||||
{"confirmation_xml/empty_body", "unknown", 1234},
|
||||
{"confirmation_xml/whitespace_body", "unknown", 1234},
|
||||
{"confirmation_xml/malformed_retains_approval", "unknown", 1234},
|
||||
{"confirmation_xml/malformed_after_approved", "unknown", 1234},
|
||||
{"confirmation_xml/malformed_after_error", "unknown", 1234},
|
||||
{"confirmation_xml/malformed_after_declined", "unknown", 1234},
|
||||
{"confirmation_xml/wrong_root", "unknown", 1234},
|
||||
{"confirmation_xml/sdk_only_disconnected", "unknown", 1234},
|
||||
{"confirmation_xml/sdk_only_not_found", "unknown", 1234},
|
||||
{"confirmation_xml/duplicate_approved_declined", "unknown", 1234},
|
||||
{"confirmation_xml/duplicate_declined_approved", "approved", 1234},
|
||||
{"confirmation_xml/duplicate_error_approved", "approved", 1234},
|
||||
{"confirmation_xml/duplicate_approved_empty", "unknown", 1234},
|
||||
{"confirmation_xml/duplicate_empty_approved", "approved", 1234},
|
||||
{"confirmation_xml/duplicate_approved_error", "unknown", 1234},
|
||||
{"confirmation_result/DECLINED", "unknown", 1234},
|
||||
{"confirmation_result/ERROR", "unknown", 1234},
|
||||
{"confirmation_result/CANCELLED", "unknown", 1234},
|
||||
{"confirmation_result/CANCELED", "unknown", 1234},
|
||||
{"confirmation_result/TIMEOUT", "unknown", 1234},
|
||||
{"confirmation_result/UNKNOWN", "unknown", 1234},
|
||||
{"confirmation_result/", "unknown", 1234},
|
||||
{"confirmation_metadata/returned_amount", "approved", 3100},
|
||||
{"confirmation_metadata/overrides", "approved", 2500},
|
||||
{"confirmation_metadata/empty_overrides", "approved", 3100},
|
||||
} {
|
||||
for _, legacy := range []bool{false, true} {
|
||||
mode := "modern"
|
||||
if legacy {
|
||||
mode = "legacy"
|
||||
}
|
||||
t.Run(mode+"/"+tc.name, func(t *testing.T) {
|
||||
fixture, ok := fixtures["sale/"+tc.name]
|
||||
if !ok {
|
||||
t.Fatalf("missing confirmation fixture %q", tc.name)
|
||||
}
|
||||
got := captureCreditCallDiagnostic(t, fixture, legacy)
|
||||
if len(got.Requests) != 2 {
|
||||
t.Fatalf("Sale(%s) requests=%+v, want one start and one confirmation", tc.name, got.Requests)
|
||||
}
|
||||
if got.HTTPStatus != http.StatusOK || got.Requests[1].Path != "/confirm-transaction/" {
|
||||
t.Errorf("Sale(%s) HTTP/requests=%d/%+v, want HTTP 200, one start and one confirmation", tc.name, got.HTTPStatus, got.Requests)
|
||||
}
|
||||
for _, request := range got.Requests {
|
||||
if !request.FreshCallDeadline || request.Method != http.MethodPost {
|
||||
t.Errorf("Sale(%s) request=%+v, want POST with an independent 300-second timeout", tc.name, request)
|
||||
}
|
||||
}
|
||||
var confirmation creditcall.ConfirmTransactionRequest
|
||||
if err := xml.Unmarshal([]byte(got.Requests[1].Body), &confirmation); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if confirmation.Amount != "1234" || confirmation.Reference != "SYNTH-STAGE2" {
|
||||
t.Errorf("Sale(%s) confirmation=%+v, want the original requested amount and authorization reference", tc.name, confirmation)
|
||||
}
|
||||
if legacy {
|
||||
if strings.HasPrefix(got.Legacy.Data, "/successful?") != (tc.outcome == "approved") {
|
||||
t.Errorf("Sale(%s) legacy=%+v, want success only for fresh approval", tc.name, got.Legacy)
|
||||
}
|
||||
if fixture.correctedConfirmation && (got.Legacy.Status.Code != http.StatusOK || got.Legacy.Status.Message != "unknown" || got.Legacy.Data != "/unsuccessful?Description=Transaction+unknown&MsgType=error") {
|
||||
t.Errorf("Sale(%s) legacy=%+v, want unchanged status code and explicit uncertainty failure response", tc.name, got.Legacy)
|
||||
}
|
||||
} else if got.Final.Outcome != tc.outcome || got.Final.Retryable || got.Final.HTTPStatus != http.StatusOK || got.Final.AmountMinor != tc.amount || got.Final.Reason != fixture.reason || got.Final.Message != fixture.message {
|
||||
t.Errorf("Sale(%s) final=%+v, want %s/nonretryable/HTTP200/amount%d and %q/%q", tc.name, got.Final, tc.outcome, tc.amount, fixture.reason, fixture.message)
|
||||
}
|
||||
wantReceipt := "synthetic initial receipt"
|
||||
if tc.name == "confirmation_metadata/overrides" {
|
||||
wantReceipt = "synthetic confirmation receipt"
|
||||
}
|
||||
if tc.name == "confirmation_metadata/empty_overrides" {
|
||||
wantReceipt = ""
|
||||
}
|
||||
if !reflect.DeepEqual(got.Receipts, []string{wantReceipt}) || got.PersistenceCount != 0 {
|
||||
t.Errorf("Sale(%s) receipts/persistence=%v/%d, want [%q]/0", tc.name, got.Receipts, got.PersistenceCount, wantReceipt)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreditCallSaleConfirmationPreservesMergedFields(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name, rawXML, receipt string
|
||||
confirmation map[string]string
|
||||
approved bool
|
||||
}{
|
||||
{name: "minimal approval", confirmation: map[string]string{types.TransactionResult: "APPROVED"}, receipt: "synthetic initial receipt", approved: true},
|
||||
{name: "confirmation overrides", confirmation: map[string]string{types.TransactionResult: "APPROVED", types.Reference: "SYNTH-CONFIRMED", types.TotalAmount: "2500", types.CardHash: "", types.ReceiptDataCardholder: "synthetic confirmation receipt"}, receipt: "synthetic confirmation receipt", approved: true},
|
||||
{name: "SDK-only uncertainty", confirmation: map[string]string{types.Errors: "ClientNotConnectedToServer"}, receipt: "synthetic initial receipt"},
|
||||
{name: "partial approved XML", rawXML: "<TransactionResult><Entry><Key>TRANSACTION_RESULT</Key><Value>APPROVED</Value></Entry><Entry>", receipt: "synthetic initial receipt"},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
initial := creditCallDiagnosticFields("APPROVED", "")
|
||||
initial[types.TotalAmount] = "3100"
|
||||
initial["AUTH_DATE_TIME"], initial["CARDEASE_REFERENCE"] = "20300101120000", "synthetic-authorization"
|
||||
expected := map[string]string{}
|
||||
for key, value := range initial {
|
||||
if key != types.ReceiptDataCardholder {
|
||||
expected[key] = value
|
||||
}
|
||||
}
|
||||
for key, value := range tc.confirmation {
|
||||
if key != types.ReceiptDataCardholder {
|
||||
expected[key] = value
|
||||
}
|
||||
}
|
||||
var receipts []string
|
||||
starts, confirms := 0, 0
|
||||
body := &creditCallDiagnosticBody{}
|
||||
app := &App{cfg: &config.ConfigRec{}, creditCallReceipt: func(receipt string) { receipts = append(receipts, receipt) }}
|
||||
app.creditCallTransport = creditCallRoundTrip(func(r *http.Request) (*http.Response, error) {
|
||||
confirms++
|
||||
if r.URL.Path != "/confirm-transaction/" {
|
||||
t.Errorf("unexpected confirmation path %q", r.URL.Path)
|
||||
}
|
||||
wire := tc.rawXML
|
||||
if wire == "" {
|
||||
wire = chipDNAFixture(t, tc.confirmation)
|
||||
}
|
||||
body.Reader = strings.NewReader(wire)
|
||||
return &http.Response{StatusCode: http.StatusOK, Body: body}, nil
|
||||
})
|
||||
outcome := app.executeCreditCallSale(cmstypes.TransactionRec{AmountMinorUnits: "1234"}, func(*http.Client) (creditcall.TransactionResultXML, error) {
|
||||
starts++
|
||||
var result creditcall.TransactionResultXML
|
||||
for key, value := range initial {
|
||||
result.Entries = append(result.Entries, creditcall.EntryXML{Key: key, Value: value})
|
||||
}
|
||||
return result, nil
|
||||
})
|
||||
if outcome.Approved != tc.approved || !reflect.DeepEqual(outcome.Payment.Fields, expected) || outcome.Payment.CardholderReceipt != tc.receipt {
|
||||
t.Errorf("Sale(%s) approved/fields/receipt=%t/%v/%q, want %t/%v/%q", tc.name, outcome.Approved, outcome.Payment.Fields, outcome.Payment.CardholderReceipt, tc.approved, expected, tc.receipt)
|
||||
}
|
||||
if !tc.approved && (outcome.Status.Message != "unknown" || outcome.FailureType != "unknown" || outcome.Payment.Status.Message != "APPROVED") {
|
||||
t.Errorf("Sale(%s) status/failure/payment status=%+v/%q/%+v, want uncertainty without mutating merged authorization evidence", tc.name, outcome.Status, outcome.FailureType, outcome.Payment.Status)
|
||||
}
|
||||
if starts != 1 || confirms != 1 || !body.closed || !reflect.DeepEqual(receipts, []string{tc.receipt}) {
|
||||
t.Errorf("Sale(%s) starts/confirms/closed/receipts=%d/%d/%t/%v, want 1/1/true/[%q]", tc.name, starts, confirms, body.closed, receipts, tc.receipt)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreditCallConfirmationRetryAndFailureParity(t *testing.T) {
|
||||
for _, streaming := range []bool{false, true} {
|
||||
var attempts int
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
|
||||
`buildVersion` is a const in `cmd/hardlink/main.go`.
|
||||
|
||||
#### v2.2.4 - 05 November 2026
|
||||
fix(creditcall): require fresh confirmation approval for sale
|
||||
|
||||
#### v2.2.3 - 05 November 2026
|
||||
fix(creditcall): preserve detailed SDK failure diagnostics
|
||||
|
||||
|
||||
Reference in New Issue
Block a user