Skip to main content
Solved

Update customerInfo after successful purchase with Paywall's PayWallView?


Tim Mitra
Forum|alt.badge.img+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

Best answer by Tim Mitra

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)
    }

 

View original
Did this post help you find an answer to your question?

12 replies

Michael Fogel
Forum|alt.badge.img+6
  • Dedicated Contributor
  • 382 replies
  • January 18, 2024

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! 


Tim Mitra
Forum|alt.badge.img+2
  • Author
  • Helper
  • 3 replies
  • January 18, 2024

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)
          }
        }

 


Tim Mitra
Forum|alt.badge.img+2
  • Author
  • Helper
  • 3 replies
  • Answer
  • January 22, 2024

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)
    }

 


Chris-29
Forum|alt.badge.img+5
  • Dedicated Member
  • 19 replies
  • May 11, 2024

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


Chris-29
Forum|alt.badge.img+5
  • Dedicated Member
  • 19 replies
  • May 11, 2024

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 .


  • New Member
  • 2 replies
  • August 5, 2024

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.entitlements["pro"]?.isActive == true
}

 

What is wrong or missing?


  • New Member
  • 2 replies
  • August 27, 2024

Anyone could help here?  Thanks.


ptorab
Forum|alt.badge.img
  • New Member
  • 2 replies
  • September 28, 2024

I wonder what I’m missing, is this problem specific to using RC’s own Paywall?

In my case after calling purchase() from Paywall (and Paywall view being dismissed), the purchases() function updates customerInfo, and as long as you have customerInfo as an @ObservedObject in your view (e.g. @ObservedObject userInfo: UserInfo = .shared), you can promptly see the updated entitlements. This works fine with limited testing so far, so a bit worried if I’m missing something.

It seems with some proper flow in the app, user can kept in a spot where “doing more” needs a purchase, without that spot being tight in the sense that it has to be unblocked right at purchase completion.

func purchases(_ purchases: Purchases, receivedUpdated customerInfo: CustomerInfo) { UserInfo.shared.customerInfo = customerInfo }

 


Forum|alt.badge.img
  • New Member
  • 2 replies
  • November 22, 2024

Similar (same?) issue here.

  • iOS 18.0/18.1
  • RC 5.10.0
  • Compiled with Xcode 16.1 beta

 

PaywallView(displayCloseButton: false)
            .onPurchaseCompleted { customerInfo in
                print(customerInfo.entitlements)
                self.isPro = !customerInfo.entitlements.active.isEmpty
            }


The ‘onPurchaseCompleted’ callback/modifier never gets called.


Michael Fogel
Forum|alt.badge.img+6
  • Dedicated Contributor
  • 382 replies
  • November 22, 2024

Hey ​@joey_ ,

 

Is the onPurchaseCompleted block never triggering or only in some instances? 


Forum|alt.badge.img
  • New Member
  • 2 replies
  • November 26, 2024

Hey Michael, thanks for coming back to me.

I haven't seen it fire yet on device (iPhone 14 Pro) or simulator.

In the meantime, we have added defensive code to check customer info e.g. `onDisappear`.


Forum|alt.badge.img+6
  • Helper
  • 15 replies
  • November 28, 2024

Hi all, this solution works for us in our live app with all the relevant closures being called.

Hope it helps someone 🙂
 

.sheet(isPresented: $showPaywall) {
                PaywallView(displayCloseButton: true)
                    .onPurchaseStarted { info in

                    }
                    .onPurchaseCompleted { info in

                    }
                    .onPurchaseCancelled {

                    }
                    .onRestoreStarted {

                    }
                    .onRestoreCompleted { info in

                    }
                    .onPurchaseFailure { error in

                    }
                    .onRestoreFailure { error in

                    }
            }

 


Did this post help you find an answer to your question?

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings