validateReceiptAndroid method
Validate receipt in android
For Android, you need separate json file from the service account to get the access_token from google-apis, therefore it is impossible to implement serverless. You should have your own backend and get access_token. Read: https://stackoverflow.com/questions/35127086/android-inapp-purchase-receipt-validation-google-play?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
Example:
const result = await validateReceiptAndroid(
packageName: 'com.dooboolab.iap',
productId: 'product_1',
productToken: 'some_token_string',
accessToken: 'play_console_access_token',
isSubscription: false,
);
console.log(result);
Implementation
Future<http.Response> validateReceiptAndroid({
required String packageName,
required String productId,
required String productToken,
required String accessToken,
bool isSubscription = false,
}) async {
final String type = isSubscription ? 'subscriptions' : 'products';
final String url =
'https://www.googleapis.com/androidpublisher/v3/applications/$packageName/purchases/$type/$productId/tokens/$productToken?access_token=$accessToken';
return await _client.get(
Uri.parse(url),
headers: {
'Accept': 'application/json',
},
);
}