M-Pesa Reversal
AI-generatedOverview
This node performs a reversal of an M-Pesa transaction. It is designed to reverse either the full amount or a partial amount of a previously completed M-Pesa payment. This functionality is useful in scenarios such as correcting erroneous payments, handling refunds, or canceling transactions that were made by mistake.
Practical examples include:
- Reversing a full payment when a customer cancels an order.
- Partially refunding a transaction if only part of the service/product was delivered.
- Automatically triggering reversals in workflows that detect failed deliveries or disputes.
Properties
| Name | Meaning |
|---|---|
| Transaction ID | The unique identifier of the M-Pesa transaction to be reversed. |
| Third Party Reference | A unique reference string from the third-party system initiating the reversal (max 20 chars). |
| Service Provider Code | The shortcode identifying the service provider (usually preconfigured in credentials). |
| Initiator Identifier | Identifier of the initiator authorized to perform the reversal (usually from credentials). |
| Security Credential | Security credential (password/token) used to authenticate the reversal request. |
| Reversal Amount | The amount to reverse; optional for full reversal, required for partial reversal. |
| Reversal Type | Specifies whether the reversal is full (entire transaction amount) or partial (specified amount). Options: Full Reversal, Partial Reversal |
Output
The node outputs JSON data containing the response from the M-Pesa API along with metadata about the reversal request:
output_ResponseCode: Indicates success or failure of the reversal request (success code is"INS-0").request: Echoes back the input parameters used for the reversal.reversalType: Indicates if the reversal was full or partial.success: Boolean flag indicating if the reversal succeeded.timestamp: ISO timestamp of when the reversal was processed.
If the node encounters errors and "Continue On Fail" is enabled, it outputs an error message per item instead of stopping execution.
No binary data output is produced by this node.
Dependencies
- Requires an API key credential for authenticating with the M-Pesa API.
- Uses an internal helper class to make HTTP requests to the M-Pesa reversal endpoint (
/ipg/v1x/reversal/). - The node expects certain credential fields to be configured: service provider code, initiator identifier, and security credential.
Troubleshooting
- Missing Required Fields: Errors will occur if mandatory fields like Transaction ID, Third Party Reference, Initiator Identifier, or Security Credential are missing.
- Third Party Reference Length: If the third party reference exceeds 20 characters, the node throws an error.
- Invalid Reversal Amount: For partial reversals, the reversal amount must be provided and be a positive number.
- API Errors: If the M-Pesa API returns an error code other than
"INS-0", the reversal is considered unsuccessful. - Credential Issues: Incorrect or missing credentials will cause authentication failures.
- To resolve these issues, verify all required inputs, ensure references meet length constraints, provide valid numeric amounts for partial reversals, and confirm credentials are correctly set up.
Links and References
- M-Pesa API Documentation (general reference for M-Pesa APIs)
- n8n Documentation on Creating Nodes