Skip to content

Commit

Permalink
Merge 8754743 into 3fbf03a
Browse files Browse the repository at this point in the history
  • Loading branch information
mgonzalezc committed Sep 28, 2020
2 parents 3fbf03a + 8754743 commit aca5152
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ios/Classes/FlutterInappPurchasePlugin.m
Expand Up @@ -91,7 +91,7 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
NSString* result = [self convertDicToJsonString:err];
[self.channel invokeMethod:@"purchase-error" arguments:result];
}
} else if ([@"requestProductWithOffer" isEqualToString:call.method]) {
} else if ([@"requestProductWithOfferIOS" isEqualToString:call.method]) {
NSString* sku = (NSString*)call.arguments[@"sku"];
NSDictionary* discountOffer = (NSDictionary*)call.arguments[@"withOffer"];
NSString* usernameHash = (NSString*)call.arguments[@"forUser"];
Expand Down
2 changes: 1 addition & 1 deletion lib/flutter_inapp_purchase.dart
Expand Up @@ -305,7 +305,7 @@ class FlutterInappPurchase {
///
/// @returns {Future} will receive result from `purchaseUpdated` listener.
Future requestProductWithOfferIOS(
String sku, String forUser, String withOffer,
String sku, String forUser, Map<String, dynamic> withOffer,
) async {
if (_platform.isIOS) {
return await _channel.invokeMethod('requestProductWithOfferIOS', <String, dynamic>{
Expand Down
67 changes: 66 additions & 1 deletion lib/modules.dart
Expand Up @@ -27,6 +27,7 @@ class IAPItem {
final String introductoryPricePaymentModeIOS;
final String introductoryPriceNumberOfPeriodsIOS;
final String introductoryPriceSubscriptionPeriodIOS;
final List<DiscountIOS> discountsIOS;

/// android only
final String subscriptionPeriodAndroid;
Expand Down Expand Up @@ -66,7 +67,8 @@ class IAPItem {
signatureAndroid = json['signatureAndroid'] as String,
iconUrl = json['iconUrl'] as String,
originalJson = json['originalJson'] as String,
originalPrice = json['originalJson'] as String;
originalPrice = json['originalJson'] as String,
discountsIOS = _extractDiscountIOS(json['discounts']);

/// wow, i find if i want to save a IAPItem, there is not "toJson" to cast it into String...
/// i'm sorry to see that... so,
Expand Down Expand Up @@ -102,6 +104,7 @@ class IAPItem {
data['iconUrl'] = this.iconUrl;
data['originalJson'] = this.originalJson;
data['originalPrice'] = this.originalPrice;
data['discounts'] = this.discountsIOS;
return data;
}

Expand All @@ -128,6 +131,68 @@ class IAPItem {
'iconUrl: $iconUrl, '
'originalJson: $originalJson, '
'originalPrice: $originalPrice, '
'discounts: $discountsIOS, '
;
}

static List<DiscountIOS> _extractDiscountIOS(dynamic json) {
List list = json as List;
List<DiscountIOS> discounts;

if (list != null) {
discounts = list
.map<DiscountIOS>(
(dynamic discount) => DiscountIOS.fromJSON(discount as Map<String, dynamic>),
)
.toList();
}


return discounts;
}
}

class DiscountIOS {
String identifier;
String type;
String numberOfPeriods;
double price;
String localizedPrice;
String paymentMode;
String subscriptionPeriod;

/// Create [DiscountIOS] from a Map that was previously JSON formatted
DiscountIOS.fromJSON(Map<String, dynamic> json)
: identifier = json['identifier'] as String,
type = json['type'] as String,
numberOfPeriods = json['numberOfPeriods'] as String,
price = json['price'] as double,
localizedPrice = json['localizedPrice'] as String,
paymentMode = json['paymentMode'] as String,
subscriptionPeriod = json['subscriptionPeriod'] as String;

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['identifier'] = this.identifier;
data['type'] = this.type;
data['numberOfPeriods'] = this.numberOfPeriods;
data['price'] = this.price;
data['localizedPrice'] = this.localizedPrice;
data['paymentMode'] = this.paymentMode;
data['subscriptionPeriod'] = this.subscriptionPeriod;
return data;
}

/// Return the contents of this class as a string
@override
String toString() {
return 'identifier: $identifier, '
'type: $type, '
'numberOfPeriods: $numberOfPeriods, '
'price: $price, '
'localizedPrice: $localizedPrice, '
'paymentMode: $paymentMode, '
'subscriptionPeriod: $subscriptionPeriod, '
;
}
}
Expand Down

0 comments on commit aca5152

Please sign in to comment.