Exemplo n.º 1
0
        private async Task <Result <SubscriptionPackage> > RegisterPackageWithStripe(DtoNewSubscriptionPackage package)
        {
            var billingPackage = new BillingSubscriptionPackage
            {
                Name          = package.PackageName,
                MonthlyAmount = package.MonthlyAmount,
                Identifier    = package.Identifier,
            };

            try
            {
                var id = await billingManager.AddSubscriptionPackage(billingPackage).ConfigureAwait(false);

                return(Result.Ok <SubscriptionPackage>(new SubscriptionPackage
                {
                    PackageName = package.PackageName,
                    ExternalPackageId = id,
                }));
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "Failed to register package with Stripe");
                return(Result.Fail <SubscriptionPackage>("Failed to register package with Stripe"));
            }
        }
Exemplo n.º 2
0
 public async Task <IActionResult> CreatePackage([FromBody] DtoNewSubscriptionPackage package)
 {
     return(await RegisterPackageWithStripe(package)
            .OnSuccess(p => packages.CreateSubscriptionPackage(p))
            .Ensure(p => p.HasValue, "Package exists")
            .OnBoth(p => p.IsFailure ? StatusCode(404) : StatusCode(201))
            .ConfigureAwait(false));
 }