In this tutorial, we’ll implement PayPal payment integration using its Sandbox Environment in a Flutter app. By the end, you’ll have a working payment gateway that redirects users to a Thank You page upon successful payment.
✅ Prerequisites
-
Basic understanding of Flutter and Dart
-
Installed Flutter and Android Studio/VS Code
-
PayPal Developer Account (Create one at developer.paypal.com)
🚀 Step 1: Create a PayPal App in Sandbox
-
Log in to the PayPal Developer Dashboard.
-
Navigate to Apps & Credentials → Create App.
-
Get your Client ID and Secret.
-
Make sure the app is set to Sandbox mode for testing.
🛠️ Step 2: Install Required Packages
Add the following packages to your pubspec.yaml
:
Run:
🧱 Step 3: Configure Platform-Specific Settings
For Android
-
Add internet permission to
AndroidManifest.xml
:
For iOS
-
In
ios/Runner/Info.plist
, add the following:
📁 Folder Structure
Here’s how the project will be organized:
🧑💻 Step 4: Create PayPal Service for API Calls
Create a file named paypal_service.dart
under the services
folder.
🧑💻 Step 5: Create a PayPal Payment Screen
Create a file named paypal_payment_screen.dart
.
🎉 Step 6: Create a Thank You Screen
Create thank_you_screen.dart
to display after successful payment.
🚀 Step 7: Update main.dart
🔎 Testing Your Payment
-
Run the app using:
-
Click the Pay with PayPal button.
-
A browser will open with a sandbox PayPal checkout.
-
Complete the payment using a sandbox buyer account.
-
Upon success, you’ll be redirected to the Thank You screen.
🚦 Troubleshooting
-
MissingPluginException: Ensure you’ve run:
-
Invalid Credentials: Double-check your Client ID and Secret.
-
URL Not Opening: Confirm you’ve added URL launcher permissions.
🎯 Conclusion
You have successfully integrated PayPal sandbox payments in your Flutter app. For a production setup, switch to Live Mode by using your live credentials.
Need further tweaks or explanations? Let me know! 😊