Skip to content

Commit 853ea0f

Browse files
authored
Custom Entitlement Computation: re-enable syncPurchases/restorePurchases (#2451)
Follow up to #2442
1 parent 4a74d33 commit 853ea0f

File tree

3 files changed

+110
-110
lines changed

3 files changed

+110
-110
lines changed

Sources/Misc/Concurrency/Purchases+async.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,22 @@ extension Purchases {
7272
}
7373
}
7474

75+
func syncPurchasesAsync() async throws -> CustomerInfo {
76+
return try await withCheckedThrowingContinuation { continuation in
77+
syncPurchases { customerInfo, error in
78+
continuation.resume(with: Result(customerInfo, error))
79+
}
80+
}
81+
}
82+
83+
func restorePurchasesAsync() async throws -> CustomerInfo {
84+
return try await withCheckedThrowingContinuation { continuation in
85+
restorePurchases { customerInfo, error in
86+
continuation.resume(with: Result(customerInfo, error))
87+
}
88+
}
89+
}
90+
7591
#if !ENABLE_CUSTOM_ENTITLEMENT_COMPUTATION
7692

7793
func purchaseAsync(product: StoreProduct, promotionalOffer: PromotionalOffer) async throws -> PurchaseResultData {
@@ -102,22 +118,6 @@ extension Purchases {
102118
}
103119
}
104120

105-
func syncPurchasesAsync() async throws -> CustomerInfo {
106-
return try await withCheckedThrowingContinuation { continuation in
107-
syncPurchases { customerInfo, error in
108-
continuation.resume(with: Result(customerInfo, error))
109-
}
110-
}
111-
}
112-
113-
func restorePurchasesAsync() async throws -> CustomerInfo {
114-
return try await withCheckedThrowingContinuation { continuation in
115-
restorePurchases { customerInfo, error in
116-
continuation.resume(with: Result(customerInfo, error))
117-
}
118-
}
119-
}
120-
121121
func checkTrialOrIntroductoryDiscountEligibilityAsync(_ product: StoreProduct) async
122122
-> IntroEligibilityStatus {
123123
return await withCheckedContinuation { continuation in

Sources/Purchasing/Purchases/Purchases.swift

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,28 @@ public extension Purchases {
769769
return try await purchaseAsync(package: package)
770770
}
771771

772+
@objc func syncPurchases(completion: ((CustomerInfo?, PublicError?) -> Void)?) {
773+
self.purchasesOrchestrator.syncPurchases { @Sendable in
774+
completion?($0.value, $0.error?.asPublicError)
775+
}
776+
}
777+
778+
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, *)
779+
func syncPurchases() async throws -> CustomerInfo {
780+
return try await syncPurchasesAsync()
781+
}
782+
783+
@objc func restorePurchases(completion: ((CustomerInfo?, PublicError?) -> Void)? = nil) {
784+
purchasesOrchestrator.restorePurchases { @Sendable in
785+
completion?($0.value, $0.error?.asPublicError)
786+
}
787+
}
788+
789+
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, *)
790+
func restorePurchases() async throws -> CustomerInfo {
791+
return try await restorePurchasesAsync()
792+
}
793+
772794
#if !ENABLE_CUSTOM_ENTITLEMENT_COMPUTATION
773795

774796
@available(iOS 12.2, macOS 10.14.4, watchOS 6.2, macCatalyst 13.0, tvOS 12.2, *)
@@ -801,28 +823,6 @@ public extension Purchases {
801823
return try await purchaseAsync(package: package, promotionalOffer: promotionalOffer)
802824
}
803825

