flutter_stripe intent payment sheet not working in Android APK #1651
Unanswered
AhmedBashirAwan
asked this question in
Q&A
Replies: 1 comment
-
Have you found solution? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have integrate flutter_stripe to a project and the issue which is arising is, when I run the app on emulator it works fine and as soon I export an APK of it the intent payment sheet does not show. oN debugging in emulator the logs are empty
import 'dart:convert';
import 'package:flutter_stripe/flutter_stripe.dart';
import 'package:http/http.dart' as http;
class StripePaymentHandle {
Future payment(String amount) async {
try {
Map<String, String> body = {
'amount': amount,
'currency': 'usd'
};
var response = await http.post(
Uri.parse('https://api.stripe.com/v1/payment_intents'),
headers: {
'Authorization':
'Bearer sk_test_51OiEIjKJXVCbENfEHwbzkGokrLWYdRYlh3N3kFAFVoE4LoJJW4kFJyh3jKZ8Cs2OCxxW4d4iPxFEzMEhwSgGGIlt00xHt6emi8',
'Content-Type': 'application/x-www-form-urlencoded'
},
body: body,
);
if (response.statusCode == 200) {
Map<String, dynamic> paymentIntentData = json.decode(response.body);
String clientSecret = paymentIntentData['client_secret'];
await initializePaymentSheet(clientSecret);
} else {
throw Exception('Failed to create payment intent');
}
} catch (e) {
print('Error creating payment intent: $e');
}
}
Future initializePaymentSheet(String clientSecret) async {
try {
await Stripe.instance.initPaymentSheet(
paymentSheetParameters: SetupPaymentSheetParameters(
paymentIntentClientSecret: clientSecret,
merchantDisplayName: 'Your Merchant Name',
customFlow: true,
allowsDelayedPaymentMethods: true,
// confirmPayment: false,
),
);
} catch (e) {
print('Error initializing payment sheet: $e');
}
}
Future presentPaymentSheet() async {
try {
await Stripe.instance.presentPaymentSheet().then((value) {
print('Payment successfully completed');
});
} catch (e) {
print('Error presenting payment sheet: $e');
}
}
}
package com.example.esim
import io.flutter.embedding.android.FlutterFragmentActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant
class MainActivity: FlutterFragmentActivity() {
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine)
}
}
<!-- Required to query activities that can process text, see:
https://developer.android.com/training/package-visibility?hl=en and
https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT.
Beta Was this translation helpful? Give feedback.
All reactions