Skip to content

feat: implement MonnifyGateway (Nigeria - bank transfer + card)#26

Merged
teesofttech merged 6 commits into
masterfrom
feature/issue-9-monnify-gateway
Jun 4, 2026
Merged

feat: implement MonnifyGateway (Nigeria - bank transfer + card)#26
teesofttech merged 6 commits into
masterfrom
feature/issue-9-monnify-gateway

Conversation

@teesofttech

@teesofttech teesofttech commented Jun 4, 2026

Copy link
Copy Markdown
Owner

Summary

Implements the Monnify payment gateway (by Moniepoint) for Nigeria NGN payments.

Changes

  • PaymentGatewayType.cs — added Monnify = 7
  • PaymentGatewayConfig.cs — added MonnifyConfig with ApiKey, SecretKey, ContractCode
  • Gateways/MonnifyGateway.cs — full implementation: create, verify, refund
  • IServiceCollectionExtensions.cs — registered MonnifyGateway in DI
  • PaymentGatewayFactory.cs — added Monnify to factory switch + nullable fix
  • PaymentService.cs — NGN currency now prefers Monnify; added MNF_ prefix detection

How it works

  • Authentication: Basic Auth (ApiKey:SecretKey) → Bearer token per request
  • Create: POST /api/v1/merchant/transactions/init-transaction
  • Verify: GET /api/v2/merchant/transactions/query?paymentReference={ref}
  • Refund: POST /api/v1/merchant/refunds/initiate-refund

Config (appsettings.json)

"PaymentGatewayConfig": {
  "Monnify": {
    "ApiKey": "YOUR_API_KEY",
    "SecretKey": "YOUR_SECRET_KEY",
    "ContractCode": "YOUR_CONTRACT_CODE"
  }
}

Closes #9

Summary by CodeRabbit

  • New Features
    • Monnify payment gateway is now available as a payment processing option
    • Support for creating payments, verifying transactions, and processing refunds through Monnify
    • New configuration properties added to specify Monnify gateway credentials
    • Monnify is automatically recognized for NGN currency payments

Copilot AI review requested due to automatic review settings June 4, 2026 08:31
@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@teesofttech, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 11 minutes and 16 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8d6ff0d6-f2f3-47a6-9dec-ca60f513f403

📥 Commits

Reviewing files that changed from the base of the PR and between b32bd0f and c3c178a.

📒 Files selected for processing (2)
  • PayBridge.SDK/Externsions/IServiceCollectionExtensions.cs
  • PayBridge.SDK/Gateways/MonnifyGateway.cs
📝 Walkthrough

Walkthrough

This pull request implements the Monnify payment gateway for Nigeria, adding configuration schemas, provider type enumeration, dependency injection wiring, a complete gateway implementation with payment creation/verification/refund operations, and updates to payment service routing for NGN currency and transaction reference detection.

Changes

Monnify Payment Gateway

Layer / File(s) Summary
Monnify configuration and enum type
PayBridge.SDK/Dtos/PaymentGatewayConfig.cs, PayBridge.SDK/Enums/PaymentGatewayType.cs
Adds MonnifyConfig DTO with ApiKey, SecretKey, and ContractCode properties. Introduces PaymentGatewayType.Monnify = 7 enum member for provider identification.
Dependency injection and factory registration
PayBridge.SDK/Externsions/IServiceCollectionExtensions.cs, PayBridge.SDK/Factories/PaymentGatewayFactory.cs
Registers MonnifyGateway in the DI container as both a default gateway and a selectively enabled option. Updates factory to resolve and instantiate MonnifyGateway when the Monnify gateway type is requested.
MonnifyGateway implementation
PayBridge.SDK/Gateways/MonnifyGateway.cs
Implements IPaymentGateway with credential validation, Basic-auth token acquisition, payment creation (transaction init with checkout URL), payment verification (status mapping, amount and date extraction), and refund processing (reference generation and tracking).
Payment service routing updates
PayBridge.SDK/Services/PaymentService.cs
Updates gateway selection for NGN currency to include Monnify alongside Paystack and Flutterwave. Extends transaction reference prefix detection to map MNF_ to Monnify and handle both FW_ and FLW_ prefixes for Flutterwave.

