#exeideas_flutter-setupintent
1 messages ¡ Page 1 of 1 (latest)
đ Welcome to your new thread!
â˛ď¸ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
âąď¸ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
đ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1278408321711476856
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
ID = req_EMC3D8GCpTyq97
Future<void> _saveCard() async {
try {
// Step 1: Create a new Stripe customer
final customerId = await _createCustomer();
// Step 2: Create a SetupIntent for the customer
final clientSecret = await _createSetupIntent(customerId);
// Step 3: Initialize the payment sheet with the customer and setupintent information
await Stripe.instance.initPaymentSheet(
paymentSheetParameters: SetupPaymentSheetParameters(
paymentIntentClientSecret: clientSecret,
customerId: customerId,
merchantDisplayName: 'Your App Name',
),
);
// Step 4: Present the payment sheet to collect card details
await Stripe.instance.presentPaymentSheet();
// Card details have been saved successfully for the customer
print("Card saved successfully for customer: $customerId");
} catch (e) {
print("Error saving card: $e");
}
}
Future<String> _createCustomer() async {
final response = await http.post(
Uri.parse('https://api.stripe.com/v1/customers'),
headers: {
'Authorization': 'Bearer your-secret-key',
'Content-Type': 'application/x-www-form-urlencoded',
},
);
if (response.statusCode == 200) {
final body = json.decode(response.body);
return body['id'];
} else {
throw Exception('Failed to create customer');
}
}
Future<String> _createSetupIntent(String customerId) async {
final response = await http.post(
Uri.parse('https://api.stripe.com/v1/setup_intents'),
headers: {
'Authorization': 'Bearer your-secret-key',
'Content-Type': 'application/x-www-form-urlencoded',
},
body: {
'customer': customerId,
},
);
if (response.statusCode == 200) {
final body = json.decode(response.body);
return body['client_secret'];
} else {
throw Exception('Failed to create SetupIntent');
}
}
}```
exeideas_flutter-setupintent
Invalid Payment Intent client secret: seti_1Psnd7H7z
You are passing the client_secret of a SetupIntent but your code is expecting a PaymentIntent so it's erroring.
You are doing // Step 3: Initialize the payment sheet with the customer and setupintent information await Stripe.instance.initPaymentSheet( paymentSheetParameters: SetupPaymentSheetParameters( paymentIntentClientSecret: clientSecret, customerId: customerId, merchantDisplayName: 'Your App Name', ), );
Change paymentIntentClientSecret: clientSecret, to setupIntentClientSecret: clientSecret,
see https://docs.stripe.com/payments/save-and-reuse?platform=react-native&mobile-ui=payment-element#collect-payment-details for example for ReactNative
Aahhh... Thanks. Got it...