createPortalLink method
Méthode d'instance qui peut être testée
Implementation
Future<String> createPortalLink({
required String customerId,
String callbackUrl = 'settings',
}) async {
// Vérifier que l'ID client n'est pas vide
if (customerId.isEmpty) {
throw StripeException('customer_id cannot be empty');
}
if (callbackUrl.startsWith('/')) {
callbackUrl = callbackUrl.substring(1);
}
try {
final response = await _functionsService
.callFunction('createStripePortalSession', {
'customer_id': customerId,
'from_url': getLocalhostUrl(),
'callback_url': callbackUrl,
});
// Vérifier si la réponse contient une URL
if (response.data == null ||
!response.data.containsKey('url') ||
response.data['url'] == null) {
throw StripeException(
'Invalid response from Stripe portal service',
response.data,
);
}
return response.data['url'];
} on FirebaseFunctionsException catch (e) {
throw StripeException('Firebase function error: ${e.message}', {
'code': e.code,
'details': e.details,
});
} catch (e) {
throw StripeException('Failed to create portal link', e);
}
}