Sequence Diagram

sequenceDiagram
  participant Client
  participant MonnifyGateway
  participant MonnifyAPI as Monnify Auth/API
  participant GatewayResponse as Response Handler
  
  Client->>MonnifyGateway: CreatePaymentAsync(request)
  MonnifyGateway->>MonnifyAPI: GetAccessTokenAsync via Basic-auth
  MonnifyAPI-->>MonnifyGateway: accessToken
  MonnifyGateway->>MonnifyAPI: POST /api/v1/transactions/init with token
  MonnifyAPI-->>MonnifyGateway: checkoutUrl or error
  MonnifyGateway->>GatewayResponse: parse responseBody and map to PaymentResponse
  GatewayResponse-->>Client: PaymentResponse (pending + checkoutUrl)
  
  Client->>MonnifyGateway: VerifyPaymentAsync(reference)
  MonnifyGateway->>MonnifyAPI: GetAccessTokenAsync
  MonnifyAPI-->>MonnifyGateway: accessToken
  MonnifyGateway->>MonnifyAPI: GET /api/v1/transactions/query?reference
  MonnifyAPI-->>MonnifyGateway: paymentStatus, amountPaid, completedOn, fee
  GatewayResponse->>GatewayResponse: map Monnify status to internal PaymentStatus
  GatewayResponse-->>Client: VerificationResponse with payment details
  
  Client->>MonnifyGateway: RefundPaymentAsync(request)
  MonnifyGateway->>MonnifyAPI: GetAccessTokenAsync
  MonnifyAPI-->>MonnifyGateway: accessToken
  MonnifyGateway->>MonnifyAPI: POST /api/v1/transactions/refunds with token
  MonnifyAPI-->>MonnifyGateway: refundReference or error
  GatewayResponse->>GatewayResponse: parse response and map to RefundResponse
  GatewayResponse-->>Client: RefundResponse (refunded + RefundDate)
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly Related Issues

  • #9: This PR directly implements the objectives of the linked issue, which calls for Monnify gateway support with the same files and API integration points.
  • #10, #11, #12: These issues likely add other payment gateway providers following the same pattern of modifying PaymentGatewayConfig, PaymentGatewayType, and adding new Gateways implementations, so they are structurally related and may share merge conflict patterns on common SDK registration points.

Poem

🐰 A rabbit hops through gateways green,
Where Nigeria's Monnify coin doth gleam—
With tokens auth'd and payments verified,
Refunds swift and systems wired,
Cross-border payments now aligned! 🪙✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.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 accurately summarizes the main change: implementing the MonnifyGateway for Nigeria with bank transfer and card payment support.
Linked Issues check ✅ Passed All coding requirements from issue #9 are met: MonnifyGateway class added with create/verify/refund operations, configuration DTOs added, enum updated, DI registration implemented, factory updated.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing the Monnify gateway as specified in issue #9; no unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/issue-9-monnify-gateway

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 and usage tips.

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

Implements a new Nigeria (NGN) payment option by adding a Monnify gateway and wiring it into gateway selection and registration so the SDK can initiate, verify, and refund Monnify transactions.

Changes:

  • Added Monnify to the gateway enum/config and introduced a full MonnifyGateway implementation (create/verify/refund).
  • Updated DI + factory wiring to include Monnify and updated NGN routing / reference-prefix detection to recognize Monnify and Flutterwave prefixes.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