804-
@objc func syncPurchases(completion: ((CustomerInfo?, PublicError?) -> Void)?) {
805-
self.purchasesOrchestrator.syncPurchases { @Sendable in
806-
completion?($0.value, $0.error?.asPublicError)
807-
}
808-
}
809-
810-
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, *)
811-
func syncPurchases() async throws -> CustomerInfo {
812-
return try await syncPurchasesAsync()
813-
}
814-
815-
@objc func restorePurchases(completion: ((CustomerInfo?, PublicError?) -> Void)? = nil) {
816-
purchasesOrchestrator.restorePurchases { @Sendable in
817-
completion?($0.value, $0.error?.asPublicError)
818-
}
819-
}
820-
821-
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, *)
822-
func restorePurchases() async throws -> CustomerInfo {
823-
return try await restorePurchasesAsync()
824-
}
825-
826826
@objc(checkTrialOrIntroDiscountEligibility:completion:)
827827
func checkTrialOrIntroDiscountEligibility(productIdentifiers: [String],
828828
completion: @escaping ([String: IntroEligibility]) -> Void) {

Sources/Purchasing/Purchases/PurchasesType.swift

Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,78 @@ public protocol PurchasesType: AnyObject {
340340
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, *)
341341
func purchase(package: Package) async throws -> PurchaseResultData
342342

343+
/**
344+
* This method will post all purchases associated with the current App Store account to RevenueCat and become
345+
* associated with the current ``appUserID``. If the receipt is being used by an existing user, the current
346+
* ``appUserID`` will be aliased together with the ``appUserID`` of the existing user.
347+
* Going forward, either ``appUserID`` will be able to reference the same user.
348+
*
349+
* You shouldn't use this method if you have your own account system. In that case "restoration" is provided
350+
* by your app passing the same ``appUserID`` used to purchase originally.
351+
*
352+
* - Note: This may force your users to enter the App Store password so should only be performed on request of
353+
* the user. Typically with a button in settings or near your purchase UI. Use
354+
* ``Purchases/syncPurchases(completion:)`` if you need to restore transactions programmatically.
355+
*
356+
* - Warning: Receiving a ``CustomerInfo`` instead of an error does not imply that the user has any
357+
* entitlements, simply that the process was successful. You must verify the ``CustomerInfo/entitlements``
358+
* to confirm that they are active.
359+
*/
360+
func restorePurchases(completion: ((CustomerInfo?, PublicError?) -> Void)?)
361+
362+
/**
363+
* This method will post all purchases associated with the current App Store account to RevenueCat and become
364+
* associated with the current ``appUserID``. If the receipt is being used by an existing user, the current
365+
* ``appUserID`` will be aliased together with the ``appUserID`` of the existing user.
366+
* Going forward, either ``appUserID`` will be able to reference the same user.
367+
*
368+
* You shouldn't use this method if you have your own account system. In that case "restoration" is provided
369+
* by your app passing the same ``appUserID`` used to purchase originally.
370+
*
371+
* - Note: This may force your users to enter the App Store password so should only be performed on request of
372+
* the user. Typically with a button in settings or near your purchase UI. Use
373+
* ``Purchases/syncPurchases(completion:)`` if you need to restore transactions programmatically.
374+
*
375+
* - Warning: Receiving a ``CustomerInfo`` instead of an error does not imply that the user has any
376+
* entitlements, simply that the process was successful. You must verify the ``CustomerInfo/entitlements``
377+
* to confirm that they are active.
378+
*/
379+
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, *)
380+
func restorePurchases() async throws -> CustomerInfo
381+
382+
/**
383+
* This method will post all purchases associated with the current App Store account to RevenueCat and
384+
* become associated with the current ``appUserID``.
385+
*
386+
* If the receipt is being used by an existing user, the current ``appUserID`` will be aliased together with
387+
* the ``appUserID`` of the existing user.
388+
* Going forward, either ``appUserID`` will be able to reference the same user.
389+
*
390+
* - Warning: This function should only be called if you're not calling any purchase method.
391+
*
392+
* - Note: This method will not trigger a login prompt from App Store. However, if the receipt currently
393+
* on the device does not contain subscriptions, but the user has made subscription purchases, this method
394+
* won't be able to restore them. Use ``Purchases/restorePurchases(completion:)`` to cover those cases.
395+
*/
396+
func syncPurchases(completion: ((CustomerInfo?, PublicError?) -> Void)?)
397+
398+
/**
399+
* This method will post all purchases associated with the current App Store account to RevenueCat and
400+
* become associated with the current ``appUserID``.
401+
*
402+
* If the receipt is being used by an existing user, the current ``appUserID`` will be aliased together with
403+
* the ``appUserID`` of the existing user.
404+
* Going forward, either ``appUserID`` will be able to reference the same user.
405+
*
406+
* - Warning: This function should only be called if you're not calling any purchase method.
407+
*
408+
* - Note: This method will not trigger a login prompt from App Store. However, if the receipt currently
409+
* on the device does not contain subscriptions, but the user has made subscription purchases, this method
410+
* won't be able to restore them. Use ``Purchases/restorePurchases(completion:)`` to cover those cases.
411+
*/
412+
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, *)
413+
func syncPurchases() async throws -> CustomerInfo
414+
343415
#if !ENABLE_CUSTOM_ENTITLEMENT_COMPUTATION
344416

