Complete Guide: Integrating Apple Pay in a Flutter App (Full Code) 🚀

Complete Guide: Integrating Apple Pay in a Flutter App (Full Code) 🚀

Apple Pay allows seamless and secure payments in iOS apps. Here’s a step-by-step guide to adding Apple Pay in your Flutter app using Stripe.


📌 Step 1: Prerequisites

Before starting, ensure you have:

Apple Developer Account (Enroll here)

Stripe Account (Sign up here)

Physical iPhone (Apple Pay does not work on simulators)

Flutter Environment Setup (Install Flutter)


📌 Step 2: Create a Merchant ID in Apple Developer Account

1️⃣ Go to Apple Developer Console

2️⃣ Click the "+" button and select Merchant ID

3️⃣ Enter a unique identifier (e.g., merchant.com.yourapp)

4️⃣ Click ContinueRegister


📌 Step 3: Enable Apple Pay in Xcode

1️⃣ Open your Flutter project in Xcode:

2️⃣ In Xcode, go to Runner > Signing & Capabilities

3️⃣ Click "+ Capability" → Add Apple Pay

4️⃣ Select the Merchant ID you created earlier


📌 Step 4: Install flutter_stripe Package

Run the following command:


📌 Step 5: Add Apple Pay Configuration to Info.plist

  • Edit ios/Runner/Info.plist and add the following:


📌 Step 6: Initialize Stripe in main.dart

Create a new main.dart file with the following code:


📌 Step 7: Implement Apple Pay Button in Flutter

Create a new file apple_pay_screen.dart and add the following code:


📌 Step 8: Set Up a Backend for Stripe Payments (Recommended)

Apple Pay requires a backend to generate a client secret. You can use Firebase or Node.js.

Node.js Backend Example

1️⃣ Install Stripe in your Node.js backend:

2️⃣ Create a file server.js and add the following:

3️⃣ Create a .env file and add:

4️⃣ Run the backend:

5️⃣ Replace "your-client-secret" in Flutter with the API response from http://localhost:3000/create-payment-intent.


📌 Step 9: Test Apple Pay on a Physical Device

  • Apple Pay only works on real iPhones, not emulators

  • Ensure you have an Apple Pay-supported card added in Wallet

  • Run your Flutter app and tap "Pay with Apple Pay"


📌 Step 10: Deploy Your App 🚀

Once tested, submit your app to the App Store via Xcode > Product > Archive.


🎯 Summary of Steps

Step 1: Apple Developer Account & Stripe Setup

Step 2: Create Apple Pay Merchant ID

Step 3: Enable Apple Pay in Xcode

Step 4: Install flutter_stripe Package

Step 5: Update Info.plist

Step 6: Initialize Stripe in Flutter

Step 7: Implement Apple Pay Button

Step 8: Set Up Backend (Stripe API)

Step 9: Test on Physical iPhone

Step 10: Deploy to App Store


Stripe

What is Stripe? 💳

Stripe is a popular payment processing platform that allows businesses and developers to accept payments online and in mobile apps. It supports various payment methods like credit/debit cards, Apple Pay, Google Pay, UPI, and bank transfers.

🔹 Why Use Stripe?

Easy Integration – Works with web & mobile apps (Flutter, React, etc.)

Supports Multiple Payment Methods – Cards, UPI, wallets, bank transfers, etc.

Secure & PCI Compliant – Ensures safe transactions

Global Support – Accepts payments in 135+ currencies

Subscriptions & One-Time Payments – Handles recurring billing


✅ Use test card numbers from Stripe:

✅ Run your app and tap "Pay with Stripe"

  • Visa: 4242 4242 4242 4242

  • MasterCard: 5555 5555 5555 4444

🔹 Stripe in Flutter

Stripe provides a Flutter SDK (flutter_stripe) to integrate payments in mobile apps. You can use Stripe to add Apple Pay, Google Pay, and Card Payments in your Flutter app.

To view or add a comment, sign in

Insights from the community

Explore topics