7.1 C
New York
Saturday, April 12, 2025

ios – Process code being known as twice for revenuecat code


I’ve the next code. The self.buy code contained in the Process {} is being known as twice. Although the remainder of the code above is known as as soon as. Can somebody please assist?

@MainActor func purchaseProduct(productId: String, plan: String, supply: String, vc: UIViewController) async -> Bool {
    
Purchases.shared.getOfferings { (choices, error) in
            if let choices = choices {
                for providing in choices.all {
                    let packages = providing.worth.availablePackages
                    if let indexOfItem = packages.firstIndex(the place: { $0.storeProduct.productIdentifier == productId }) {
                        let bundle = packages[indexOfItem]
                        
                        Purchases.shared.buy(bundle: bundle) { (transaction, customerInfo, error, userCancelled) in
                            if customerInfo?.entitlements["premium"]?.isActive == true {
                                Process {
                                    await self.buy (vc: vc, productId: productId, product: productId, transaction: transaction?.transactionIdentifier ?? "")
                                }
                            } else if userCancelled {
                                DispatchQueue.major.async {
                                    Amplitude.sharedInstance.observe(
                                        eventType: "payment_cancelled",
                                        eventProperties: [
                                            "PlanId": productId,
                                            "UserId": WUser.sharedInstance.userId,
                                            "Source": source
                                        ]
                                    )
                                    if (self.loadingIndicator != nil) {
                                        self.loadingIndicator.removeFromSuperview()
                                    }
                                }
                            } else if error != nil {
                                DispatchQueue.major.async {
                                    Amplitude.sharedInstance.observe(
                                        eventType: "payment_failed",
                                        eventProperties: [
                                            "PlanId": productId,
                                            "UserId": WUser.sharedInstance.userId,
                                            "Source": source,
                                            "ErrorObject": String(describing: error),
                                            "Error": error?.localizedDescription
                                        ]
                                    )
                                }
                            } else {
                                DispatchQueue.major.async {
                                    Amplitude.sharedInstance.observe(
                                        eventType: "payment_failed_no_error",
                                        eventProperties: [
                                            "PlanId": productId,
                                            "UserId": WUser.sharedInstance.userId,
                                            "Source": source
                                        ]
                                    )
                                    
                                    if (self.loadingIndicator != nil) {
                                        self.loadingIndicator.removeFromSuperview()
                                    }
                                    showMessageWithTitle("Error", "We have been unable to course of your buy.", .error)
                                }
                            }
                        }
                    }
                }
            } else {
                DispatchQueue.major.async {
                    Amplitude.sharedInstance.observe(
                        eventType: "payment_failed",
                        eventProperties: [
                            "PlanId": productId,
                            "UserId": WUser.sharedInstance.userId,
                            "Source": source,
                            "Error": "Error fetching packages"
                        ]
                    )
                    
                    if (self.loadingIndicator != nil) {
                        self.loadingIndicator.removeFromSuperview()
                    }
                    showMessageWithTitle("Error", "We have been unable to course of your buy.", .error)
                }
            }
        }

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles