/*
         * Here we're initializing the part of the iDeal payment that has to happen on the backend. For now, that's only attaching an actual customer record to the payment source.
         * In the future to handle SCA, we might need to start using payment intents or checkout here. SCA starts from september the 14th. The support for iDeal is not there yet though, so we'll have to wait.
         */
        public async Task InitializeIDealCheckout(IDealCheckout checkout, CancellationToken token)
        {
            logger.LogInformation("Initializing iDeal");
            IEnumerable <ValidationResult> validationResults = ValidationHelper.Validate(checkout, serviceProvider);

            if (validationResults.Any())
            {
                throw new InvalidOperationException(string.Join(",", validationResults.Select(v => $"{string.Join(", ", v.MemberNames)}: {v.ErrorMessage}")));
            }

            ApplicationUser user = await userManager.FindByEmailAsync(checkout.Email).ConfigureAwait(false);

            Customer customer = await GetOrCreateCustomer(checkout.Name, checkout.Email, token).ConfigureAwait(false);

            Source source = await sourceService.AttachAsync(
                customer.Id,
                new SourceAttachOptions()
            {
                Source = checkout.SourceId
            },
                cancellationToken : token).ConfigureAwait(false);

            context.DonationEventLog.Add(new DonationEventLog(userId: user?.Id, type: DonationEventType.Internal, eventData: source.ToJson()));
            await context.SaveChangesAsync(token).ConfigureAwait(false);

            logger.LogInformation("Done initializing iDeal");
        }
Beispiel #2
0
        public DonationMutationGraph()
        {
            FieldAsync <NonNullGraphType <StringGraphType>, string>(
                "initializeCreditCardCheckout",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <CreditCardCheckoutInputGraph> >()
            {
                Name = "checkout"
            }),
                resolve: c =>
            {
                CreditCardCheckout checkout = c.GetArgument <CreditCardCheckout>("checkout");
                var provider = c.GetUserContext().ServiceProvider;
                return(provider.GetRequiredService <IDonationService>()
                       .InitializeCreditCardCheckout(checkout, c.CancellationToken));
            });

            FieldAsync <NonNullGraphType <StringGraphType>, string>(
                "initializeSepaDirect",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <SepaDirectCheckoutInputGraph> >()
            {
                Name = "checkout"
            }),
                resolve: async c =>
            {
                SepaDirectCheckout checkout = c.GetArgument <SepaDirectCheckout>("checkout");
                var provider = c.GetUserContext().ServiceProvider;
                await provider.GetRequiredService <IDonationService>()
                .InitializeSepaDirect(checkout, c.CancellationToken)
                .ConfigureAwait(false);
                return(checkout.SourceId);
            });

            FieldAsync <NonNullGraphType <StringGraphType>, string>(
                "initializeIDealCheckout",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IDealCheckoutInputGraph> >()
            {
                Name = "checkout"
            }),
                resolve: async c =>
            {
                IDealCheckout checkout = c.GetArgument <IDealCheckout>("checkout");
                var provider           = c.GetUserContext().ServiceProvider;
                await provider.GetRequiredService <IDonationService>()
                .InitializeIDealCheckout(checkout, c.CancellationToken)
                .ConfigureAwait(false);
                return(checkout.SourceId);
            });

            FieldAsync <NonNullGraphType <StringGraphType>, string>(
                "cancelSubscription",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> >()
            {
                Name = "subscriptionId"
            }),
                resolve: async c =>
            {
                string subscriptionId = c.GetArgument <string>("subscriptionId");
                var context           = c.GetUserContext();
                await context.ServiceProvider
                .GetRequiredService <IDonationService>()
                .CancelSubscription(subscriptionId, context.User, c.CancellationToken)
                .ConfigureAwait(false);
                return(subscriptionId);
            });
        }