Exemplo n.º 1
0
        public async Task HandleEventAsync(Stripe.Event stripeEvent)
        {
            switch (stripeEvent.Type)
            {
            case "customer.subscription.updated": {
                await SubscriptionUpdatedAsync((Subscription)stripeEvent.Data.Object).AnyContext();

                break;
            }

            case "customer.subscription.deleted": {
                await SubscriptionDeletedAsync((Subscription)stripeEvent.Data.Object).AnyContext();

                break;
            }

            case "invoice.payment_succeeded": {
                await InvoicePaymentSucceededAsync((Invoice)stripeEvent.Data.Object).AnyContext();

                break;
            }

            case "invoice.payment_failed": {
                await InvoicePaymentFailedAsync((Invoice)stripeEvent.Data.Object).AnyContext();

                break;
            }

            default: {
                _logger.LogTrace("Unhandled stripe webhook called. Type: {Type} Id: {Id} Account: {Account}", stripeEvent.Type, stripeEvent.Id, stripeEvent.Account);
                break;
            }
            }
        }
Exemplo n.º 2
0
        private Session ExpandAsSession(Stripe.Event stripeEvent)
        {
            var session = stripeEvent.Data.Object as Session;
            var service = new SessionService();

            var options = new SessionGetOptions();

            options.AddExpand("customer");

            return(service.Get(session.Id, options));
        }
    private string GetInvoiceId(Stripe.Event stripeEvent)
    {
        var invoiceId = "";

        if (stripeEvent.Type.StartsWith("invoice"))
        {
            var invoice = stripeEvent.Data.Object as Invoice;

            invoiceId = invoice !.Id;
        }
        return(invoiceId);
    }
Exemplo n.º 4
0
 private async Task<Subscription> GetSubscriptionAsync(Stripe.Event parsedEvent, bool fresh = false)
 {
     if(!(parsedEvent.Data.Object is Subscription eventSubscription))
     {
         throw new Exception("Subscription is null (from parsed event). " + parsedEvent.Id);
     }
     if(!fresh)
     {
         return eventSubscription;
     }
     var subscriptionService = new SubscriptionService();
     var subscription = await subscriptionService.GetAsync(eventSubscription.Id);
     if(subscription == null)
     {
         throw new Exception("Subscription is null. " + eventSubscription.Id);
     }
     return subscription;
 }
Exemplo n.º 5
0
 private async Task<Invoice> GetInvoiceAsync(Stripe.Event parsedEvent, bool fresh = false)
 {
     if(!(parsedEvent.Data.Object is Invoice eventInvoice))
     {
         throw new Exception("Invoice is null (from parsed event). " + parsedEvent.Id);
     }
     if(!fresh)
     {
         return eventInvoice;
     }
     var invoiceService = new InvoiceService();
     var invoice = await invoiceService.GetAsync(eventInvoice.Id);
     if(invoice == null)
     {
         throw new Exception("Invoice is null. " + eventInvoice.Id);
     }
     return invoice;
 }
Exemplo n.º 6
0
 private async Task<Charge> GetChargeAsync(Stripe.Event parsedEvent, bool fresh = false)
 {
     if(!(parsedEvent.Data.Object is Charge eventCharge))
     {
         throw new Exception("Charge is null (from parsed event). " + parsedEvent.Id);
     }
     if(!fresh)
     {
         return eventCharge;
     }
     var chargeService = new ChargeService();
     var charge = await chargeService.GetAsync(eventCharge.Id);
     if(charge == null)
     {
         throw new Exception("Charge is null. " + eventCharge.Id);
     }
     return charge;
 }
    private string GetSubscriptionId(Stripe.Event stripeEvent)
    {
        var invoice = stripeEvent.Data.Object as Invoice;

        if (invoice != null)
        {
            return(invoice.SubscriptionId);
        }

        var subscription = stripeEvent.Data.Object as Subscription;

        if (subscription != null)
        {
            return(subscription.Id);
        }

        return(string.Empty);
    }