Skip to main content
Solved

Update customerInfo after successful purchase with Paywall's PayWallView?

  • 15 January 2024
  • 7 replies
  • 390 views

Hi, I’m using the PaywallView in my app after the user creates 5 records. When the user tries to add a record greater than 5, the Paywall displays.

However I don’t know how to update my logic if the user successfully purchases a subscription. The Pay wall dismisses after “you’re all set” displays. Is there a callback I can use to update the local state of the subscription? Does .sheet(isPresented:_) have an onEnded or the like where I can call Purchases.shared.customerInfo() ?

I can check the in a task when the view loads… but not sure how to update the state during/after the purchase

Hey @Tim Mitra !

 

You can listen to the customerInfo during the purchase of the paywall by calling the following: 

purchaseCompleted: { customerInfo in
print("Purchase completed: \(customerInfo.entitlements)")
}

 

More information on this can be found in the code block here: https://www.revenuecat.com/docs/displaying-paywalls#ios

 

Hope that helps! 


I’m doing that but not at the app level. I want my users to be able to perform some actions deeper in the app. When they reach a number of activities, I’m using PaywallView(), but there doesn’t seem to be a reliable way to get notice that the purchase was successful.

 

.task {
do {
let customerInfo = try await Purchases.shared.customerInfo()
isProUser = customerInfo.entitlementsl"Pro"]?.isActive == true
// uddate AppStorage
subscribed = isProUser
print("isProUser: \(isProUser)")
} catch {
print(error.localizedDescription)
}
}

 


This is my solution:
 

   .sheet(isPresented: $displayPaywall,
onDismiss: {
Task {
do {
let customerInfo = try await Purchases.shared.customerInfo()
isProUser = customerInfo.entitlementss"Pro"]?.isActive == true
// update AppStorage
subscribed = isProUser
print("isProUser: \(isProUser)")
} catch {
print(error.localizedDescription)
}
}
}) {
PaywallView(displayCloseButton: true)
}

 


@Tim Mitra I had the EXACT same question. This answer is how I’m doing to do it with PaywallView.


If the documentation on this page was updated it would really help.  For the “custom logic” example it shows a purchaseCompleted completion handler you can use.  However, it’s not clear at all how to do that with the “manually” example.  From that other thread I learned you can use .onPurchaseCompleted .


I’m attempting to use .onPurchaseCompleted but don’t see it called after PaywallView is dismissed.

.sheet(isPresented: self.$displayPaywall) {
PaywallView(displayCloseButton: true)
}
.onPurchaseCompleted { customerInfo in
    print("purchase completed")
    isSubscribed = customerInfo.entitlementst"pro"]?.isActive == true
}

 

What is wrong or missing?


Anyone could help here?  Thanks.


Reply