Exemplo n.º 1
0
        public async Task ConfirmPayment(StripeConfirmPaymentInput input)
        {
            var paymentId = await _subscriptionPaymentExtensionDataRepository.GetPaymentIdOrNullAsync(
                StripeGatewayManager.StripeSessionIdSubscriptionPaymentExtensionDataKey,
                input.StripeSessionId
                );

            if (!paymentId.HasValue)
            {
                throw new ApplicationException($"Cannot find any payment with sessionId {input.StripeSessionId}");
            }


            var payment = await _subscriptionPaymentRepository.GetAsync(paymentId.Value);

            if (payment.Status != SubscriptionPaymentStatus.NotPaid)
            {
                throw new ApplicationException(
                          $"Invalid payment status {payment.Status}, cannot create a charge on stripe !");
            }

            payment.Gateway = SubscriptionPaymentGatewayType.Stripe;

            var newEditionId = payment.EditionId;

            var service = new SessionService();
            var session = service.Get(input.StripeSessionId);

            if (session.Mode == "payment")
            {
                payment.ExternalPaymentId = session.PaymentIntentId;
            }
            else if (session.Mode == "subscription")
            {
                payment.ExternalPaymentId = session.SubscriptionId;
            }
            else
            {
                throw new ApplicationException(
                          $"Unexpected session mode {session.Mode}. 'payment' or 'subscription' expected");
            }

            payment.SetAsPaid();
            await CurrentUnitOfWork.SaveChangesAsync();

            if (payment.IsProrationPayment())
            {
                await ConfirmSubscriptionUpgradeProrationPayment(newEditionId, payment.TenantId);
            }

            await CompletePayment(paymentId.Value);
        }
Exemplo n.º 2
0
        public async Task ConfirmPayment(StripeConfirmPaymentInput input)
        {
            var payment = await _subscriptionPaymentRepository.GetAsync(input.PaymentId);

            if (payment.Status != SubscriptionPaymentStatus.NotPaid)
            {
                throw new ApplicationException($"Invalid payment status {payment.Status}, cannot create a charge on stripe !");
            }

            var result = await _stripeGatewayManager.CreateCharge(input.StripeToken, payment.Amount, payment.Description);

            payment.Gateway           = SubscriptionPaymentGatewayType.Stripe;
            payment.ExternalPaymentId = result.Id;
            payment.SetAsPaid();
        }