more functions

This commit is contained in:
matst80
2025-11-20 21:34:39 +01:00
parent 60cd6cfd51
commit 729c67f992
6 changed files with 122 additions and 75 deletions

View File

@@ -101,8 +101,8 @@ func msgSubscriptionAdded(itemId uint32, detailsId, orderRef string) *messages.S
return &messages.SubscriptionAdded{ItemId: itemId, DetailsId: detailsId, OrderReference: orderRef}
}
func msgPaymentDeclined() *messages.PaymentDeclined {
return &messages.PaymentDeclined{}
func msgPaymentDeclined(message, code string) *messages.PaymentDeclined {
return &messages.PaymentDeclined{Message: message, Code: &code}
}
func msgConfirmationViewed() *messages.ConfirmationViewed {
@@ -650,12 +650,22 @@ func TestPaymentDeclined(t *testing.T) {
g := newTestGrain()
g.CheckoutOrderId = "test-order"
applyOK(t, reg, g, msgPaymentDeclined())
applyOK(t, reg, g, msgPaymentDeclined("Payment failed due to insufficient funds", "INSUFFICIENT_FUNDS"))
if g.PaymentStatus != "declined" || g.CheckoutOrderId != "" {
t.Fatalf("payment declined not handled: status=%s checkoutId=%s", g.PaymentStatus, g.CheckoutOrderId)
}
if g.PaymentDeclinedAt.IsZero() {
t.Fatalf("PaymentDeclinedAt not set")
if len(g.PaymentDeclinedNotices) != 1 {
t.Fatalf("expected 1 notice, got %d", len(g.PaymentDeclinedNotices))
}
notice := g.PaymentDeclinedNotices[0]
if notice.Message != "Payment failed due to insufficient funds" {
t.Fatalf("notice message not set correctly: %s", notice.Message)
}
if notice.Code == nil || *notice.Code != "INSUFFICIENT_FUNDS" {
t.Fatalf("notice code not set correctly: %v", notice.Code)
}
if notice.Timestamp.IsZero() {
t.Fatalf("notice timestamp not set")
}
}