RequestPurchaseProps.fromJson constructor
RequestPurchaseProps.fromJson(
- Map<String, dynamic> json
)
Implementation
factory RequestPurchaseProps.fromJson(Map<String, dynamic> json) {
final typeValue = json['type'] as String?;
final parsedType = typeValue != null ? ProductQueryType.fromJson(typeValue) : null;
final purchaseJson = json['requestPurchase'] as Map<String, dynamic>?;
if (purchaseJson != null) {
final request = RequestPurchasePropsRequestPurchase(RequestPurchasePropsByPlatforms.fromJson(purchaseJson));
final finalType = parsedType ?? ProductQueryType.InApp;
if (finalType != ProductQueryType.InApp) {
throw ArgumentError('type must be IN_APP when requestPurchase is provided');
}
return RequestPurchaseProps(request: request, type: finalType);
}
final subscriptionJson = json['requestSubscription'] as Map<String, dynamic>?;
if (subscriptionJson != null) {
final request = RequestPurchasePropsRequestSubscription(RequestSubscriptionPropsByPlatforms.fromJson(subscriptionJson));
final finalType = parsedType ?? ProductQueryType.Subs;
if (finalType != ProductQueryType.Subs) {
throw ArgumentError('type must be SUBS when requestSubscription is provided');
}
return RequestPurchaseProps(request: request, type: finalType);
}
throw ArgumentError('RequestPurchaseProps requires requestPurchase or requestSubscription');
}