Skip to content

Commit cd5b65f

Browse files
committed
Merge branch 'add-more-logs-to-payment-flows'
2 parents ed45d9a + d77b241 commit cd5b65f

3 files changed

Lines changed: 36 additions & 3 deletions

File tree

ios/MullvadLogging/Date+LogFormat.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ extension Date {
1919
return formatter.string(from: self)
2020
}
2121

22+
public var safeLogFormatted: String {
23+
let formatter = DateFormatter()
24+
25+
formatter.dateFormat = "dd/MM/yyyy"
26+
formatter.locale = Locale(identifier: "en_US_POSIX")
27+
formatter.timeZone = TimeZone(abbreviation: "UTC")
28+
29+
return formatter.string(from: self)
30+
}
31+
2232
public var logFileFormatted: String {
2333
let formatter = DateFormatter()
2434

ios/MullvadVPN/StorePaymentManager/StorePaymentManager.swift

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ final actor StorePaymentManager: @unchecked Sendable {
6969
}
7070

7171
func purchase(product: Product) async {
72+
logger.debug("Purchasing product: \(product.id)")
73+
7274
let token: UUID
7375
do {
7476
token = try await self.getPaymentToken()
@@ -140,12 +142,16 @@ final actor StorePaymentManager: @unchecked Sendable {
140142
}
141143

142144
static func finishOutstandingSandboxAndOldAPITransactions() async {
145+
let logger = Logger(label: "StorePaymentManager")
146+
147+
logger.debug("Finishing outstanding sandbox and old transactions")
148+
143149
for await verification in Transaction.unfinished {
144150
guard let payload = try? verification.payloadValue else {
151+
logger.debug("Verification is missing a valid payload")
145152
continue
146153
}
147154

148-
let logger = Logger(label: "StorePaymentManager")
149155
logger.debug("Unfinished transaction environment is \(payload.environment)")
150156

151157
let isStagingEnvironment = payload.environment != .production
@@ -155,8 +161,13 @@ final actor StorePaymentManager: @unchecked Sendable {
155161

156162
if isStagingEnvironment || isOldAPI {
157163
logger.debug(
158-
"Finishing transaction. isStagingEnvironment: \(isStagingEnvironment), isOldAPI: \(isOldAPI)")
164+
"Finishing transaction. isStagingEnvironment: \(isStagingEnvironment), isOldAPI: \(isOldAPI)"
165+
)
159166
await payload.finish()
167+
} else {
168+
logger.debug(
169+
"Skipping transaction. isStagingEnvironment: \(isStagingEnvironment), isOldAPI: \(isOldAPI)"
170+
)
160171
}
161172
}
162173
}
@@ -173,7 +184,15 @@ final actor StorePaymentManager: @unchecked Sendable {
173184
}
174185

175186
private func uploadReceipt(verification: VerificationResult<Transaction>) async throws {
176-
logger.debug("Uploading receipt")
187+
let payload = try verification.payloadValue
188+
189+
let logMessage: String =
190+
"Uploading receipt. "
191+
+ "Product ID: \(payload.productID), "
192+
+ "Environment: \(payload.environment), "
193+
+ "Purchase date: \(payload.purchaseDate.safeLogFormatted), "
194+
+ "Revocation date: \(payload.revocationDate?.safeLogFormatted ?? "none")"
195+
logger.debug(.init(stringLiteral: logMessage))
177196

178197
let result = await interactor.checkPayment(jwsRepresentation: verification.jwsRepresentation)
179198

ios/MullvadVPN/View controllers/InAppPurchase/InAppPurchaseViewController.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
// Copyright © 2026 Mullvad VPN AB. All rights reserved.
77
//
88

9+
import MullvadLogging
910
import StoreKit
1011
import UIKit
1112

1213
class InAppPurchaseViewController: UIViewController, StorePaymentObserver {
14+
private let logger = Logger(label: "InAppPurchaseViewController")
1315
private let storePaymentManager: StorePaymentManager
1416
private let accountNumber: String
1517
private let paymentAction: PaymentAction
@@ -81,6 +83,7 @@ class InAppPurchaseViewController: UIViewController, StorePaymentObserver {
8183
}
8284

8385
func startRestorationBeforePurchaseFlow() async {
86+
logger.debug("Restoring purchases before starting payment flow")
8487
spinnerView.startAnimating()
8588

8689
do {
@@ -106,6 +109,7 @@ class InAppPurchaseViewController: UIViewController, StorePaymentObserver {
106109
}
107110

108111
func startPaymentFlow() async {
112+
logger.debug("Starting payment flow")
109113
spinnerView.startAnimating()
110114

111115
var products: [Product]

0 commit comments

Comments
 (0)