1
0
mirror of https://github.com/bitwarden/server.git synced 2025-01-22 21:51:22 +01:00

parse cancellation dates to detect refunds

This commit is contained in:
Kyle Spearrin 2020-01-28 09:23:50 -05:00
parent 2c68e01e14
commit 82be2ae06b

View File

@ -49,6 +49,22 @@ namespace Bit.Billing.Models
return LatestReceipt;
}
public DateTime? GetLastCancellationDate()
{
return LatestReceiptInfo?.LastOrDefault()?.CancellationDate;
}
public bool IsRefunded()
{
var cancellationDate = GetLastCancellationDate();
var expiresDate = GetLastCancellationDate();
if(cancellationDate.HasValue && expiresDate.HasValue)
{
return cancellationDate.Value <= expiresDate.Value;
}
return false;
}
public Transaction BuildTransactionFromLastTransaction(decimal amount, Guid userId)
{
return new Transaction
@ -111,8 +127,13 @@ namespace Bit.Billing.Models
[JsonProperty("expires_date_ms")]
[JsonConverter(typeof(MsEpochConverter))]
public DateTime ExpiresDate { get; set; }
[JsonProperty("cancellation_date_ms")]
[JsonConverter(typeof(MsEpochConverter))]
public DateTime? CancellationDate { get; set; }
[JsonProperty("web_order_line_item_id")]
public string WebOrderLineItemId { get; set; }
[JsonProperty("cancellation_reason")]
public string CancellationReason { get; set; }
}
public class MsEpochConverter : DateTimeConverterBase