handlePurchaseProductEvent method
Handles the FastStoreBlocEventType.purchaseProduct event to initiate a purchase of a specific product.
Implementation
Stream<FastStoreBlocState> handlePurchaseProductEvent(
FastStoreBlocPayload payload,
) async* {
if (!_isPurchasePending &&
payload.productId != null &&
!_isRestoringPurchases) {
final productId = payload.productId!;
_logger.debug('Purchasing product: $productId');
_pendingPurchaseProductId = productId;
_isPurchasePending = true;
yield currentState.copyWith(isPurchasePending: true);
try {
// Purchase status handled by _listenToPurchases
await _iapService!.purchaseProduct(productId);
} catch (error) {
addEvent(FastStoreBlocEvent.purchaseProductFailed(
_formartError(error),
productId,
));
}
}
}