getPurchaseList method
Future<List<ProductDetails?> ?>
getPurchaseList(
- List<
String> purchase_ids, - String purchase_type,
- PurchaseListener? listener
override
Implementation
@override
Future<List<ProductDetails?>?> getPurchaseList(List<String> purchase_ids,
String purchase_type, PurchaseListener? listener) async {
this.listener = listener;
final List<PurchaseId> pricingList = [];
purchase_ids.forEach((element) {
pricingList
.add(PurchaseId(purchaseId: element, purchaseType: purchase_type));
});
final price = await methodChannel.invokeMethod<String?>(
'getPurchaseList', {"purchases": purchaseIdToJson(pricingList)});
if ((price ?? "").isEmpty) {
return List.empty();
}
final List<ProductDetails> retrievePricingList = [];
productDetailsResponseFromJson(price!).forEach((element) {
if ((element.zza ?? "").isNotEmpty) {
retrievePricingList.add(productDetailsFromJson(element.zza!));
}
});
retrievePricingList.sort((a, b) {
int aAmount = 0;
int bAmount = 0;
if (a.subscriptionOfferDetails.isNotEmpty) {
if (a.subscriptionOfferDetails[0]?.pricingPhases.isNotEmpty == true) {
aAmount = a.subscriptionOfferDetails[0]?.pricingPhases[0]?.priceAmountMicros ?? aAmount;
}
}
if (b.subscriptionOfferDetails.isNotEmpty) {
if (b.subscriptionOfferDetails[0]?.pricingPhases.isNotEmpty == true) {
bAmount = b.subscriptionOfferDetails[0]?.pricingPhases[0]?.priceAmountMicros ?? bAmount;
}
}
return aAmount.compareTo(bAmount);
},);
return retrievePricingList;
}