Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save pmutua/47d4ea918de1a4a201fb1cf13cafc952 to your computer and use it in GitHub Desktop.

Select an option

Save pmutua/47d4ea918de1a4a201fb1cf13cafc952 to your computer and use it in GitHub Desktop.
Arifa Updates - Paystack Checkout, Rate Limits, and Bug Fixes
title Arifa Updates - Paystack Checkout, Rate Limits, and Bug Fixes
date 2026-05-26
author pmutua
tags
react-native
expo
astro
cloudflare-workers
hono
d1
drizzle
kv
r2
rag
workers-ai
vectorize
turborepo
typescript
commit d1208bb
type dev-diary

The Hook

This update brings significant improvements to the Arifa platform, including the integration of Paystack checkout for seamless subscription upgrades, the addition of rate limits to prevent abuse of analytics, intelligence, subscription, and user routes, and several bug fixes to enhance the overall user experience.

Context

Arifa is an AI-powered news aggregation, analysis, and distribution platform designed for Kenya and Global Tech & Science news. It leverages a range of technologies including React Native, Expo, Astro, Cloudflare Workers, Hono, D1, Drizzle, KV, R2, and Rag, among others, to provide a comprehensive news experience.

What Changed

Paystack Checkout Integration

The UpgradePrompt component has been updated to wire the Paystack checkout flow, allowing users to upgrade their plans seamlessly. This change involves the use of usePlans, useInitializeSubscription, and useVerifySubscription hooks to manage the subscription process.

const handleUpgrade = async (planId: string) => {
  setLoadingPlanId(planId);
  await Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Medium);

  try {
    const result = await initMutation.mutateAsync({ planId });

    const browserResult = await WebBrowser.openBrowserAsync(result.authorizationUrl, {
      dismissButtonStyle: 'close',
    });

    if (browserResult.type === 'cancel' || browserResult.type === 'dismiss') {
      // User closed browser -- attempt to verify in case payment completed
      try {
        await verifyMutation.mutateAsync(result.reference);
        Alert.alert('Payment Confirmed', 'Your plan has been upgraded successfully!');
      } catch {
        // Payment wasn't completed -- no-op
      }
    }
  } catch (err) {
    Alert.alert('Error', 'Unable to start checkout. Please try again.');
  } finally {
    setLoadingPlanId(null);
  }
};

Rate Limits

Rate limits have been added to analytics, intelligence, subscription, and user routes to prevent abuse. This involves the use of the rateLimit middleware in routes such as analyticsRoutes, intelligenceRoutes, subscriptionRoutes, and userRoutes.

analyticsRoutes.get('/sentiment', authMiddleware, rateLimit(30), async (c) => {
  // ...
});

intelligenceRoutes.get('/briefing/today', optionalAuthMiddleware, rateLimit(60), async (c) => {
  // ...
});

subscriptionRoutes.get('/plans', rateLimit(30), async (c) => {
  // ...
});

userRoutes.get('/profile', authMiddleware, rateLimit(30), async (c) => {
  // ...
});

Bug Fixes

Several bug fixes have been implemented, including replacing the notification bell coming-soon alert with navigation to preferences, updating audio tests to expect WAV format, and resolving silent error swallowing in empty catch blocks.

Challenges

One of the challenges faced during this update was ensuring that the Paystack checkout integration was seamless and secure. This required careful handling of payment verification and error handling to prevent any potential issues.

What I Learned

  • The importance of rate limiting in preventing abuse of API routes.
  • How to integrate Paystack checkout into a React Native application using Expo.
  • The need for thorough error handling in asynchronous operations.

What's Next

The next steps involve further enhancing the user experience through additional features and improvements, such as expanding the analytics capabilities and introducing more personalized content recommendations.

Mermaid Diagram

Given the changes to the data schema, particularly with the introduction of rate limits and the integration of Paystack checkout, an erDiagram illustrating these changes is necessary. However, due to the complexity and the nature of the changes, which are more functional and less about altering the database schema directly, the focus shifts towards understanding how these changes impact the system's architecture and user interaction.

erDiagram
    USER ||--o{ SUBSCRIPTION : has
    SUBSCRIPTION }|..|{ PLAN : includes
    PLAN ||--|{ RATE_LIMIT : applies
    RATE_LIMIT }|..|{ ANALYTICS_ROUTE : restricts
    ANALYTICS_ROUTE ||--|{ INTELLIGENCE_ROUTE : complements
    INTELLIGENCE_ROUTE }|..|{ USER_ROUTE : serves
    USER_ROUTE ||--o|{ PAYSTACK_CHECKOUT : integrates
    PAYSTACK_CHECKOUT }|..|{ SUBSCRIPTION : upgrades
Loading

This diagram illustrates the relationship between users, subscriptions, plans, rate limits, and the various routes (analytics, intelligence, user), as well as the integration of Paystack checkout for subscription upgrades. It highlights how these components interact within the Arifa platform to provide a secure, personalized, and feature-rich experience.


Git Provenance

All commits are SSH-signed (Ed25519) and show a Verified badge on GitHub. The source repository is private — commit URLs are not publicly accessible.

Commit Date Message Verified
e97a4dc 2026-05-25 20:09 +03:00 feat(mobile): wire UpgradePrompt to Paystack checkout flow (closes #41)
85f38d2 2026-05-25 20:18 +03:00 fix(api): add rate limits to analytics, intelligence, subscription, and user routes (closes #43, closes #44, closes #47, closes #49)
21c1ca7 2026-05-25 20:21 +03:00 fix(mobile): replace notification bell coming-soon alert with navigation to preferences (closes #42)
a854056 2026-05-25 20:24 +03:00 fix(shared): update audio tests to expect WAV format (closes #46)
d1208bb 2026-05-25 20:28 +03:00 fix(web): resolve silent error swallowing in empty catch blocks (closes #45)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment