diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ae4d0b..1e65ecc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.0.0-beta.10 +Feature +* Adds 'offerPrice' to return Introductory price for Apple + ## 1.0.0-beta.9 Chore * Include latest chargebee-android with upgraded blilling client lib to v7.1.1 diff --git a/README.md b/README.md index 90cd353..382bd80 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ To use Chargebee SDK in your Flutter app, follow these steps: ``` dart dependencies: - chargebee_flutter: ^1.0.0-beta.9 + chargebee_flutter: ^1.0.0-beta.10 ``` 2. Install dependency. diff --git a/android/build.gradle b/android/build.gradle index e46721a..89b5146 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,5 +1,5 @@ group 'com.chargebee.flutter.sdk' -version '1.0.0-beta.9' +version '1.0.0-beta.10' buildscript { ext.kotlin_version = '1.6.0' diff --git a/ios/Classes/SwiftChargebeeFlutterSdkPlugin.swift b/ios/Classes/SwiftChargebeeFlutterSdkPlugin.swift index 581fccf..aca09dc 100644 --- a/ios/Classes/SwiftChargebeeFlutterSdkPlugin.swift +++ b/ios/Classes/SwiftChargebeeFlutterSdkPlugin.swift @@ -395,16 +395,39 @@ extension Encodable { extension SKProduct { func toMap() -> [String: Any?] { - let map: [String: Any?] = [ + var map: [String: Any?] = [ "productId": productIdentifier, "productPrice": price.doubleValue, "productPriceString": price.description, "productTitle": localizedTitle, "currencyCode": priceLocale.currencyCode, - "subscriptionPeriod": subscriptionPeriod() + "subscriptionPeriod": subscriptionPeriod(), ] + if let introPrice = self.introductoryPrice { + map["offer"] = offerPrice(introPrice) + } return map } + + func offerPrice(_ discount: SKProductDiscount) -> [String:Any?] { + let map: [String: Any?] = [ + "id": discountIdentifier(discount), + "price": discount.price.doubleValue, + "priceString": discount.price.description, + "period": [ "periodUnit": periodUnit(discount.subscriptionPeriod.unit), + "numberOfUnits": discount.numberOfPeriods + ] + ] + return map + } + + func discountIdentifier(_ discount: SKProductDiscount) -> String { + if #available(iOS 12.2, *) { + return discount.identifier ?? "" + } + return "" + } + func subscriptionPeriod() -> [String:Any?] { let period:String = periodUnit() let subscriptionPeriod: [String: Any?] = [ @@ -423,4 +446,14 @@ extension SKProduct { case .none, .some(_): return "" } } + + func periodUnit(_ period: SKProduct.PeriodUnit) -> String { + switch period { + case .day: return "day" + case .week: return "week" + case .month: return "month" + case .year: return "year" + default: return "" + } + } } diff --git a/ios/chargebee_flutter.podspec b/ios/chargebee_flutter.podspec index 272410a..3ba2db1 100644 --- a/ios/chargebee_flutter.podspec +++ b/ios/chargebee_flutter.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = 'chargebee_flutter' - s.version = '1.0.0-beta.9' + s.version = '1.0.0-beta.10' s.summary = 'This is the official Software Development Kit (SDK) for Chargebee Flutter.' s.description = <<-DESC A new Flutter plugin. diff --git a/lib/src/models/product.dart b/lib/src/models/product.dart index d57d2bf..3d0aac5 100644 --- a/lib/src/models/product.dart +++ b/lib/src/models/product.dart @@ -8,7 +8,7 @@ class Product { /// For Android, returns the basePlanId late String? baseProductId; - /// For Android, returns the Offer details if present + /// For Android and iOS, returns the Offer details if present late Offer? offer; /// For Android, returns the offerToken @@ -29,9 +29,10 @@ class Product { /// Subscription period, which consists of unit and number of units late SubscriptionPeriod subscriptionPeriod; + Product(this.id, this.baseProductId, this.offer, this.offerToken, this.price, this.priceString, this.title, this.currencyCode, this.subscriptionPeriod); - + /// convert json data into Product model factory Product.fromJson(Map json) { debugPrint('json: $json'); @@ -51,7 +52,7 @@ class Product { json['productPriceString'] as String, json['productTitle'] as String, json['currencyCode'] as String, - subscriptionPeriod, + subscriptionPeriod ); } diff --git a/pubspec.yaml b/pubspec.yaml index 5b43c3d..058f73c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: chargebee_flutter description: This is the official Software Development Kit (SDK) for Chargebee Flutter. -version: 1.0.0-beta.9 +version: 1.0.0-beta.10 homepage: 'https://chargebee.com' repository: 'https://github.com/chargebee/chargebee-flutter'