Solved

Update customerInfo after successful purchase with Paywall's PayWallView?

  • 15 January 2024
  • 5 replies
  • 161 views

Badge +2

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

icon

Best answer by Tim Mitra 22 January 2024, 06:11

View original

5 replies

Userlevel 4
Badge +6

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! 

Badge +2

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.entitlements["Pro"]?.isActive == true
// uddate AppStorage
subscribed = isProUser
print("isProUser: \(isProUser)")
} catch {
print(error.localizedDescription)
}
}

 

Badge +2

This is my solution:
 

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

 

Userlevel 2
Badge +4

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

Userlevel 2
Badge +4

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 .

Reply