iOS apps cannot receive Paystack webhooks directly. Build a backend webhook endpoint, verify the signature, and update your database. Send payment events to the iOS app via APNs push notifications using Firebase Cloud Messaging or the Apple Push Notification service directly. In iOS, handle push notifications in AppDelegate or UNUserNotificationCenter and update your app state accordingly.
The payment notification flow for iOS:
Your iOS app never makes outbound connections to Paystack. It only talks to your backend.
// Node.js backend with Firebase Admin SDK (FCM to iOS)
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;
await db.orders.markAsPaid(reference);
var user = await db.users.findByEmail(email);
if (user?.iosApnsToken) {
// Send via FCM (which delivers to APNs for iOS)
await admin.messaging().send({
token: user.iosFcmToken,
apns: {
payload: {
aps: {
alert: {
title: 'Payment Confirmed',
body: 'NGN ' + amount + ' received'
},
sound: 'default',
badge: 1
}
}
},
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.
// AppDelegate.swift
import UIKit
import UserNotifications
import FirebaseCore
import FirebaseMessaging
@main
class AppDelegate: UIResponder, UIApplicationDelegate, MessagingDelegate,
UNUserNotificationCenterDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
UNUserNotificationCenter.current().delegate = self
Messaging.messaging().delegate = self
UNUserNotificationCenter.current().requestAuthorization(
options: [.alert, .badge, .sound]
) { granted, error in
if granted {
DispatchQueue.main.async {
application.registerForRemoteNotifications()
}
}
}
return true
}
// FCM token received — send to your backend
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
guard let token = fcmToken else { return }
sendTokenToBackend(token: token)
}
// Notification received while app is in foreground
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let userInfo = notification.request.content.userInfo
handlePaystackEvent(userInfo: userInfo)
completionHandler([.banner, .sound])
}
// Notification tapped (app in background or closed)
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
handlePaystackEvent(userInfo: userInfo)
completionHandler()
}
private func handlePaystackEvent(userInfo: [AnyHashable: Any]) {
guard let event = userInfo["event"] as? String,
let reference = userInfo["reference"] as? String else { return }
if event == "charge.success" {
// Post notification so any listening View can update
NotificationCenter.default.post(
name: Notification.Name("PaystackPaymentConfirmed"),
object: nil,
userInfo: ["reference": reference]
)
}
}
private func sendTokenToBackend(token: String) {
// POST token to your backend API
}
}
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