Next.js 15 integration guide
Integrating Fungies with Next.js 15: A Concise Guide
1. Introduction
Fungies is a payment merchant of record platform designed specifically for SaaS developers. It offers a streamlined way to handle payments, subscriptions, and checkout experiences with key benefits including:
No hidden fees pricing structure
Beautiful checkout solutions (Overlay, Embedded, and Hosted options)
Easy integration process
No-code store builder for quick setup
This guide will walk you through integrating Fungies checkout into your Next.js 15 application. We'll use straightforward language and provide practical code examples that you can adapt to your own projects.
2. Getting Started with Fungies & Next.js
Prerequisites
Before beginning the integration process, ensure you have:
Next.js 15 Project: Create one with
npx create-next-app@latest my-fungies-appUse TypeScript (recommended)
Use App Router (to leverage Next.js 15 features)
Fungies Account:
Sign up at Fungies.io
For testing, use the Sandbox environment: https://app.stage.fungies.net
Create a store in your dashboard
Set up at least one product or subscription
Note your API keys (public and secret)
Create a checkout element and note the checkout URL
Development Environment:
Node.js 18.17 or later
npm, yarn, or pnpm package manager
Installation
Install the Fungies JavaScript SDK in your Next.js project:bash
Setup
Environment Variables
Create a .env.local file in your project root:
SDK Initialization
Create a utility file to initialize the Fungies SDK (lib/fungies.ts):typescript
This utility ensures Fungies is only initialized on the client side, preventing server-side rendering errors.
3. Implementing Fungies Checkout
Checkout Options Overview
Fungies offers three main checkout integration options:
Overlay Checkout: Displays in a modal overlay (simplest option)
Embedded Checkout: Displays directly within your page layout
Hosted Checkout: Redirects to a Fungies-hosted checkout page
We'll focus on implementing the Overlay and Embedded options as they provide the best balance of ease and user experience.
Overlay Checkout Implementation
Create a client component for the overlay checkout (components/OverlayCheckoutButton.tsx):typescript
Use this component in any page:tsx
Embedded Checkout Implementation
Create a container component for the embedded checkout (components/EmbeddedCheckout.tsx):typescript
Use the embedded checkout in your pages:tsx
4. Handling Payments & Events
Working with Checkout Data
Fungies provides several options for customizing the checkout experience:
Pre-filling Customer Information
typescript
Applying Discount Codes
typescript
Setting Quantities
typescript
Webhook Integration
Webhooks allow your application to receive real-time notifications about events in your Fungies account.Create an API route to handle webhook events:typescript
Security Considerations for Webhooks
Always verify signatures using the webhook secret
Store secrets in environment variables, never hardcode them
Design webhook handlers to be idempotent as Fungies may retry webhook deliveries
Catch and log errors but still return a 200 status to acknowledge receipt
Keep webhook processing quick or move long-running tasks to a background job
5. Integrating with Next.js 15 Features
Server vs. Client Components
Next.js 15 uses React's Server Components by default, but Fungies SDK requires client-side JavaScript.Server Components are great for:
Fetching data from your backend or APIs
Accessing environment variables securely
Rendering static content
Client Components are necessary for:
Interacting with the Fungies SDK
Handling user interactions like button clicks
Managing local state
Here's a pattern for combining both:tsx
tsx
Server Actions
Next.js 15 includes Server Actions, which allow you to run server-side code from client components. This is perfect for operations that require your secret API key.typescript
Use this Server Action in a client component:tsx
Performance Tips
Lazy Loading Checkout Components
Use Next.js dynamic imports to lazy load checkout components:typescript
Optimizing Webhook Processing
For long-running webhook tasks, use a background process:typescript
6. Testing & Deployment
Testing with Fungies Sandbox
Fungies provides a Sandbox environment for testing:
Sandbox App URL: https://app.stage.fungies.net
Sandbox API Docs: https://api.stage.fungies.net/v0/api-docs/
Set up environment variables to switch between environments:typescript
Use this configuration in your API calls:typescript
Debugging Common Issues
SDK Not Loading
typescript
Webhook Verification Issues
typescript
Deployment
Environment Variables in Production
For Vercel deployments, add these environment variables in the Vercel dashboard:
Security Best Practices
Never expose your secret API key in client-side code
Add security headers to your webhook endpoints
Validate user input before sending it to Fungies
Use Server Actions for operations requiring the secret key
7. Conclusion
In this guide, we've covered how to integrate Fungies checkout into your Next.js 15 application. We've explored:
Setting up the Fungies SDK in a Next.js environment
Implementing both Overlay and Embedded checkout options
Working with checkout data and customization
Setting up webhooks to handle payment events
Leveraging Next.js 15 features like Server Components and Server Actions
Testing with the Fungies Sandbox environment
Deploying your integration to production
For more information, refer to:
For support, contact [email protected] or join the Fungies community forums.
Last updated