From 7675478daa53b9bdb6188f58069403cb0bde8c13 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Sun, 3 Feb 2019 00:05:35 -0500 Subject: [PATCH] refund if something screws up --- src/Billing/Controllers/StripeController.cs | 27 ++++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/Billing/Controllers/StripeController.cs b/src/Billing/Controllers/StripeController.cs index 0803e785d3..44d6133498 100644 --- a/src/Billing/Controllers/StripeController.cs +++ b/src/Billing/Controllers/StripeController.cs @@ -406,17 +406,26 @@ namespace Bit.Billing.Controllers return false; } - var invoiceService = new InvoiceService(); - await invoiceService.UpdateAsync(invoice.Id, new InvoiceUpdateOptions + try { - Metadata = new Dictionary + var invoiceService = new InvoiceService(); + await invoiceService.UpdateAsync(invoice.Id, new InvoiceUpdateOptions { - ["btTransactionId"] = transactionResult.Target.Id, - ["btPayPalTransactionId"] = - transactionResult.Target.PayPalDetails?.AuthorizationId - } - }); - await invoiceService.PayAsync(invoice.Id, new InvoicePayOptions { PaidOutOfBand = true }); + Metadata = new Dictionary + { + ["btTransactionId"] = transactionResult.Target.Id, + ["btPayPalTransactionId"] = + transactionResult.Target.PayPalDetails?.AuthorizationId + } + }); + await invoiceService.PayAsync(invoice.Id, new InvoicePayOptions { PaidOutOfBand = true }); + } + catch(Exception e) + { + await _btGateway.Transaction.RefundAsync(transactionResult.Target.Id); + throw e; + } + return true; }