Hi! That 401 error usually means something is off with the authentication. With PayFast, the signature/passphrase must match exactly what they expect, and the parameters need to be in the right order and encoding.
A few things to check: make sure you’re using the correct passphrase for live vs sandbox. Sandbox and live credentials are separate, so using one with the other will fail. Also, PayFast requires the POST body to be URL-encoded exactly as documented, otherwise the signature won’t match.
In Bubble’s API Connector, set the method to POST, add the body parameters as form-data or JSON depending on their docs, and include merchant_id + subscription_id + signature. You might need to generate the signature dynamically in Bubble if it includes timestamp or parameter concatenation.
Here’s the answer for the PayFast 401 “Merchant authorization failed” error:
Problem: Getting 401 authorization error when calling PayFast Cancel Subscription API from Bubble despite using correct merchant_id and subscription_id.
Root Cause: PayFast authentication requires a correctly generated signature/passphrase that must match exactly what their system expects. The issue is usually with signature generation or parameter formatting.
Solutions:
1. Signature Generation Issue:
PayFast requires parameters to be concatenated in a specific order with the passphrase, then MD5 hashed. The signature format is:
URL: https://api.payfast.co.za/subscriptions/{subscription_token}/cancel Method: PUT Headers: merchant-id: <dynamic> timestamp: <dynamic ISO timestamp> signature: <dynamic MD5 hash> version: v1
Key Points:
Use PUT, not POST
Signature must include timestamp (that’s why it needs to be dynamic)
All parameters must be in alphabetical order before hashing
Sandbox and live have different passphrases
The signature generation is the tricky part - you may need a server-side plugin or backend workflow to generate the MD5 hash properly with all parameters in the right order.