![]() |
Stripe is a platform that allows businesses to handle online transactions and add payment gateway in your applications or websites all over the world with different currencies.
A sample video is given below to get an idea about what we are going to do in this article. Step By Step ImplementationStep 1: Create a New Project in Android StudioTo set up Flutter Development on Android Studio please refer to Android Studio Setup for Flutter Development, and then create a new project in Android Studio please refer to Creating a Simple Application in Flutter. Step 2: Add the flutter_stripe and http packageAdd the following package to your pubspec.yaml file Dart
The version may get change depending on your usage. We have preferred this package because it is developed by stripe itself and it is well maintained project with error free code
Step 3: Create a stripe account and get publishable and secret key from it and store it in dotenv fileTo get this key you need to create a stripe and go to Developers section on top left corner Then go to API key and copy both the keys in dotenv file. You can refer following Dotenv article to save this apikeys Step 4: Set the publishable key in void main functionDart
Step 5: Add some permissions and files in platforms folder like android and iOSLet’s start with android first
Kotlin
Add the Proguard file with name proguard-rules.pro at location android/app/ Dart
Add the following in android/app/src/main/AndroidManifest.xml XML
Step 6: Add 1 button from where a bottomsheet for payment will openWe will add 1 elevated button in screen with OnTap Function which will open the payment page and we can handle the different case like payment is successful or cancelled. Let’s learn step by step process to open the payment sheet and handle different scenario 1. Payment intent data via http request: Dart
2. Intialise the payment intent: Dart
3. Display paymentsheet: Dart
We will combine all this method and will call that function in elevated button Dart
Complete Code:Dart
Output:When Payment is uccessful: When Payment is Cancelled: |
Reffered: https://www.geeksforgeeks.org
Dart |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 15 |