completePurchase method
Mark that purchased content has been delivered to the user.
You are responsible for completing every PurchaseDetails
whose
PurchaseDetails.status
is PurchaseStatus.purchased
or
PurchaseStatus.restored
.
Completing a PurchaseStatus.pending
purchase will cause an exception.
For convenience, PurchaseDetails.pendingCompletePurchase
indicates if a
purchase is pending for completion.
The method will throw a PurchaseException
when the purchase could not be
finished. Depending on the PurchaseException.errorCode
the developer
should try to complete the purchase via this method again, or retry the
completePurchase method at a later time. If the
PurchaseException.errorCode
indicates you should not retry there might
be some issue with the app's code or the configuration of the app in the
respective store. The developer is responsible to fix this issue. The
PurchaseException.message
field might provide more information on what
went wrong.
Implementation
@override
Future<BillingResultWrapper> completePurchase(
PurchaseDetails purchase) async {
assert(
purchase is GooglePlayPurchaseDetails,
'On Android, the `purchase` should always be of type `GooglePlayPurchaseDetails`.',
);
final GooglePlayPurchaseDetails googlePurchase =
purchase as GooglePlayPurchaseDetails;
if (googlePurchase.billingClientPurchase.isAcknowledged) {
return const BillingResultWrapper(responseCode: BillingResponse.ok);
}
return billingClientManager.runWithClient(
(BillingClient client) => client.acknowledgePurchase(
purchase.verificationData.serverVerificationData),
);
}