Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import SwiftUI
import StoreKit
import Yosemite

@MainActor
Expand Down Expand Up @@ -37,7 +36,8 @@ struct InAppPurchasesDebugView: View {
Task {
isPurchasing = true
do {
try await inAppPurchasesForWPComPlansManager.purchaseProduct(with: product.id, for: siteID)
let result = try await inAppPurchasesForWPComPlansManager.purchaseProduct(with: product.id, for: siteID)
print("[IAP Debug] Purchase result: \(result)")
} catch {
purchaseError = PurchaseError(error: error)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ protocol WPComPlanProduct {

extension StoreKit.Product: WPComPlanProduct {}

typealias InAppPurchaseResult = StoreKit.Product.PurchaseResult

protocol InAppPurchasesForWPComPlansProtocol {
/// Retrieves asynchronously all WPCom plans In-App Purchases products.
///
Expand All @@ -33,7 +35,7 @@ protocol InAppPurchasesForWPComPlansProtocol {
/// id: the id of the product to be purchased
/// remoteSiteId: the id of the site linked to the purchasing plan
///
func purchaseProduct(with id: String, for remoteSiteId: Int64) async throws
func purchaseProduct(with id: String, for remoteSiteId: Int64) async throws -> InAppPurchaseResult

/// Retries forwarding the product purchase to our backend, so the plan can be unlocked.
/// This can happen when the purchase was previously successful but unlocking the WPCom plan request
Expand Down Expand Up @@ -73,8 +75,8 @@ final class InAppPurchasesForWPComPlansManager: InAppPurchasesForWPComPlansProto
}
}

func purchaseProduct(with id: String, for remoteSiteId: Int64) async throws {
_ = try await withCheckedThrowingContinuation { continuation in
func purchaseProduct(with id: String, for remoteSiteId: Int64) async throws -> InAppPurchaseResult {
try await withCheckedThrowingContinuation { continuation in
stores.dispatch(InAppPurchaseAction.purchaseProduct(siteID: remoteSiteId, productID: id, completion: { result in
continuation.resume(with: result)
}))
Expand Down