From e5ad8998416236fb348c89dd225fef97a5fe66a8 Mon Sep 17 00:00:00 2001 From: Haripriyan Date: Mon, 24 Nov 2025 19:13:25 +0530 Subject: [PATCH 1/3] Adds 'offerPrice' ofr returning the introductoryOffer price for Apple --- ios/Classes/SwiftChargebeeFlutterSdkPlugin.swift | 3 ++- lib/src/models/product.dart | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ios/Classes/SwiftChargebeeFlutterSdkPlugin.swift b/ios/Classes/SwiftChargebeeFlutterSdkPlugin.swift index 581fccf..c6600f0 100644 --- a/ios/Classes/SwiftChargebeeFlutterSdkPlugin.swift +++ b/ios/Classes/SwiftChargebeeFlutterSdkPlugin.swift @@ -401,7 +401,8 @@ extension SKProduct { "productPriceString": price.description, "productTitle": localizedTitle, "currencyCode": priceLocale.currencyCode, - "subscriptionPeriod": subscriptionPeriod() + "subscriptionPeriod": subscriptionPeriod(), + "offerPrice": self.introductoryPrice?.price.doubleValue, ] return map } diff --git a/lib/src/models/product.dart b/lib/src/models/product.dart index d57d2bf..090ed34 100644 --- a/lib/src/models/product.dart +++ b/lib/src/models/product.dart @@ -29,8 +29,11 @@ class Product { /// Subscription period, which consists of unit and number of units late SubscriptionPeriod subscriptionPeriod; + /// Discounted Price + late num? discountedPrice; + Product(this.id, this.baseProductId, this.offer, this.offerToken, this.price, this.priceString, this.title, this.currencyCode, - this.subscriptionPeriod); + this.subscriptionPeriod, this.discountedPrice); /// convert json data into Product model factory Product.fromJson(Map json) { @@ -52,6 +55,7 @@ class Product { json['productTitle'] as String, json['currencyCode'] as String, subscriptionPeriod, + json['offerPrice'] as num?, ); } From c8950034d502ae26dddb31cbc04b16997bf5a091 Mon Sep 17 00:00:00 2001 From: Haripriyan Date: Mon, 24 Nov 2025 19:18:10 +0530 Subject: [PATCH 2/3] Increments version --- CHANGELOG.md | 4 ++++ README.md | 2 +- android/build.gradle | 2 +- ios/chargebee_flutter.podspec | 2 +- pubspec.yaml | 2 +- 5 files changed, 8 insertions(+), 4 deletions(-) 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/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/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' From 4606811c1de706c0d66c2ff855ccc4ffa03ddd42 Mon Sep 17 00:00:00 2001 From: Haripriyan Date: Mon, 24 Nov 2025 20:13:48 +0530 Subject: [PATCH 3/3] Populates offer for Apple products with introductory prices --- .../SwiftChargebeeFlutterSdkPlugin.swift | 36 +++++++++++++++++-- lib/src/models/product.dart | 11 +++--- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/ios/Classes/SwiftChargebeeFlutterSdkPlugin.swift b/ios/Classes/SwiftChargebeeFlutterSdkPlugin.swift index c6600f0..aca09dc 100644 --- a/ios/Classes/SwiftChargebeeFlutterSdkPlugin.swift +++ b/ios/Classes/SwiftChargebeeFlutterSdkPlugin.swift @@ -395,17 +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(), - "offerPrice": self.introductoryPrice?.price.doubleValue, ] + 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?] = [ @@ -424,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/lib/src/models/product.dart b/lib/src/models/product.dart index 090ed34..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,12 +29,10 @@ class Product { /// Subscription period, which consists of unit and number of units late SubscriptionPeriod subscriptionPeriod; - /// Discounted Price - late num? discountedPrice; Product(this.id, this.baseProductId, this.offer, this.offerToken, this.price, this.priceString, this.title, this.currencyCode, - this.subscriptionPeriod, this.discountedPrice); - + this.subscriptionPeriod); + /// convert json data into Product model factory Product.fromJson(Map json) { debugPrint('json: $json'); @@ -54,8 +52,7 @@ class Product { json['productPriceString'] as String, json['productTitle'] as String, json['currencyCode'] as String, - subscriptionPeriod, - json['offerPrice'] as num?, + subscriptionPeriod ); }