The androidPublisher subscription APIs (for example the cancel subscription api) always throw a 400 error when I pass the purchaseId after a successful purchase in place of the token parameter. The purchaseId is a field in the PurchaseDetails class in the in_app_purchase package in Flutter. The error looks like this:

  "error": {
    "code": 400,
    "message": "Invalid Value",
    "errors": [
      {
        "message": "Invalid Value",
        "domain": "global",
        "reason": "invalid"
      }
    ]
  }
}

After going through various other questions, it seems that the error is in the purchaseId field. It seems it is not the token that is specific to a subscription purchase. What should be used instead of this?

1

There are 1 answers

0
Aknk On BEST ANSWER

The reason for getting the 400 error is because, the purchaseId field is not referring the purchaseToken as stated by the API (though not quite clear). This becomes clear on referring to the Purchase class in native Android In app billing.

The purchaseId field refers to the orderId field of the Purchase class(which is not what the androidPublisher API uses). In order to refer to the purchaseToken field of Android's Purchase class in Flutter, use the following field data: PurchaseDetails.verificationData.serverVerificationData