1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-16 10:38:17 -05:00

add helpers and renewal info to receipt model

This commit is contained in:
Kyle Spearrin 2019-09-17 22:58:06 -04:00
parent 8290ddbb94
commit ed7da76bac

View File

@ -1,5 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using Bit.Core.Enums;
using Bit.Core.Models.Table;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Bit.Billing.Models namespace Bit.Billing.Models
@ -16,20 +19,47 @@ namespace Bit.Billing.Models
public AppleReceipt Receipt { get; set; } public AppleReceipt Receipt { get; set; }
[JsonProperty("latest_receipt_info")] [JsonProperty("latest_receipt_info")]
public List<AppleTransaction> LatestReceiptInfo { get; set; } public List<AppleTransaction> LatestReceiptInfo { get; set; }
/* [JsonProperty("pending_renewal_info")]
[JsonProperty("latest_expired_receipt_info")] public AppleRenewalInfo PendingRenewalInfo { get; set; }
public AppleReceipt LatestExpiredReceiptInfo { get; set; }
[JsonProperty("auto_renew_status")] public string GetOriginalTransactionId()
public string AutoRenewStatus { get; set; } {
[JsonProperty("auto_renew_product_id")] return LatestReceiptInfo?.LastOrDefault()?.OriginalTransactionId;
public string AutoRenewProductId { get; set; } }
[JsonProperty("notification_type")]
public string NotificationType { get; set; } public string GetLastTransactionId()
[JsonProperty("expiration_intent")] {
public string ExpirationIntent { get; set; } return LatestReceiptInfo?.LastOrDefault()?.TransactionId;
[JsonProperty("is_in_billing_retry_period")] }
public string IsInBillingRetryPeriod { get; set; }
*/ public AppleTransaction GetLastTransaction()
{
return LatestReceiptInfo?.LastOrDefault();
}
public DateTime? GetLastExpiresDate()
{
return LatestReceiptInfo?.LastOrDefault()?.ExpiresDate;
}
public string GetReceiptData()
{
return LatestReceipt;
}
public Transaction BuildTransactionFromLastTransaction(decimal amount, Guid userId)
{
return new Transaction
{
Amount = amount,
CreationDate = GetLastTransaction().PurchaseDate,
Gateway = GatewayType.AppStore,
GatewayId = GetLastTransactionId(),
UserId = userId,
PaymentMethodType = PaymentMethodType.AppleInApp,
Details = GetLastTransactionId()
};
}
public class AppleReceipt public class AppleReceipt
{ {
@ -43,6 +73,22 @@ namespace Bit.Billing.Models
public List<AppleTransaction> InApp { get; set; } public List<AppleTransaction> InApp { get; set; }
} }
public class AppleRenewalInfo
{
[JsonProperty("expiration_intent")]
public string ExpirationIntent { get; set; }
[JsonProperty("auto_renew_product_id")]
public string AutoRenewProductId { get; set; }
[JsonProperty("original_transaction_id")]
public string OriginalTransactionId { get; set; }
[JsonProperty("is_in_billing_retry_period")]
public string IsInBillingRetryPeriod { get; set; }
[JsonProperty("product_id")]
public string ProductId { get; set; }
[JsonProperty("auto_renew_status")]
public string AutoRenewStatus { get; set; }
}
public class AppleTransaction public class AppleTransaction
{ {
[JsonProperty("quantity")] [JsonProperty("quantity")]