handleProductPurchasedEvent method
Handles the FastStoreBlocEventType.productPurchased event when a product has been successfully purchased.
Implementation
Stream<FastStoreBlocState> handleProductPurchasedEvent(
FastStoreBlocPayload payload,
) async* {
if (_isPurchasePending) {
_logger.debug('Product purchased');
_isPurchasePending = false;
_pendingPurchaseProductId = null;
if (payload.purchaseDetails != null) {
final purchase = FastInAppPurchase.fromPurchaseDetails(
payload.purchaseDetails!,
);
await _iapDataProvider.enablePurchaseWithProductId(purchase.productId);
yield currentState.copyWith(
purchases: [...currentState.purchases, purchase],
isPurchasePending: false,
);
} else {
yield currentState.copyWith(isPurchasePending: false);
}
}
}