chirag04 / react-native-in-app-utils

A react-native wrapper for handling in-app payments
MIT License
890 stars 185 forks source link

InAppUtils.purchaseProduct returns error when switching between different subscriptions #122

Open rhur opened 6 years ago

rhur commented 6 years ago

I have four different subscriptions under the same subscription level:

trainee.monthly

trainee.annual

pro.monthly

pro.annual

Whenever I subscribe to each of them independently, the purchase works fine. The problem is when I try to Manage subscriptions. With the current iTunes connect config that I described above, I can switch from trainee.monthly to pro.monthly and back and from trainee.annual to pro.annual and back, but nothing else works. I tried moving the subscriptions to different levels in iTunes connect in several ways, but the wanted behavior was never reached (the wanted behavior is being able to switch between any subscription).

The error that I get looks like the following:

{"code":"ESKERRORDOMAIN0","message":"Cannot connect to iTunes Store","nativeStackIOS":["0 RouteTest 0x0000000100176d5c RCTJSErrorFromCodeMessageAndNSError + 152","1 RouteTest 0x0000000100176c84 RCTJSErrorFromNSError + 264","2 RouteTest 0x00000001002b8f5c -[InAppUtils paymentQueue:updatedTransactions:] + 604","3 StoreKit 0x0000000197e206e4 + 104","4 CoreFoundation 0x000000018ac2a710 CFArrayApplyFunction + 68","5 StoreKit 0x0000000197e20660 + 148","6 StoreKit 0x0000000197e21158 + 1220","7 StoreKit 0x0000000197e21c78 + 144","8 StoreKit 0x0000000197e20510 + 152","9 libdispatch.dylib 0x00000001008c9a50 _dispatch_call_block_and_release + 24","10 libdispatch.dylib 0x00000001008c9a10 _dispatch_client_callout + 16","11 libdispatch.dylib 0x00000001008ceb78 _dispatch_main_queue_callback_4CF + 1204","12 CoreFoundation 0x000000018acfd0c8 + 12","13 CoreFoundation 0x000000018acface4 + 1572","14 CoreFoundation 0x000000018ac2ada4 CFRunLoopRunSpecific + 424","15 GraphicsServices 0x000000018c695074 GSEventRunModal + 100","16 UIKit 0x0000000190ee5c9c UIApplicationMain + 208","17 RouteTest 0x000000010001b9ec main + 124","18 libdyld.dylib 0x0000000189c3959c + 4"],"domain":"SKErrorDomain","userInfo": {"NSLocalizedDescription":"Cannot connect to iTunes Store"}

Here's a snippet of my code:

const makePurchase  = (product) =>{
Logger.logInfo("called makepurchase: " + product)
const { InAppUtils } = NativeModules
var products = []
products.push(product)
if (Platform.OS === 'ios') {
    return new Promise(function (resolve, reject) {
    InAppUtils.loadProducts(products, (error, products) => {
        Logger.logInfo("products are:")
        Logger.logInfo(products)
        InAppUtils.purchaseProduct(product, (error, response) => {

            if (error) {

                Logger.logInfo('error in purchase')
                Logger.logInfo(error)
                Logger.logInfo(response)
                return reject(error)
            }
            if(response && response.productIdentifier) {
                Logger.logInfo('Purchase Successful', 'Your Transaction receipt is ' + response.transactionReceipt)
                InAppUtils.receiptData((error, receiptData)=> {
            if(error) {
                        Logger.logInfo(error)
                        return reject(error)
            } else {
            //send to validation server
                    Logger.logInfo("receipt data" + receiptData)
                    var ret =  {
                                        "receiptData":receiptData,
                                    ...products[0]
                                    }
                    Logger.logInfo("return is...")
                    Logger.logInfo(ret)
                    return resolve(ret)
            }
                });
            }
            Logger.logInfo(response)
        })
    })
  })
}}

Why is it not working? Is there a special way to handle what I described?

christophby commented 6 years ago

+1

Chenjh1992 commented 6 years ago

Actually the subscription get schedule to next billing cycle. but the methodupdateTransactions return SKPaymentTransactionStateFailed with error 'Cannot connect to iTunes` .

rhur commented 6 years ago

@Chenjh1992 I tested with a test account where the subscriptions expire faster than on prod. However, after the subscription expired, it did not update to the new selection.

superandrew213 commented 6 years ago

@robertohurtado did you come up with a solution?

rhur commented 6 years ago

@superandrew213 if I remember correctly, this is an issue on Apple's end. I think this is related: https://forums.developer.apple.com/thread/80560

superandrew213 commented 6 years ago

@robertohurtado from what I've heard, it doesn't seem to happen on apps downloaded from App Store.

Mubashirkhan commented 6 years ago

was anyone able to resolve this downgrade issue ?????