public async Task <IActionResult> Payment([FromBody] ApplePayment payment)
        {
            var r = await _applePaymentService.HandleAsync(payment, _userService.User);

            if (r)
            {
                return(Ok());
            }
            return(BadRequest());
        }
        public async Task <bool> HandleAsync(ApplePayment payment, User user)
        {
            Console.WriteLine(payment.Dump("Apple payment for userId=" + user.Id));
            if (payment.TransactionReceipt == null || (payment.EntityId == null && payment.PlanId == null))
            {
                return(false);
            }

            var receipt = await GetReceiptAsync(payment.TransactionReceipt);

            Console.WriteLine(receipt == null ? "NO APPLE RECEIPT GOT;" : receipt.Dump("Apple receipt"));
            if (receipt == null || receipt.status != 0)
            {
                return(false);
            }

            PaymentTypes?type = payment switch
            {
                var x when x.PlanId != null => PaymentTypes.SubscriptionContinuation,
                var x when x.EntityId != null => PaymentTypes.SaleableEntityBuy,
                        _ => null
            };

            Console.WriteLine("payment type: " + type);
            if (type == null)
            {
                return(false);
            }

            var dbPayment = await CreateAsync(payment, user, type.Value);

            return(type switch
            {
                PaymentTypes.SubscriptionContinuation => await _saleService.SubscriptionContinuationHandle(user,
                                                                                                           payment.PlanId, dbPayment.Id),
                PaymentTypes.SaleableEntityBuy => await _saleService.SaleableEntityBuyHandle(user, payment.EntityId,
                                                                                             dbPayment.Id),
                _ => false
            });