Skip to content
This repository has been archived by the owner on Jun 11, 2023. It is now read-only.

Commit

Permalink
Stripe webhooks updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
pedropaf committed Feb 6, 2015
1 parent 48d8946 commit 01af20c
Showing 1 changed file with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
public async Task<HttpStatusCodeResult> Index()
{
var json = new StreamReader(Request.InputStream).ReadToEnd();

var stripeEvent = StripeEventUtility.ParseEvent(json);

#region All Event types
Expand All @@ -50,7 +49,6 @@
case "charge.failed": // Occurs whenever a failed charge attempt occurs.
break;
case "charge.refunded": // Occurs whenever a charge is refunded, including partial refunds.
var stripeCharge = Stripe.Mapper<StripeCharge>.MapFromJson(stripeEvent.Data.Object.ToString());
break;
case "charge.captured": // Occurs whenever a previously uncaptured charge is captured.
break;
Expand All @@ -71,6 +69,7 @@
case "customer.card.created": // Occurs whenever a new card is created for the customer.
break;
case "customer.card.updated": // Occurs whenever a card's details are changed.
// TODO: Save card updated, might happen when the card is close to expire
break;
case "customer.card.deleted": // Occurs whenever a card is removed from a customer.
break;
Expand All @@ -90,15 +89,22 @@
case "customer.discount.deleted":
break;
case "invoice.created": // Occurs whenever a new invoice is created. If you are using webhooks, Stripe will wait one hour after they have all succeeded to attempt to pay the invoice; the only exception here is on the first invoice, which gets created and paid immediately when you subscribe a customer to a plan. If your webhooks do not all respond successfully, Stripe will continue retrying the webhooks every hour and will not attempt to pay the invoice. After 3 days, Stripe will attempt to pay the invoice regardless of whether or not your webhooks have succeeded. See how to respond to a webhook.
case "invoice.payment_succeeded": // Occurs whenever an invoice attempts to be paid, and the payment succeeds.
break;
case "invoice.payment_failed": // Occurs whenever an invoice attempts to be paid, and the payment fails. This can occur either due to a declined payment, or because the customer has no active card. A particular case of note is that if a customer with no active card reaches the end of its free trial, an invoice.payment_failed notification will occur.
// TODO: Notify customer
break;
case "invoice.payment_succeeded": // Occurs whenever an invoice attempts to be paid, and the payment succeeds.
var stripeInvoice = Stripe.Mapper<StripeInvoice>.MapFromJson(stripeEvent.Data.Object.ToString());
var invoice = Mapper.Map<Invoice>(stripeInvoice);
await InvoiceDataService.CreateOrUpdateAsync(invoice);
// TODO: Send invoice by email
Invoice invoice = Mapper.Map<Invoice>(stripeInvoice);
if (invoice != null && invoice.Total > 0)
{
await InvoiceDataService.CreateOrUpdateAsync(invoice);

// TODO: Send invoice by email

}
break;
case "invoice.updated": // Occurs whenever an invoice changes (for example, the amount could change).
// TODO: Update invoice
break;
case "invoiceitem.created": // Occurs whenever an invoice item is created.
break;
Expand Down

0 comments on commit 01af20c

Please sign in to comment.