visamasterpay: keep a payment pending while GBÜS still reports it in progress
Some checks failed
CI/CD / Vet, test, build (push) Has been cancelled
CI/CD / Docker image (push) Has been cancelled
CI/CD / Deploy binary to server (push) Has been cancelled

A status check that ran before the card was entered (orderStatus 0,
"no payment attempts") finalized the payment as failed, and later
callbacks returned it as already finalized without asking GBÜS again -
so cardholderName/maskedPan stayed null and a real payment was never
recorded. Unpaid in-progress statuses (0, 1, 5) now keep the row
pending with the latest response stored, and rows already failed that
way are re-checked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-24 22:58:49 +05:00
parent f1337706f0
commit 78e1976e53
3 changed files with 60 additions and 8 deletions

View File

@@ -58,6 +58,17 @@ type StatusResult struct {
RawResponse []byte
}
// InProgress reports an unpaid order GBÜS may still complete - registered
// but not attempted yet (0), pre-authorized (1) or in 3-D Secure (5) - so
// it must stay re-checkable instead of being finalized as failed. Reversed
// (3), refunded (4), declined (6) or any gateway error are final.
func (r StatusResult) InProgress() bool {
if r.ErrorCode != "" && r.ErrorCode != "0" {
return false
}
return r.OrderStatus == 0 || r.OrderStatus == 1 || r.OrderStatus == 5
}
// Client is the gateway contract. Plug a real HTTPClient in once
// credentials are configured; LogClient is a stand-in for local/dev use.
type Client interface {

View File

@@ -27,6 +27,27 @@ func TestRegisterResultSuccess(t *testing.T) {
}
}
func TestStatusResultInProgress(t *testing.T) {
cases := []struct {
name string
r StatusResult
want bool
}{
{"registered, not attempted", StatusResult{OrderStatus: 0, ErrorCode: "0"}, true},
{"pre-authorized", StatusResult{OrderStatus: 1}, true},
{"3-D Secure", StatusResult{OrderStatus: 5, ErrorCode: "0"}, true},
{"paid", StatusResult{Paid: true, OrderStatus: 2}, false},
{"reversed", StatusResult{OrderStatus: 3}, false},
{"declined", StatusResult{OrderStatus: 6, ErrorCode: "0"}, false},
{"gateway error", StatusResult{OrderStatus: 0, ErrorCode: "6"}, false},
}
for _, c := range cases {
if got := c.r.InProgress(); got != c.want {
t.Errorf("%s: InProgress()=%v want %v", c.name, got, c.want)
}
}
}
func TestLogClientAlwaysPaid(t *testing.T) {
c := NewLogClient(nil)
reg, err := c.Register(context.Background(), RegisterRequest{OrderNumber: "vmo-1-2", ReturnURL: "https://x/cb"})
@@ -74,8 +95,8 @@ func TestHTTPClientCheckStatusPaidMapping(t *testing.T) {
body string
paid bool
}{
{`{"orderStatus":2,"actionCode":"0"}`, true}, // 2 = deposited
{`{"orderStatus":1,"actionCode":0}`, false}, // numeric actionCode still decodes
{`{"orderStatus":2,"actionCode":"0"}`, true}, // 2 = deposited
{`{"orderStatus":1,"actionCode":0}`, false}, // numeric actionCode still decodes
{`{"orderStatus":6,"actionCode":"declined"}`, false},
}
for _, tc := range cases {