From ed7da76bac2b1209fe9a9919fbad3e8dabe7d1be Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 17 Sep 2019 22:58:06 -0400 Subject: [PATCH] add helpers and renewal info to receipt model --- .../Models/Business/AppleReceiptStatus.cs | 74 +++++++++++++++---- 1 file changed, 60 insertions(+), 14 deletions(-) diff --git a/src/Core/Models/Business/AppleReceiptStatus.cs b/src/Core/Models/Business/AppleReceiptStatus.cs index d0b3a516cb..e4dacdc5a5 100644 --- a/src/Core/Models/Business/AppleReceiptStatus.cs +++ b/src/Core/Models/Business/AppleReceiptStatus.cs @@ -1,5 +1,8 @@ using System; using System.Collections.Generic; +using System.Linq; +using Bit.Core.Enums; +using Bit.Core.Models.Table; using Newtonsoft.Json; namespace Bit.Billing.Models @@ -16,20 +19,47 @@ namespace Bit.Billing.Models public AppleReceipt Receipt { get; set; } [JsonProperty("latest_receipt_info")] public List LatestReceiptInfo { get; set; } - /* - [JsonProperty("latest_expired_receipt_info")] - public AppleReceipt LatestExpiredReceiptInfo { get; set; } - [JsonProperty("auto_renew_status")] - public string AutoRenewStatus { get; set; } - [JsonProperty("auto_renew_product_id")] - public string AutoRenewProductId { get; set; } - [JsonProperty("notification_type")] - public string NotificationType { get; set; } - [JsonProperty("expiration_intent")] - public string ExpirationIntent { get; set; } - [JsonProperty("is_in_billing_retry_period")] - public string IsInBillingRetryPeriod { get; set; } - */ + [JsonProperty("pending_renewal_info")] + public AppleRenewalInfo PendingRenewalInfo { get; set; } + + public string GetOriginalTransactionId() + { + return LatestReceiptInfo?.LastOrDefault()?.OriginalTransactionId; + } + + public string GetLastTransactionId() + { + return LatestReceiptInfo?.LastOrDefault()?.TransactionId; + } + + 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 { @@ -43,6 +73,22 @@ namespace Bit.Billing.Models public List 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 { [JsonProperty("quantity")]