Я пытаюсь заставить игровую площадку OAuth2 вернуть квитанцию о покупке, сделанной в нашем приложении флаттера, однако мне не удалось заставить ее работать.
У меня есть вся необходимая информация
ProjectID = com.myorg.myapp
ProductID = myapp.funds.five
PurchaseToken = TokenValueGoesHere
Разрешаю, дохожу до пункта "Настроить запрос к API", заполняю соответствующий url
https://androidpublisher.googleapis.com/androidpublisher/v3/applications/[ProjectID]/purchases/products/[ProductID]/tokens/[PurchaseToken]
однако игровая площадка возвращается с
HTTP/1.1 403 Forbidden
Content-length: 423
X-xss-protection: 0
X-content-type-options: nosniff
Transfer-encoding: chunked
Vary: Origin, X-Origin, Referer
Server: ESF
-content-encoding: gzip
Cache-control: private
Date: Thu, 26 Jan 2023 12:52:26 GMT
X-frame-options: SAMEORIGIN
Alt-svc: h3 = ":443"; ma=2592000,h3-29 = ":443"; ma=2592000
Content-type: application/json; charset=UTF-8
{
"error": {
"message": "The project id used to call the Google Play Developer API has not been linked in the Google Play Developer Console.",
"code": 403,
"errors": [
{
"reason": "projectNotLinked",
"message": "The project id used to call the Google Play Developer API has not been linked in the Google Play Developer Console.",
"domain": "androidpublisher"
}
]
}
}
Мы проверяем дважды и трижды, чтобы убедиться, что API связан. Я создал новые продукты после связывания, потому что видел, как это делают другие. Мы считаем, что учетная запись службы имеет правильные разрешения.
Что мне не хватает и как это исправить, чтобы я мог проверить получение покупки?
Итак, проект БЫЛ связан должным образом, и ошибка была в лучшем случае расплывчатой в отношении того, в чем заключалась реальная проблема, поскольку учетных данных OAUTH, которые я предоставлял игровой площадке, было недостаточно для извлечения информации.
В итоге я решил проблему в коде.
@GetMapping("/verifyPurchase/app/appName = {appName}&productId = {productId}&purchaseToken = {purchaseToken}")
public boolean isPurchaseSuccessful(@PathVariable(value = "appName") String appName,
@PathVariable(value = "productId") String productId,
@PathVariable(value = "purchaseToken") String purchaseToken) throws GeneralSecurityException, IOException {
// Build service account credentials, important to include the scope which you can get from googles documentation
GoogleCredentials serviceAccountCredentials =
ServiceAccountCredentials.fromStream(new FileInputStream("src/main/resources/auth.json")) // Service Account Credentials json file from Google cloud
.createScoped(Collections.singleton("https://www.googleapis.com/auth/androidpublisher"));
// Android publisher object, slightly older version but does operate as of 2023-Jan-26
AndroidPublisher androidPublisher = new AndroidPublisher.Builder(
GoogleNetHttpTransport.newTrustedTransport(),
JacksonFactory.getDefaultInstance(),
new HttpCredentialsAdapter(serviceAccountCredentials)
).setApplicationName(appName).build(); // Give it the application to build the publisher for.
// At this point we're authorized. We can pull down the receipt from the API, and provide the publisher
// with the appropriate product information and purchase token that we got when we made the purchase from the
// flutter application side of things.
var receipt = androidPublisher.purchases().products().get(appName, productId, purchaseToken).execute();
// return if the purchase was successful, may need error handling here testing to come.
return PURCHASED.equals(receipt.getPurchaseState());
}