fix: add ShouldFail to Square MockClient for testing payment error paths

This commit is contained in:
2026-07-11 16:07:05 +01:00
parent ce0bb43ebf
commit 05c5d73d30
2 changed files with 50 additions and 0 deletions
+7
View File
@@ -30,6 +30,7 @@ type MockClient struct {
refunds map[string]*RefundResult
completed map[string]*PaymentResult
HoldCheckouts bool
ShouldFail bool // if true, CreatePayment/RefundPayment return errors for testing error paths
}
type devProdClient struct{}
@@ -80,6 +81,9 @@ func NewDevClient() SquareClient {
}
func (m *MockClient) CreatePayment(ctx context.Context, req CreatePaymentReq) (*PaymentResult, error) {
if m.ShouldFail {
return nil, fmt.Errorf("mock: payment declined (simulated failure)")
}
log.Printf("[SQUARE-MOCK] CreatePayment: amount=%d, reference=%s", req.Amount, req.ReferenceID)
mockSleep(1 * time.Second)
@@ -183,6 +187,9 @@ func (m *MockClient) GetCheckout(ctx context.Context, checkoutID string) (*Payme
}
func (m *MockClient) RefundPayment(ctx context.Context, req RefundPaymentReq) (*RefundResult, error) {
if m.ShouldFail {
return nil, fmt.Errorf("mock: refund declined (simulated failure)")
}
log.Printf("[SQUARE-MOCK] RefundPayment: payment=%s, amount=%d", req.PaymentID, req.Amount)
mockSleep(1 * time.Second)