345417
/**
@@ -443,78 +515,6 @@ public protocol PurchasesType: AnyObject {
443515
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, *)
444516
func purchase(package: Package, promotionalOffer: PromotionalOffer) async throws -> PurchaseResultData
445517

446-
/**
447-
* This method will post all purchases associated with the current App Store account to RevenueCat and become
448-
* associated with the current ``appUserID``. If the receipt is being used by an existing user, the current
449-
* ``appUserID`` will be aliased together with the ``appUserID`` of the existing user.
450-
* Going forward, either ``appUserID`` will be able to reference the same user.
451-
*
452-
* You shouldn't use this method if you have your own account system. In that case "restoration" is provided
453-
* by your app passing the same ``appUserID`` used to purchase originally.
454-
*
455-
* - Note: This may force your users to enter the App Store password so should only be performed on request of
456-
* the user. Typically with a button in settings or near your purchase UI. Use
457-
* ``Purchases/syncPurchases(completion:)`` if you need to restore transactions programmatically.
458-
*
459-
* - Warning: Receiving a ``CustomerInfo`` instead of an error does not imply that the user has any
460-
* entitlements, simply that the process was successful. You must verify the ``CustomerInfo/entitlements``
461-
* to confirm that they are active.
462-
*/
463-
func restorePurchases(completion: ((CustomerInfo?, PublicError?) -> Void)?)
464-
465-
/**
466-
* This method will post all purchases associated with the current App Store account to RevenueCat and become
467-
* associated with the current ``appUserID``. If the receipt is being used by an existing user, the current
468-
* ``appUserID`` will be aliased together with the ``appUserID`` of the existing user.
469-
* Going forward, either ``appUserID`` will be able to reference the same user.
470-
*
471-
* You shouldn't use this method if you have your own account system. In that case "restoration" is provided
472-
* by your app passing the same ``appUserID`` used to purchase originally.
473-
*
474-
* - Note: This may force your users to enter the App Store password so should only be performed on request of
475-
* the user. Typically with a button in settings or near your purchase UI. Use
476-
* ``Purchases/syncPurchases(completion:)`` if you need to restore transactions programmatically.
477-
*
478-
* - Warning: Receiving a ``CustomerInfo`` instead of an error does not imply that the user has any
479-
* entitlements, simply that the process was successful. You must verify the ``CustomerInfo/entitlements``
480-
* to confirm that they are active.
481-
*/
482-
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, *)
483-
func restorePurchases() async throws -> CustomerInfo
484-
485-
/**
486-
* This method will post all purchases associated with the current App Store account to RevenueCat and
487-
* become associated with the current ``appUserID``.
488-
*
489-
* If the receipt is being used by an existing user, the current ``appUserID`` will be aliased together with
490-
* the ``appUserID`` of the existing user.
491-
* Going forward, either ``appUserID`` will be able to reference the same user.
492-
*
493-
* - Warning: This function should only be called if you're not calling any purchase method.
494-
*
495-
* - Note: This method will not trigger a login prompt from App Store. However, if the receipt currently
496-
* on the device does not contain subscriptions, but the user has made subscription purchases, this method
497-
* won't be able to restore them. Use ``Purchases/restorePurchases(completion:)`` to cover those cases.
498-
*/
499-
func syncPurchases(completion: ((CustomerInfo?, PublicError?) -> Void)?)
500-
501-
/**
502-
* This method will post all purchases associated with the current App Store account to RevenueCat and
503-
* become associated with the current ``appUserID``.
504-
*
505-
* If the receipt is being used by an existing user, the current ``appUserID`` will be aliased together with
506-
* the ``appUserID`` of the existing user.
507-
* Going forward, either ``appUserID`` will be able to reference the same user.
508-
*
509-
* - Warning: This function should only be called if you're not calling any purchase method.
510-
*
511-
* - Note: This method will not trigger a login prompt from App Store. However, if the receipt currently
512-
* on the device does not contain subscriptions, but the user has made subscription purchases, this method
513-
* won't be able to restore them. Use ``Purchases/restorePurchases(completion:)`` to cover those cases.
514-
*/
515-
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, *)
516-
func syncPurchases() async throws -> CustomerInfo
517-
518518
/**
519519
* Computes whether or not a user is eligible for the introductory pricing period of a given product.
520520
* You should use this method to determine whether or not you show the user the normal product price or

0 commit comments

Comments
 (0)