Feat webhook#139
Open
watersRand wants to merge 3 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR introduces a unified callback routing feature (
MpesaClient.process_callback(payload)) that dynamically detects the signature and structure of incoming M-PESA webhook payloads (e.g., STK Push, Ratiba, B2C, Bill Manager) and automatically forwards them to their respective strongly-typed validation and parsing models.Closes #133
Motivation:
Reduces cognitive load significantly for developers integrating the SDK. Instead of manually inspecting the payload structure in their web controllers to decide whether to call
.process_stk_callback()or.process_ratiba_service_callback(), they can now pass any raw M-PESA JSON payload to a single, intuitive entry point.Additionally, this PR fixes a documentation example in the Dynamic QR Code Callback section. In alignment with official Safaricom Daraja documentation, the
RequestIDfield is omitted as it is not part of the standard Dynamic QR response schema.Type of Change
How Has This Been Tested?
TestUnifiedCallbackRoutinginsidetests/unit/test_mpesa_client.pyto verify accurate structural sniffing and correct downstream schema generation across distinct payloads (STK Push, Ratiba, B2B, etc.).test_process_ratiba_service_callbacklist-traversal structure passes cleanly without throwingAttributeError.Checklist
Additional Context
The sniffing router handles nuanced payload definitions (such as differentiating structural commonalities like
Resultparameters between Account Balance, Tax, and B2C transactions) by inspect-matching signature keys natively embedded within Safaricom’s standard response parameters.