PAY HERO DOCS
  • Introduction-Pay Hero Developer APIs
  • Creating Account
  • Authorization
  • GET: Service Wallet Balance
  • GET: Payments Wallet Balance
  • POST: Service Wallet Top Up
  • POST: Initiate MPESA STK Push Request
  • Payment Button
  • Lipwa Link
  • POST: Pay Hero Wallet- Withdraw To Mobile
  • GET: Account Transactions
  • GET: Transaction Status
  • WooCommerce Plugin
    • Plugin Installation
  • Shopify
  • Videos
  • Other Integrations
  • Email API Reference
    • Register SMTP
    • Send Email
    • Mail status
  • WhatsApp API Reference
    • Introduction
    • Getting Started
    • Send API Whats App Text
    • Bulk WhatsApp API Messaging
    • Bulk WhatsApp Using UI/CSV File
Powered by GitBook
On this page
  • API Method
  • This endpoint enables you to get paid to your payments wallet.
  • Sample Code
  • Callback URL Response Sample

Was this helpful?

POST: Pay Hero Wallet- Request Payment

This endpoint is used to collect funds to your payments wallet

Pay Hero wallet enables your customers to pay you using MPESA,. In this documentation, we will show you how to initiate payments

API Method

This endpoint enables you to get paid to your payments wallet.

POST https://backend.payhero.co.ke/api/v2/payments

Headers

Name
Type
Description

Authorization:*

String

Basic basicAuthToken

Request Body

Name
Type
Description

amount*

Integer

Amount you want to get paid eg: 10

phone_number*

String

Customer phone number to make the payment eg: 0787655535

provider*

String

Value: sasapay

network_code*

String

A unique digit code used for identifying the various mobile money providers

63902 (MPesa)

external_reference

String

Your unique reference to track this transaction Eg: INV-009

callback_url

String

Your endpoint URL that we will use to send payment status response eg: https://example.com/callback.php

{
    "success": true,
    "status": "QUEUED",
    "reference": "TX97JU3E1K",
    "CheckoutRequestID": "60122767-bce3-4749-8129-a7bba7726dc8",
    "manual_instructions": "1. GO TO 'LIPA NA MPESA' 2. SELECT 'PAY BILL' 3. ENTER BUSINESS NUMBER: 756756  4. ENTER ACCOUNT NUMBER: PR5161667  5. ENTER AMOUNT:10 6. ENTER YOUR MPESA PIN AND PRESS OK"
}

Sample Code

This represents PHP Curl example of how to make the request, you can implement this in your specific language of choice

<?php
$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://backend.payhero.co.ke/api/v2/payments',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>'{
    "amount": 10,
    "phone_number": "0798988787",
    "provider": "sasapay", 
    "network_code":"63902",
    "external_reference": "INV-99992",
    "callback_url": "https://example.com/callback.php"
}',
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json',
    'Authorization: Basic 3A6anVoWFZrRk5qSVl0MGNMOERGMlR3dlhrQ0VWUWJHNDVVVnNaMEdDSw=='
  ),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;

Callback URL Response Sample

This represents the JSON that will be sent to your request callback_url, NOTE: it contains the ExternalReference that you provided in the request and CheckoutRequestID that was returned in the request response, you can use those to track and update your payments in your system/app

{
  "forward_url": "",
  "response": {
    "Amount": 10,
    "CheckoutRequestID": "d12c6aeb-ce42-45c6-af02-ce4b8d3596f0",
    "ExternalReference": "INV-99992",
    "MerchantRequestID": "7ZBNDZFT6T",
    "MpesaReceiptNumber": "SAF24HOLGA",
    "Phone": "254798988787",
    "ResultCode": 0,
    "ResultDesc": "Transaction processed successfully.",
    "Status": "Success"
  },
  "status": true
}

Last updated 6 months ago

Was this helpful?