Skip to main content

Direct Charge

Direct Charge

Give your users the option of funding their wallets on your business directly from other wallets or funding their wallets on other businesses directly from their wallets on your business. Or both.

How Direct Charge Works

Prerequisites

  1. Create a Thepeer Account.
  2. Navigate to the Settings page and click Preferences on the tab menu.
  3. Check the Direct Charge option on your Thepeer dashboard.

Checking the Direct Charge option in the Accept payments via section enables your users to be able to fund their wallets on your business directly from their wallets on other businesses.


Checking the Direct Charge option in the Accept payments via section gives your users the option of funding their wallets on other businesses directly from their wallets on your business.


Initiate Direct Charge

Initiating Direct Charge brings up Thepeer’s modal so your users can proceed with linking their account on your business with the one on the business they want to fund with — and then funding it.


Load Thepeer via CDN

Thepeer needs to available on your app before you can make use of its APIs.

    <script type="application/javascript" src="https://cdn.thepeer.co/v1/chain.js"></script>

Instantiate Thepeer’s Direct Charge

Here, you create a direct charge object containing details necessary for the transaction like amount, currency, and so on.


direct charge
<button onclick="directDebit()">Direct Charge</button>
<script
type="application/javascript"
src="https://cdn.thepeer.co/v1/chain.js"
></script>
<script type="application/javascript">
function directDebit() {
const dc = new Thepeer.DirectCharge({
currency: "NGN",
amount: 480000,
publicKey: "YOUR_PUBLIC_KEY",
userReference: "USER_REFERENCE",
onSuccess(response) {
console.log(response.event);
},
onError(error) {
console.log(error);
},
onClose(event) {
console.log("User closed the widget ->", { event });
},
});
dc.setup();
dc.open();
}
</script>

Parameters

NameDescriptionRequiredData type
currencyThe currency the transaction should be carried out in. The supported value is NGN.falseString
amountThe amount you are debiting the customer. This should be in kobo. The minimum value is 10000trueNumber
publicKeyThe public key generated for your Thepeer account. You can retrieve this from Settings > API Keys & Webhooks on your dashboard.trueString
userReferenceThe reference of the user to chargetrueString
onSuccessA callback function that Thepeer calls after a successful charge transaction.trueFunction
onErrorA callback function that Thepeer calls after a failed charge transaction.trueFunction
onCloseA callback function that Thepeer calls after the user closes the payment modal.trueFunction
metaAn object containing additional attributes you will like to have in your transaction response.falseObject

After creating an instance of Thepeer’s Direct Charge with the details to be used for the transaction, you will need to call its setup() method. The setup() method sends the details of the transaction to Thepeer and Thepeer, in turn, gets it ready for your user to proceed with.


When the open() method is called, the payment modal comes up. Obviously.


Testing Direct Charge

We have an endpoint that allows you to simulate the processing of payments on test environment via webhooks.

Endpoint Post

Request Body Parameters

NameDescriptionRequiredData type
currencyThe currency the transaction should be carried out in. The supported value is NGN.falseString
amountThe amount you are debiting the customer. This should be in kobo. The minimum value is 10000trueNumber
fromThe user reference of one of your indexed userstrueString
toThe user reference of one of your indexed users. Can be the same as from.trueString
remarkThe transaction descriptiontrueString
channelThe specific Thepeer channel that the transaction is processed with. Supported values are send, checkout, and direct_charge.falseString
metaAn object containing additional attributes you will like to have in your transaction response.falseObject
Sample request
{
"currency": "NGN",
"amount": 10000,
"from": "USER_REFERENCE",
"to": "USER_REFERENCE",
"remark": "test",
"channel": "direct_charge",
"meta": {
"city": "Ketu",
"state": "London"
}
}

Note that this endpoint only simulates the actual direct charge feature by transfer of funds between users on test environment.


Sample response
{
"message": "hook sent"
}

After you have successfully called the request endpoint, we send an authorization payload via webhook in the default transaction object format. This is the same format when receiving payments.


You can then verify the webhook request and process the authorization of the charge.