PayBridge.SDK/Services/PaymentService.cs Prefer Monnify for NGN and detect MNF_ / FLW_ prefixes.
PayBridge.SDK/Gateways/MonnifyGateway.cs New Monnify gateway implementation (auth, create, verify, refund).
PayBridge.SDK/Factories/PaymentGatewayFactory.cs Add Monnify to gateway initialization switch and allow null gateway resolution.
PayBridge.SDK/Externsions/IServiceCollectionExtensions.cs Register Monnify in DI under enabled/all-gateways paths.
PayBridge.SDK/Enums/PaymentGatewayType.cs Add Monnify = 7.
PayBridge.SDK/Dtos/PaymentGatewayConfig.cs Add MonnifyConfig (ApiKey/SecretKey/ContractCode).

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

Comment thread PayBridge.SDK/Externsions/IServiceCollectionExtensions.cs
Comment thread PayBridge.SDK/Externsions/IServiceCollectionExtensions.cs
Comment thread PayBridge.SDK/Gateways/MonnifyGateway.cs
Comment thread PayBridge.SDK/Gateways/MonnifyGateway.cs Outdated
Comment thread PayBridge.SDK/Gateways/MonnifyGateway.cs Outdated

@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.

Actionable comments posted: 3

🤖 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.

Inline comments:
In `@PayBridge.SDK/Externsions/IServiceCollectionExtensions.cs`:
- Line 135: Register MonnifyGateway under the IPaymentGateway service type so
PaymentService (which resolves IEnumerable<IPaymentGateway> into _gateways) will
include it; replace the concrete-only registration of MonnifyGateway
(services.AddScoped<MonnifyGateway>()) with a scoped registration that maps
IPaymentGateway to MonnifyGateway (or add an additional
AddScoped<IPaymentGateway, MonnifyGateway>() alongside the concrete
registration) for both places where MonnifyGateway is currently registered so it
appears in the resolved _gateways collection.

In `@PayBridge.SDK/Gateways/MonnifyGateway.cs`:
- Around line 29-31: The MonnifyGateway constructor is using
IOptions<PaymentGatewayConfig> which doesn't match how AddPayBridge registers a
singleton PaymentGatewayConfig; change the constructor signature to accept a
concrete PaymentGatewayConfig (replace IOptions<PaymentGatewayConfig> config
with PaymentGatewayConfig config) and assign _config = config so the runtime
config from AddPayBridge (and credentials set via configAction) are used; update
any references to config.Value accordingly and keep ILogger<MonnifyGateway>
logger and IHttpClientFactory unchanged.
- Line 65: The MonnifyGateway is currently logging the raw auth response via the
_logger.LogDebug("Monnify auth response: {Body}", body) call which can expose
sensitive tokens; update the MonnifyGateway to stop emitting the full response
body — either remove the LogDebug call or replace it with a safe, redacted log
that parses the response and omits or masks sensitive fields like
accessToken/refreshToken (e.g., log only status, expiry, or a boolean indicating
token presence) so the raw credentials are never written to logs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 79969f6e-217f-40f7-8840-006caa84c781

📥 Commits

Reviewing files that changed from the base of the PR and between dbefb11 and b32bd0f.

📒 Files selected for processing (6)
  • PayBridge.SDK/Dtos/PaymentGatewayConfig.cs
  • PayBridge.SDK/Enums/PaymentGatewayType.cs
  • PayBridge.SDK/Externsions/IServiceCollectionExtensions.cs
  • PayBridge.SDK/Factories/PaymentGatewayFactory.cs
  • PayBridge.SDK/Gateways/MonnifyGateway.cs
  • PayBridge.SDK/Services/PaymentService.cs

Comment thread PayBridge.SDK/Externsions/IServiceCollectionExtensions.cs
Comment thread PayBridge.SDK/Gateways/MonnifyGateway.cs
Comment thread PayBridge.SDK/Gateways/MonnifyGateway.cs Outdated
teesofttech and others added 5 commits June 4, 2026 10:18
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.

feat: implement MonnifyGateway (Nigeria - bank transfer + card)

2 participants