Fund Wallet
How to fund a wallet using M-Pesa and Card
How to Fund Wallet with M-Pesa STK Push
The collection M-Pesa STK Push API enables you to directly bill a client and have the funds deposited to the specified wallet_id. To implement this, simply provide a wallet_id as one of the fields options in the M-Pesa STK Push API.
Below is an example of direct wallet funding with the M-Pesa STK Push API in Python. The same can be implemented in other language by simply parsing a wallet_id
field in the request payload. See the M-Pesa STK Push for more details.
from intasend import APIService
publishable_key = "INTASEND_PUBLISHABLE_KEY"
token = "INTASEND_SECRET_KEY"
service = APIService(token=token,publishable_key=publishable_key, test=True)
response = service.wallets.fund(wallet_id="<TARGETED-WALLET-ID", email=email, phone_number="2547..",
amount=amount, currency="KES", narrative="Deposit",
mode="MPESA-STK-PUSH")
print(response)
use IntaSend\IntaSendPHP\Wallet;
$wallet = new Wallet();
$wallet->init($credentials);
$response = $wallet->fund_mpesa_stk_push($wallet_id="<wallet_id>", $phone_number='2547...',$email='[email protected]', $amount=10, $api_ref="API Request");
print_r($response);
const IntaSend = require('intasend-node');
const intasend = new IntaSend(/*...Authenticate*/)
let wallets = intasend.wallets();
wallets
.fundMPesa({
first_name: 'Joe',
last_name: 'Doe',
email: '[email protected]',
host: 'https://yourwebsite.com',
amount: 10,
phone_number: '254....',
api_ref: 'test',
wallet_id:'<wallet_id>'
})
.then((resp) => {
console.log(`Response: ${JSON.stringify(resp)}`);
})
.catch((err) => {
console.error(`Error:`,err);
});
How to Fund Wallet Using the Checkout API
The Checkout Link API can be used to directly fund a wallet. To do this, you simply provide a wallet_id of the wallet you would like to fund during the Checkout API request. The API will generate a secure payment URL where you can redirect the user to complete payment. This option provide support for both M-Pesa and Card payments.
Here is an example of the Checkout Link API with the targeted wallet_id added as one of the fields.
from intasend import APIService
publishable_key = "INTASEND_PUBLISHABLE_KEY"
service = APIService(publishable_key=publishable_key, test=True)
response = service.collect.checkout(wallet_id="<TARGETED-WALLET-ID>", phone_number="2547...",
email="[email protected]", amount=1000, currency="KES",
comment="Deposit", redirect_url='http://example.com/thank-you')
print(response.get("url"))
use IntaSend\IntaSendPHP\Wallet;
use IntaSend\IntaSendPHP\Customer;
$wallet = new Wallet();
$wallet->init($this->credentials);
$customer = new Customer();
$customer->first_name = "Joe";
$customer->last_name = "Doe";
$customer->email = "[email protected]";
$customer->country = "KE";
$host = "https://example.com";
$redirect_url = "https://example.com";
$ref_order_number = "fund-wallet-10";
$response = $wallet->fund_checkout($wallet_id="<wallet_id>", $phone_number='2547..', $currency='USD',
$customer=$customer, $amount=10, $host=$host,
$redirect_url=$redirect_url, $api_ref=$ref_order_number,
$card_tarrif = "BUSINESS-PAYS", $mobile_tarrif = "BUSINESS-PAYS");
print_r($response->url);
wallets
.fundCheckout({
first_name: 'Joe',
last_name: 'Doe',
email: '[email protected]',
host: 'https://yourwebsite.com',
amount: 10,
currency: 'KES',
api_ref: 'test',
redirect_url:'http://example.com/thank-you'
wallet_id: '<wallet_id>',
})
.then((resp) => {
// Redirect user to URL to complete payment
console.log(`Charge Response:`, resp);
})
.catch((err) => {
console.error(`Charge error:`, err);
});
The successful response contains a payment URL. Redirect the user to the URL to complete payment. On successful payment, the funds will be deposited in the targeted wallet_id instead of the default SETTLEMENT wallet.
Updated 9 months ago