react-native-iap: Cannot connect to iTunes Store for sandbox users

Version of react-native-iap

2.2.2

Platforms you faced the error (IOS or Android or both?)

iOS

Expected behavior

await RNIap.buyProduct(MIXED_PACK); should not fail

Actual behavior

I get the error Cannot connect to iTunes Store even if I use a sandbox user

Tested environment (Emulator? Real Device?)

Real device, iPad and iPhone 7

Steps to reproduce the behavior

Just try to run that piece of code. I have read thoroughly the Blog to create a sandbox environment here https://medium.com/@dooboolab/react-native-in-app-purchase-121622d26b67

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 6
  • Comments: 17 (11 by maintainers)

Commits related to this issue

Most upvoted comments

For anyone else stumbling onto issue, also note “Your app is running in the Simulator, which does not support in-app purchase.” is another reason that you may get this error. Must do this on a real device.

@dooboolab I have tried using both RNIap.buyProduct(sku) and RNIap.buyProductWithoutFinishTransaction(sku) with RNIap.finishTransaction(), and for both I have used RNIap.validateReceiptIos(receiptBody, true);, with const receiptBody = {'receipt-data': purchase.transactionReceipt, password: '[apple-id-password]'};, but no luck. Also it is worth noting that whichever password I put in ‘[apple-id-password]’, validateReceiptIos response is always the same. This is an example:

{ receipt: 
   { receipt_type: 'ProductionSandbox',
     adam_id: 0,
     app_item_id: 0,
     bundle_id: 'io.fantastec.swap',
     application_version: '8',
     download_id: 0,
     version_external_identifier: 0,
     receipt_creation_date: '2018-10-09 19:16:09 Etc/GMT',
     receipt_creation_date_ms: '1539112569000',
     receipt_creation_date_pst: '2018-10-09 12:16:09 America/Los_Angeles',
     request_date: '2018-10-09 19:16:10 Etc/GMT',
     request_date_ms: '1539112570436',
     request_date_pst: '2018-10-09 12:16:10 America/Los_Angeles',
     original_purchase_date: '2013-08-01 07:00:00 Etc/GMT',
     original_purchase_date_ms: '1375340400000',
     original_purchase_date_pst: '2013-08-01 00:00:00 America/Los_Angeles',
     original_application_version: '1.0',
     in_app: 
      [ { quantity: '1',
          product_id: 'basic_pack',
          transaction_id: '1000000455003078',
          original_transaction_id: '1000000455003078',
          purchase_date: '2018-10-09 19:16:09 Etc/GMT',
          purchase_date_ms: '1539112569000',
          purchase_date_pst: '2018-10-09 12:16:09 America/Los_Angeles',
          original_purchase_date: '2018-10-09 19:16:09 Etc/GMT',
          original_purchase_date_ms: '1539112569000',
          original_purchase_date_pst: '2018-10-09 12:16:09 America/Los_Angeles',
          is_trial_period: 'false' } ] },
  status: 0,
  environment: 'Sandbox' }

As you might have noticed, receipt_type: 'ProductionSandbox', which should be caused by the fact I am using a real Apple ID username in a sandbox environment (I am not able to create a working test sandbox user, thank you Apple for making our life a living hell).

A note from apple in relation to this error: https://developer.apple.com/library/archive/technotes/tn2413/_index.html#//apple_ref/doc/uid/DTS40016228-CH1-ERROR_MESSAGES-CANNOT_CONNECT_TO_ITUNES_STORE

I think in my case, I get this error when attempting to subscribe to a product when I’m already subscribed to it. It also appears to come up when I’m subscribed and attempting to change my subscription (by initiating a new RNIAP.buySubscription request.

Figured it out, I wasn’t calling the “finishTransaction()” so i was stuck in a loop on my sandbox test account “Purchase was successful” but didn’t not fully process on Apple’s side they called it a dead loop.