How to Test Pay Hero API Callbacks Using Beeceptor

Testing API callback responses is a crucial step in ensuring your application works seamlessly with third-party services. Beeceptor is a powerful tool that helps you mock and inspect these callbacks without needing your actual production endpoint to be available.

In this guide, we will walk you through the steps to use Beeceptor for testing Pay Hero Kenya API callback responses.

Step 1: Create a New Endpoint on Beeceptor

  1. Sign Up: Visit Beeceptor and sign up for a free account. Log in to your dashboard.
  2. Create a Mock Server: Look for the “Launch a mock server now!” section.
  3. Name Your Endpoint: Enter a name for your project (e.g., payhero-test). Your dedicated endpoint will look like: https://payhero-test.free.beeceptor.com.
  4. Launch: Click “Create Mock Server” to activate the URL.

Step 2: Configure Your Beeceptor Endpoint

  • Inspect Requests: Under the Requests tab, Beeceptor will list all incoming traffic. This allows you to see the headers and JSON payload sent by Pay Hero in real-time.
  • Set Up Rules (Optional): If you want to simulate specific server responses (like a 200 OK or a 500 Error), go to the Rules tab to define how Beeceptor should respond when it receives a callback.

Step 3: Update Pay Hero to Use the Beeceptor URL

There are two ways to tell Pay Hero where to send your transaction data:

  1. Via API Request: In your API request body, set the callback_url parameter to your Beeceptor URL (e.g., https://payhero-test.free.beeceptor.com).
  2. Via Account Settings (Universal): * Log in to app.payhero.co.ke.
    • Navigate to Account Menu > Update Account.
    • Enter your Beeceptor URL in the Callback URL field and save. Note: Use this if you want all account transactions to hit the same test endpoint.

Step 4: Trigger and Verify the Callback

  1. Initiate a Transaction: Perform an action on Pay Hero that triggers a callback, such as initiating an STK Push or a test payment. Refer to the Pay Hero Developer Docs for specific API calls.
  2. Check Beeceptor: Switch back to your Beeceptor dashboard. You should see a new entry appearing in the “Requests” list.
  3. Verify Data: Click the request to view the payload. Ensure the transaction details (Amount, Phone Number, Reference) match what you expect.

Step 5: Simulate Different Scenarios (Optional)

To ensure your app is robust, you should test how it handles failures:

  • Go to the Rules tab in Beeceptor.
  • Modify the response to return a 400 Bad Request or a specific error message.
  • Re-trigger the callback from Pay Hero to see how your system reacts to the error.

Beeceptor is an essential tool for developers who want to build and debug integrations without the headache of setting up public-facing servers during the early stages of development. By following these steps, you can ensure your Pay Hero integration is reliable and production-ready.



Leave a Reply

Your email address will not be published. Required fields are marked *