cancel method
Future<void>
cancel({
- required DocumentBase<
StripePurchaseModel> purchase, - Duration timeout = const Duration(seconds: 15),
Cancel purchase
.
purchase
をキャンセルします。
Implementation
Future<void> cancel({
required DocumentBase<StripePurchaseModel> purchase,
Duration timeout = const Duration(seconds: 15),
}) async {
if (_completer != null) {
return _completer!.future;
}
_completer = Completer<void>();
try {
final value = purchase.value;
if (value == null) {
throw Exception(
"Purchase information is empty. Please run [create] method.",
);
}
if (value.canceled) {
throw Exception("This purchase has already canceled.");
}
if (value.captured || value.success) {
throw Exception("The payment has already been completed.");
}
final functionsAdapter =
StripePurchaseMasamuneAdapter.primary.functionsAdapter ??
FunctionsAdapter.primary;
await functionsAdapter.execute(
StripeCancelPurchaseAction(
userId: userId,
orderId: value.orderId,
),
);
await Future.doWhile(() async {
await Future.delayed(const Duration(milliseconds: 100));
await purchase.reload();
return purchase.value != null && !purchase.value!.canceled;
}).timeout(timeout);
_completer?.complete();
_completer = null;
notifyListeners();
} catch (e) {
_completer?.completeError(e);
_completer = null;
rethrow;
} finally {
_completer?.complete();
_completer = null;
}
}