0

I seem to be stuck on this. Trying to validate the receipt (server side) on an in-app purchase on IOS (haven't tried with android, yet.)

I'm using the official in_app_purchase pub package.

This is the setup to initialize the purchase:

   Future<bool> initiatePurchase() async {
       ...
       (verify store is available)
       ..
    print ("==> Store available, initiating purchase");

    final PurchaseParam purchaseParam =
        PurchaseParam(productDetails: _productDetails![0]);

    await InAppPurchase.instance.buyNonConsumable(purchaseParam: purchaseParam);

    return true;
  }

Here's my verify purchase call:

  Future<bool> _verifyPurchase(PurchaseDetails purchaseDetails) async {
    PurchaseVerifRest purchaseRest = PurchaseVerifRest();
    Map<String,dynamic> rsp = await purchaseRest.verifyPurchase(
      {
        "source": purchaseDetails.verificationData.source,
        "vfdata": purchaseDetails.verificationData.serverVerificationData
      });
    // bundle up the source and verificationData in a map and send to rest
    // call

      
    return rsp['status'] == 200;
  }

On the server side, the code looks like this (NodeJS/express app)

  // (in router.post() call - 'purchaseData' is the map sent in the above code,
  //                           the 'vfdata' member is the 'serverVerificationData'
  //.                          in the 'purchaseDetails' object)

  if (purchaseData.source == ('app_store')) {
    const IOS_SHARED_SECRET = process.env...;
    let postData = {
      'receipt-data': purchaseData['vfdata'],
      'password': IOS_SHARED_SECRET
    };

    try {
      let verif_rsp = await execPost(postData);
      retStatus = verif_rsp.statusCode;
      msg = verif_rsp.data;
    } catch (e) {
      retStatus = e.statusCode;
    }
  }

What I get back, invariably is

  210003 - Receipt could not be authenticated

... even though the purchase seems to go through, whether I validate or not.

Details/questions:

  • Testing with a sandbox account.
  • This is for a 'non-consumable' product purchase.
  • I'm assuming that purchaseDetails.verificationData.serverVerificationData is the payload containing the receipt to send to Apple for verification. Is this not correct? Is there another step I need to do to get the receipt data?
  • I've read in other posts that the verification step is only for recurring subscriptions and not for other types of products. Is this correct? I don't see anything in Apple's docs to indicate this.

Any thoughts appreciated.

rickb
  • 601
  • 5
  • 19
  • Update - in the original post I realized I didn't preface the 'InAppPurchase.instance.buyNonConsumable()' call with an 'await'. I've updated that in the app and here and tried again - no changes, seems to work pretty much the same way. – rickb Oct 15 '22 at 21:23
  • Not getting any input. I guess what I'll do is ignore the verification step on IOS for non-consumable purchases and move on. See what android does... – rickb Oct 24 '22 at 18:10

0 Answers0