Skip to content

Commit 4b21955

Browse files
authored
Merge pull request #8133 from woocommerce/issue/8130-iap-expose-purchase-result
[In-app Purchases] Include purchase result in purchaseProduct API
2 parents c43372b + ded8c4c commit 4b21955

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

WooCommerce/Classes/ViewRelated/InAppPurchases/InAppPurchasesDebugView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import SwiftUI
2-
import StoreKit
32
import Yosemite
43

54
@MainActor
@@ -37,7 +36,8 @@ struct InAppPurchasesDebugView: View {
3736
Task {
3837
isPurchasing = true
3938
do {
40-
try await inAppPurchasesForWPComPlansManager.purchaseProduct(with: product.id, for: siteID)
39+
let result = try await inAppPurchasesForWPComPlansManager.purchaseProduct(with: product.id, for: siteID)
40+
print("[IAP Debug] Purchase result: \(result)")
4141
} catch {
4242
purchaseError = PurchaseError(error: error)
4343
}

WooCommerce/Classes/ViewRelated/InAppPurchases/InAppPurchasesForWPComPlansManager.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ protocol WPComPlanProduct {
1515

1616
extension StoreKit.Product: WPComPlanProduct {}
1717

18+
typealias InAppPurchaseResult = StoreKit.Product.PurchaseResult
19+
1820
protocol InAppPurchasesForWPComPlansProtocol {
1921
/// Retrieves asynchronously all WPCom plans In-App Purchases products.
2022
///
@@ -33,7 +35,7 @@ protocol InAppPurchasesForWPComPlansProtocol {
3335
/// id: the id of the product to be purchased
3436
/// remoteSiteId: the id of the site linked to the purchasing plan
3537
///
36-
func purchaseProduct(with id: String, for remoteSiteId: Int64) async throws
38+
func purchaseProduct(with id: String, for remoteSiteId: Int64) async throws -> InAppPurchaseResult
3739

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

76-
func purchaseProduct(with id: String, for remoteSiteId: Int64) async throws {
77-
_ = try await withCheckedThrowingContinuation { continuation in
78+
func purchaseProduct(with id: String, for remoteSiteId: Int64) async throws -> InAppPurchaseResult {
79+
try await withCheckedThrowingContinuation { continuation in
7880
stores.dispatch(InAppPurchaseAction.purchaseProduct(siteID: remoteSiteId, productID: id, completion: { result in
7981
continuation.resume(with: result)
8082
}))

0 commit comments

Comments
 (0)