purchaseGooglePlay method
Future<LinkFiveActiveProducts>
purchaseGooglePlay(
- GooglePlayPurchaseDetails purchaseDetails,
- GooglePlayProductDetails productDetails
override
after a purchase on Google we call the purchases/google We don't need to do this on Android
Implementation
@override
Future<LinkFiveActiveProducts> purchaseGooglePlay(
GooglePlayPurchaseDetails purchaseDetails, GooglePlayProductDetails productDetails) async {
final uri = _makeUri("api/v1/purchases/user/google");
String? basePlanId;
List<PricingPhase> pricingPhaseList = [];
final subscriptionIndex = productDetails.subscriptionIndex;
final offerDetailList = productDetails.productDetails.subscriptionOfferDetails;
if (subscriptionIndex != null && offerDetailList != null && offerDetailList.isNotEmpty) {
final offerDetail = offerDetailList[subscriptionIndex];
basePlanId = offerDetail.basePlanId;
for (final pricingPhase in offerDetail.pricingPhases) {
pricingPhaseList.add(PricingPhase.fromGooglePlay(pricingPhase));
}
}
final purchaseBody = PurchaseRequestGoogle(
sku: purchaseDetails.productID,
purchaseId: purchaseDetails.billingClientPurchase.orderId,
purchaseToken: purchaseDetails.billingClientPurchase.purchaseToken,
basePlanId: basePlanId,
purchaseRequestPricingPhaseList: [
for (final phase in pricingPhaseList) PurchaseRequestPricingPhase.fromPricingPhase(phase)
]);
LinkFiveLogger.d("purchase: $purchaseBody");
final response =
await httpClient.post(uri, body: purchaseBody.toJson(), headers: await _headers);
return _parseOneTimePurchaseListResponse(response);
}