0

I am trying produce an app that requires users to subscribe when creating an account, and can only be used via an active paid subscription.

Unless I am going about this all wrong, I assumed I would want a way to somehow tie their subscription to their in-house account with the app, rather than to their apple-ID.

I actually had come up with a solution to this, very similar to an answer to a similar question posted on stack, by pulling out the original_transaction_id from the receipt and storing that with the user in firebase.

This worked in development, but once I got the app in the app store and downloaded it to test, it got hung up right here....

    func verifyPurchaseForNewAccount(_ purchase: RegisteredPurchase) {
         NetworkActivityIndicatorManager.NetworkOperationsStarted()
         let appleValidator = AppleReceiptValidator(service: .sandbox)
         SwiftyStoreKit.verifyReceipt(using: appleValidator, password: sharedSecret) { result in
         NetworkActivityIndicatorManager.NetworkOperationFinished()

        switch result {
        case .success(let receipt):
            print("success")
            let productId = "com.glossappllc.theglossapp.monthlysubscription"

            switch purchase {
            case .monthly:
                let purchaseResult = SwiftyStoreKit.verifySubscription(
                    type: .autoRenewable, productId: productId,
                    inReceipt: receipt,
                    validUntil: Date()
                )
                let receiptArray = receipt["receipt"]?["in_app"] as! NSArray
                let originalReceipt = receiptArray.firstObject as! NSDictionary

RIGHT HERE, it seems it cannot find the "original_transaction_id".

                if let originalTransactionID = originalReceipt["original_transaction_id"] as? String {
                    print("original transaction ID: ", originalTransactionID)
                    DataService.ds.REF_USERS.child(self.DBuserID).updateChildValues(["isSubscribed": "true", "purchaseID": originalTransactionID])

                    self.sendToNewUserFlow()
                }

            }

        case .error(let error):
            print("error: ", error.localizedDescription)
            if case .noReceiptData = error {
                self.refreshReceipt()
            }
        }
    }
}

Is there another way to tie the two accounts together?

Or is there a way to test through Xcode in and environment that more closely resembles production? I know the receipt must still exist, but maybe somehow it is formatted differently?

If I can't test it with a log in xcode it's hard to know why it isn't working anymore...

Math Engel
  • 83
  • 12
  • So I switched the build schema from debug to release. And ran it again. I was able to use my real appleID instead of a sandbox User. And it all worked. It found the "original_transaction_id", and saved it. Does anyone know why this might not be working with the version released on the apple App Store? – Math Engel May 06 '17 at 20:36
  • Is there any chance that this is the problem? let appleValidator = AppleReceiptValidator(service: .sandbox). I just set .sanbox to .production, don't know how I missed/forgot about that. Hopefully that does it. – Math Engel May 09 '17 at 23:20

0 Answers0