SDKs
The SDKs wrap the REST API and handle authentication and the sandbox/live switch for you.
Install
- Python
- PHP
- Node.js
- Flutter
pip install intasend-python
composer require intasend/intasend-php
npm install intasend-node
flutter pub add intasend_flutter
Authenticate
Pass your publishable key, your secret key (server side only) and whether you're testing.
Set test to false with live keys.
- Python
- PHP
- Node.js
from intasend import APIService
service = APIService(token="<SECRET_KEY>", publishable_key="<PUBLISHABLE_KEY>", test=True)
use IntaSend\IntaSendPHP\Checkout;
$credentials = [
'token' => '<SECRET_KEY>',
'publishable_key' => '<PUBLISHABLE_KEY>',
'test' => true,
];
$checkout = new Checkout();
$checkout->init($credentials);
const IntaSend = require('intasend-node');
const intasend = new IntaSend('<PUBLISHABLE_KEY>', '<SECRET_KEY>', true);
For checkout only, the publishable key is enough. Leave the secret key out of anything that runs in a browser or app.
Examples
Checkout
Creates a checkout and returns the payment url.
- Python
- PHP
- Node.js
- Flutter
response = service.collect.checkout(
comment="Order 123", redirect_url="https://example.com/thank-you",
)
print(response.get("url"))
use IntaSend\IntaSendPHP\Customer;
$customer = new Customer();
$customer->first_name = "Jane";
$customer->last_name = "Doe";
$customer->country = "KE";
$resp = $checkout->create(
$amount = 1500, $currency = "KES", $customer = $customer,
$host = "https://example.com", $redirect_url = "https://example.com/thank-you",
$api_ref = "order-123"
);
print_r($resp->url);
intasend.collection()
.charge({
host: 'https://example.com', amount: 1500, currency: 'KES',
api_ref: 'order-123', redirect_url: 'https://example.com/thank-you',
})
.then((resp) => console.log(resp.url))
.catch((err) => console.error(err));
import 'package:intasend_flutter/models/checkout.dart';
import 'package:intasend_flutter/intasend_flutter.dart';
Checkout checkout = Checkout(
publicKey: "<PUBLISHABLE_KEY>",
amount: 1500,
email: "[email protected]",
currency: "KES",
firstName: "Jane",
lastName: "Doe");
// Opens the checkout in a webview. Set test to false to go live.
IntasendFlutter.initCheckout(test: true, checkout: checkout, context: context);
The Flutter SDK only does checkout. Confirm the payment on your backend with a webhook. See the full example.
M-Pesa STK Push
Sends an STK Push prompt to the customer's phone.
- Python
- PHP
- Node.js
response = service.collect.mpesa_stk_push(
)
use IntaSend\IntaSendPHP\Collection;
$collection = new Collection();
$collection->init($credentials);
$response = $collection->create(
$amount = 10, $phone_number = "254712345678", $currency = "KES",
);
intasend.collection()
.mpesaStkPush({
host: 'https://example.com', amount: 10, phone_number: '254712345678', api_ref: 'order-123',
})
.then((resp) => console.log(resp))
.catch((err) => console.error(err));
Payment status
Pass the invoice_id from the checkout or STK Push response. See checking payment status.
- Python
- PHP
- Node.js
response = service.collect.status(invoice_id="<INVOICE_ID>")
$response = $collection->status("<INVOICE_ID>");
intasend.collection().status('<INVOICE_ID>').then((resp) => console.log(resp));
Packages
- Python:
intasend-python - PHP:
intasend/intasend-php - Node.js:
intasend-node - Flutter:
intasend_flutter - Browser:
intasend-checkout-sdk