NAV

GiftPesa API Documentation

Last updated: 2023 Feb 24 06:27:15
shell

Introduction

Welcome to GiftPesa! Giftpesa is a gift management platform that automates the entire process of buying, disbursing and redeeming gift rewards.

You can use our api to disburse vouchers and track redemption of the disbursed vouchers in realtime

We currently have language bindings in Shell(Curl)! You can view code examples in the dark area to the right.

Incase of any difficulties reach out to us via email

Authentication

The Giftpesa API uses Access token keys to authenticate requests. On your gitpesa dashboard head to settings to generate your API Keys

Giftpesa API Key generate

and .crt files.

Giftpesa API Key generate

Your API keys carry many privileges, so be sure to keep them secure! Do not share your secret API keys in publicly accessible areas such as GitHub, client-side code, and so forth.

Generating Access token

To generate authorization token

curl "https://3api.giftpesa.com/authorize" \
  -H "Authorization: Basic <Base64 encoded string>" \
  -H "Username: <your account username>

HTTP Request

GET https://3api.giftpesa.com/authorize

To generate acess token generate the api key from the Giftpesa dashboard and get the Timestamp in yyyymmddhhmmss format. When you generate the API Key you also get access to key.crt file which will be used to encrypt requests

Once you have access to both the API KEY and Pem file, Encrypt the API_KEY:TIMESTAMP with the CRT file and base64 encode the result.

Perform the request to the endpoint to get an access token

Authorization: Basic {base64_encoded_string}

Merchants

curl "https://3api.giftpesa.com/merchants"
  -H "Authorization: Bearer {ACCESS_TOKEN}"

This endpoints the list of merchants and their respective categories

HTTP Request
GET https://3api.giftpesa.com/merchants

Response

[
  {
    "MerchantID": "naivas",
    "Merchant": "Naivas",
    "Category": {
      "ID": "supermarkets",
      "Label": "Supermarkets"
    }
  },
  {
    "MerchantID": "pizza-inn",
    "Merchant": "Pizza Inn",
    "Category": {
      "ID": "cafes-restaurants",
      "Label": "Cafes and Restaurants"
    }
  }
]

Disbursements

Create a new Disbursement

curl "https://3api.giftpesa.com/disburse"
  -H "Authorization: Bearer {ACCESS_TOKEN}"

Example Payload [Name Phone and Amount required in the recipient list]

{
  "DisbursementID": "<DisbursementID>",
  "DisbursementTitle": "XYZ Disbursement",
  "VoucherStartDate": "20210512",
  "VoucherEndDate": "20210820",
  //Merchant Ids, Leave blank for open vouchers
  "Merchant":["naivas","quickmart"],
  "Recipients": [
    {
      "Name": "Jane Doe",
      "Phone": "07XXXXXXXX",
      "Amount": 100,
      ...
    },
    {
      "Name": "John Doe",
      "Phone": "07XXXXXXXX",
      "Amount": 50,
      ...
    },
    ...
  ],
  //Enable redemption from an external paybill
  "External": true,
  "CallbackURL": "https://test2.com",
  "SupressNotifications": true,
}

Response

{
  "DisbursementID": "<DisbursementID>",
  "RecipientsCount": 2,
  "Amount": 150,
  "Cost": 45
  ...
}

This is an object representing creating a new disbursement. You can initiate a new disbursement by invoking a request to the endpoint below.

HTTP Request

POST https://3api.giftpesa.com/disburse

Parameter Required Description
DisbursementID true Internal Unique Disbursement Identifier
DisbursementTitle true Title identifier for the disbursement
VoucherStartDate(yyyymmdd) false Voucher activation date.
VoucherEndDate(yyyymmdd) false Voucher expiry date
Merchant false List of merchant identifiers you wish to lock your voucher in. Leave blank for open vouchers
Recipients true List of recipients (Required fields for each recipient -> Name, Amount, Phone)
External false Enable Processing of redemptions from external sources
CallbackURL false A notification endpoint where GiftPesa will send responses on processing disbursments and successfull redemptions ** It must be a secure accessible URL **
SuppressNotifications false Prevent Giftpesa from sending messages on disbursement and redemption

