Android apps cannot receive Paystack webhooks directly. Build a webhook endpoint on your backend, verify the x-paystack-signature, and update your database. Use Firebase Cloud Messaging (FCM) to push payment events to the Android app. In the Android app, handle FCM messages in a FirebaseMessagingService subclass and update the UI.
Paystack fires webhooks to your server. Your server then notifies the Android app:
Paystack → Your Backend Server (webhook received + verified)
↓
Update Database
↓
FCM Push to Android App
↓
FirebaseMessagingService handles message
↓
Update ViewModel / UI
// Node.js backend with Firebase Admin SDK
var crypto = require('crypto');
var admin = require('firebase-admin');
app.post('/api/webhooks/paystack',
express.raw({ type: 'application/json' }),
async (req, res) => {
var sig = req.headers['x-paystack-signature'];
var hash = crypto
.createHmac('sha512', process.env.PAYSTACK_SECRET_KEY)
.update(req.body)
.digest('hex');
if (hash !== sig) return res.status(400).send('Invalid signature');
res.sendStatus(200);
var event = JSON.parse(req.body.toString());
if (event.event === 'charge.success') {
var email = event.data.customer.email;
var reference = event.data.reference;
var amount = event.data.amount / 100;
// Update order in DB
await db.orders.markAsPaid(reference);
// Get user's FCM token
var user = await db.users.findByEmail(email);
if (user?.androidFcmToken) {
await admin.messaging().send({
token: user.androidFcmToken,
notification: {
title: 'Payment Received',
body: 'NGN ' + amount + ' confirmed. Ref: ' + reference
},
data: {
event: 'charge.success',
reference: reference,
amount: String(amount)
}
});
}
}
}
);
Get weekly developer tips
Join 25,000+ developers. Practical guides, job tips, and new content — straight to your inbox.
No spam. Unsubscribe anytime.
Add Firebase to your Android project, then create a messaging service:
// PaystackMessagingService.kt
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
class PaystackMessagingService : FirebaseMessagingService() {
override fun onNewToken(token: String) {
super.onNewToken(token)
// Send the new token to your backend
sendTokenToBackend(token)
}
override fun onMessageReceived(message: RemoteMessage) {
super.onMessageReceived(message)
val event = message.data["event"]
val reference = message.data["reference"]
val amount = message.data["amount"]
when (event) {
"charge.success" -> {
// Send a broadcast that the payment Activity/ViewModel can receive
val intent = android.content.Intent("com.yourapp.PAYMENT_SUCCESS")
intent.putExtra("reference", reference)
intent.putExtra("amount", amount)
sendBroadcast(intent)
// Also show a notification
showNotification("Payment Confirmed", "NGN $amount received")
}
}
}
private fun showNotification(title: String, body: String) {
val notificationManager = getSystemService(NOTIFICATION_SERVICE)
as android.app.NotificationManager
val channelId = "payment_events"
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
val channel = android.app.NotificationChannel(
channelId, "Payment Events",
android.app.NotificationManager.IMPORTANCE_HIGH
)
notificationManager.createNotificationChannel(channel)
}
val notification = androidx.core.app.NotificationCompat.Builder(this, channelId)
.setContentTitle(title)
.setContentText(body)
.setSmallIcon(android.R.drawable.ic_dialog_info)
.setAutoCancel(true)
.build()
notificationManager.notify(System.currentTimeMillis().toInt(), notification)
}
private fun sendTokenToBackend(token: String) {
// Use Retrofit to POST the token to your backend
// Store it so your backend can target this device
}
}
Register in AndroidManifest.xml:
<service
android:name=".PaystackMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
This guide is part of the Paystack integration guides by language and framework series.
KES 2,999
The definitive guide to building payment systems with Paystack — from your first transaction to production-grade payment infrastructure across Africa. 9 modules, 47 lessons. Free preview available.
Start Paystack Course