Debit an Account

This endpoint allows you to debit a specified amount from a customer's account.

Method

  • POST

URL

  • /operations/debit

Input

The input data for this operation should be provided in the request body as a JSON object:

{
  "amount": "Amount we want to debit",
  "partnerReference": "Unique reference generated by API user",
  "customer": {
    "phone": "Customer's phone number preceded by the area code"
  }
}

Example Request

Here's an example of how to debit an account:

{
  "amount": 15000,
  "partnerReference": "001",
  "customer": {
    "phone": "+22892685526"
  }
}

Output

The API will return a JSON object with the details of the debit transaction, including:

  • Transaction Reference

  • Customer Details

  • Amount Debited

  • Transaction Status

  • Other relevant details.

HTTP Status Codes

  • 200 OK: The request was successful, and the debit transaction details are returned.

Important Note:

After initiating a debit operation, a code is transmitted to the customer. You will need to confirm or cancel the debit operation based on this code.

Example Code

Here is an example of how to make a POST request to debit an account:


import axios from 'axios';

const apiKey = 'your-api-key';
const apiSecret = 'your-api-secret';

const requestData = {
  amount: 15000,
  partnerReference: "001",
  customer: {
    phone: "+22892685526"
  }
};

axios.post('https://svc.test.bestcash.me/external/operations/debit', requestData, {
  headers: {
    'X-Auth-ApiKey': apiKey,
    'X-Auth-ApiSecret': apiSecret,
    'Content-Type': 'application/json'
  }
})
.then(response => {
  console.log('Debit Transaction Details:', response.data);
  // You will need to handle the confirmation/cancellation process here
})
.catch(error => {
  console.error('An error occurred:', error.message);
});

Summary

Use this endpoint to debit a specified amount from a customer's account. After initiating the transaction, remember to confirm or cancel the debit operation based on the code sent to the customer.