Disbursement Query

curl "https://3api.giftpesa.com/query/:id"
  -H "Authorization: Bearer {ACCESS_TOKEN}"

Response

{
  "DisbursementID": "<DisbursementID>",
  "Status": "success",
  "Amount": 100,
  "RecipientsCount": 1,
  "AmountDisbursed":100,
  ...
}

This is an object representing querying the status of a disbursement.

HTTP Request

GET https://3api.giftpesa.com/query/:id

URL Parameters

Parameter Description
DisbursementID The Internal DisbursementIdentifier

Redeem

curl "https://3api.giftpesa.com/redeem"
  -H "Authorization: Bearer {ACCESS_TOKEN}"

Example Payload

{
  "TransactionID": "<TransactionID>",
  "Name": "Jane Doe",
  "Phone": "+254720XXXXXX",
  "TillNo": "123456",
  "Amount": 10,
  "Remarks": "Weekly shopping",
}

Response

{
  "TransactionID": "<TransactionID>",
  "Status": "success",
  "ReceiptNo": "PEKL98SO",
  "TransactionCode": "A9012333",
  "TrasanctionDate": "2020-28-06 19:02:50",
  "Merchant": "Naivas - EastGate",
  "TillNo": "123456",
  "Amount": 10,
  "Message": "PEKL98SO confirmed. KES 10 redeemed at Naivas - Eastgate on 2020-28-06 19:02:50."
}

This is an object representing redeeming a in one of our partner merchants. You can initiate a new redemption by invoking a request to the endpoint below.

HTTP Request

POST https://3api.giftpesa.com/redeem

Parameter Required Description
TransactionID true Internal Unique Disbursement Identifier
Name true Recipient name
Phone true Recipient phone
Amount true Redemption amount
TillNo true Mpesa till no of the redemption outlet
Remarks false Redemption transaction remarks

Callbacks

** In the case the callback url is unreacheable the system will retry upto 10 times in the next hour after initial try **

Disbursement Callback

POST <your callback url> This represents the structure of the payload to expect on the callback url

Parameter Description
DisbursementID Internal Unique Disbursement Identifier
DisbursementTitle Title identifier for the disbursement
VoucherStartDate(yyyymmdd) Voucher activation date.
VoucherEndDate(yyyymmdd) Voucher expiry date
Merchant List of merchant identifiers you wish to lock your voucher in.
Recipients List of recipients (Name, Amount, Phone, Voucher Code)
Amount Requested Disbursement Amount
AmountDisbursed Requested Disbursement Amount
CreatedAt Date Disbursement was created
DateProcessed Date Disbursement was processed
Status Disbursement Status (sucess / failed)
TransactionCode Giftpesa Transaction code if successfull

Redemption Callback

POST <your callback url> This represents the structure of the payload to expect on the callback url

Parameter Description
Phone User Phone Number
Amount Redemption Amount
TillNo Redemption Till No
Transaction Date Date of the transaction
TransactionCode Giftpesa Transaction Code
Status Giftpesa Transaction Code
MpesaCode Mpesa Transaction Code
Merchant ID and Name of the Merchant (If exists)
Recipients List of recipients (Name, Amount, Phone, Voucher Code)
VoucherCodes All Voucher codes affected by the transaction *1
Mode Redemption Mode identifier (USSD, Web, Mpesa Miniapp)

Errors

GiftPesa uses the following error codes

Error Code Meaning
400 Bad Request -- Your request is invalid.
401 Unauthorized -- Invalid API Key / Access Token.
403 Forbidden -- Forbidden resource access.
404 Not Found -- The specified resource could not be found.
405 Method Not Allowed -- Method not allowed on resource.
406 Not Acceptable -- Invalid request format.
429 Too Many Requests -- Request overload
500 Internal Server Error -- We had a problem with our server. Try again later.
503 Service Unavailable -- We're temporarily offline for maintenance. Please try again later.