mapFlutterPurchaseResultToPurchaseResult function

ProductPurchaseResult mapFlutterPurchaseResultToPurchaseResult(
  1. FlutterProductPurchaseResult purchaseResult
)

Implementation

ProductPurchaseResult mapFlutterPurchaseResultToPurchaseResult(
    FlutterProductPurchaseResult purchaseResult) {
  if (purchaseResult.cancelled case Cancelled cancelled) {
    return CancelProductPurchaseResult(purchaseId: cancelled.purchaseId);
  } else if (purchaseResult.failure case Failure failure) {
    return FailureProductPurchaseResult(
        orderId: failure.orderId,
        purchaseId: failure.purchaseId,
        productId: failure.productId,
        invoiceId: failure.invoiceId,
        quantity: failure.quantity,
        subscriptionToken: failure.subscriptionToken,
        errorMessage: failure.errorMessage);
  } else if (purchaseResult.success case Success success) {
    return SuccessProductPurchaseResult(
      orderId: success.orderId,
      purchaseId: success.purchaseId,
      productId: success.productId,
      invoiceId: success.invoiceId,
      subscriptionToken: success.subscriptionToken,
    );
  } else {
    return UnknownProductPurchaseResult(cause: 'Unknown purchase result');
  }
}