Skip to content

Core: harden enabled gateway startup validation (#66)#125

Merged
teesofttech merged 2 commits into
masterfrom
core/issue-66-enabled-gateway-validation
Jul 18, 2026
Merged

Core: harden enabled gateway startup validation (#66)#125
teesofttech merged 2 commits into
masterfrom
core/issue-66-enabled-gateway-validation

Conversation

@teesofttech

@teesofttech teesofttech commented Jul 18, 2026

Copy link
Copy Markdown
Owner

Summary

  • validate EnabledGateways as a strict set: reject undefined enum values, reject Automatic, and reject duplicates
  • keep placeholder credentials fail-fast behavior and ensure missing required fields are reported
  • return a single aggregated startup configuration error containing all detected enabled-gateway issues
  • validate undefined DefaultGateway values with a clear startup error
  • add unit tests for duplicate, undefined, and placeholder-credential enabled-gateway cases

Validation

  • dotnet test PayBridge.SDK.Test/PayBridge.SDK.Test.csproj --filter "Category=Unit"
  • result: 162 passed, 0 failed

Addresses #66

Summary by CodeRabbit

  • Bug Fixes
    • Improved payment gateway configuration validation.
    • Invalid, duplicate, or undefined enabled gateways are now reported clearly.
    • Missing gateway credentials are identified with their configuration paths.
    • Invalid default gateway values are rejected.
    • Multiple configuration issues are reported together in a single error.

Copilot AI review requested due to automatic review settings July 18, 2026 16:02
@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

AddPayBridge now validates gateway enum values, duplicate enabled gateways, automatic gateway usage, and required configuration keys, aggregating errors into one exception. Default gateway values are also checked, with tests covering duplicate, undefined, and placeholder credential scenarios.

Changes

Gateway configuration validation

Layer / File(s) Summary
Gateway validation implementation
PayBridge.SDK/Externsions/IServiceCollectionExtensions.cs
Enabled gateways are validated for defined enum values, duplicates, disallowed Automatic, and missing required settings; default gateways are also checked for defined enum values.
Validation test coverage
PayBridge.SDK.Test/Unit/IServiceCollectionExtensionsTests.cs
Tests verify exceptions for duplicate gateways, undefined gateway values, and placeholder Paystack credentials.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant AddPayBridge
  participant GatewayValidation
  participant PaymentConfigurationException
  AddPayBridge->>GatewayValidation: validate gateway configuration
  GatewayValidation->>GatewayValidation: collect invalid values and missing keys
  GatewayValidation->>PaymentConfigurationException: throw aggregated errors
Loading

Possibly related issues

Possibly related PRs

Suggested labels: area: gateways, area: core

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: stricter startup validation for enabled gateways.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch core/issue-66-enabled-gateway-validation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens PayBridge SDK startup validation for gateway configuration to ensure misconfigured EnabledGateways/DefaultGateway fail deterministically during service registration (per Issue #66).

Changes:

  • Validates EnabledGateways as a strict set (rejects undefined enum values, rejects Automatic, rejects duplicates) and aggregates all enabled-gateway validation issues into a single startup exception.
  • Adds explicit startup validation for undefined DefaultGateway enum values.
  • Adds unit tests for duplicate/undefined enabled gateways and placeholder credential scenarios.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
PayBridge.SDK/Externsions/IServiceCollectionExtensions.cs Adds stricter startup validation for enabled gateways and undefined default gateway values, including aggregated enabled-gateway errors.
PayBridge.SDK.Test/Unit/IServiceCollectionExtensionsTests.cs Adds new unit tests for duplicate enabled gateways, undefined enabled gateway enum values, and placeholder credentials.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 209 to 213
if (!IsGatewayConfigured(config, gateway))
{
throw new PaymentConfigurationException(
errors.Add(
$"Enabled gateway '{gateway}' is missing required configuration values.");
}
Comment on lines +227 to +231
if (!Enum.IsDefined(typeof(PaymentGatewayType), config.DefaultGateway))
{
throw new PaymentConfigurationException(
$"Default gateway value '{(int)config.DefaultGateway}' is not a defined PaymentGatewayType.");
}
Comment on lines +216 to +222
if (errors.Count > 0)
{
throw new PaymentConfigurationException(
"Invalid PaymentGatewayConfig:EnabledGateways configuration:" +
Environment.NewLine +
string.Join(Environment.NewLine, errors.Select(error => $" - {error}")));
}

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
PayBridge.SDK/Externsions/IServiceCollectionExtensions.cs (1)

360-418: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider adding a default case for future-proofing.

If a new PaymentGatewayType is added in the future but this switch statement is not updated, GetMissingGatewayConfigurationKeys will silently fall through and return an empty list. This would result in a confusing validation error message like: is missing required configuration values: .

Adding a default case that throws an exception will help catch missed gateway configurations immediately during development.

♻️ Proposed refactor
             case PaymentGatewayType.PeachPayments:
                 AddIfMissing("PaymentGatewayConfig:PeachPayments:EntityId", config.PeachPayments.EntityId);
                 AddIfMissing("PaymentGatewayConfig:PeachPayments:AccessToken", config.PeachPayments.AccessToken);
                 break;
+            default:
+                throw new NotImplementedException($"Missing configuration keys check is not implemented for gateway '{gateway}'.");
         }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@PayBridge.SDK/Externsions/IServiceCollectionExtensions.cs` around lines 360 -
418, Add a default branch to the PaymentGatewayType switch in
GetMissingGatewayConfigurationKeys that throws an exception for unsupported or
newly added gateway values. Preserve all existing gateway-specific AddIfMissing
handling while ensuring unhandled enum values fail immediately instead of
returning an empty configuration-key list.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@PayBridge.SDK/Externsions/IServiceCollectionExtensions.cs`:
- Around line 360-418: Add a default branch to the PaymentGatewayType switch in
GetMissingGatewayConfigurationKeys that throws an exception for unsupported or
newly added gateway values. Preserve all existing gateway-specific AddIfMissing
handling while ensuring unhandled enum values fail immediately instead of
returning an empty configuration-key list.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 92758b8a-d251-45eb-a8ce-526c5a123ebe

📥 Commits

Reviewing files that changed from the base of the PR and between e4aa984 and a12c04c.

📒 Files selected for processing (2)
  • PayBridge.SDK.Test/Unit/IServiceCollectionExtensionsTests.cs
  • PayBridge.SDK/Externsions/IServiceCollectionExtensions.cs

@teesofttech
teesofttech merged commit 1957554 into master Jul 18, 2026
2 checks passed
@teesofttech
teesofttech deleted the core/issue-66-enabled-gateway-validation branch July 18, 2026 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants