From 5e7ac0a9bcf08896b764b8574bdd2460f91ac989 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 23 Sep 2019 10:27:14 -0400 Subject: [PATCH] handle appleReceipt already existing on customer --- .../Implementations/StripePaymentService.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Core/Services/Implementations/StripePaymentService.cs b/src/Core/Services/Implementations/StripePaymentService.cs index b44d374454..4ad28b1ed5 100644 --- a/src/Core/Services/Implementations/StripePaymentService.cs +++ b/src/Core/Services/Implementations/StripePaymentService.cs @@ -1297,7 +1297,20 @@ namespace Bit.Core.Services if(appleReceiptStatus != null) { - stripeCustomerMetadata.Add("appleReceipt", appleReceiptStatus.GetOriginalTransactionId()); + var originalTransactionId = appleReceiptStatus.GetOriginalTransactionId(); + if(stripeCustomerMetadata.ContainsKey("appleReceipt")) + { + if(originalTransactionId != stripeCustomerMetadata["appleReceipt"]) + { + var nowSec = Utilities.CoreHelpers.ToEpocSeconds(DateTime.UtcNow); + stripeCustomerMetadata.Add($"appleReceipt_{nowSec}", stripeCustomerMetadata["appleReceipt"]); + } + stripeCustomerMetadata["appleReceipt"] = originalTransactionId; + } + else + { + stripeCustomerMetadata.Add("appleReceipt", originalTransactionId); + } await _appleIapService.SaveReceiptAsync(appleReceiptStatus, subscriber.Id); }