diff --git a/CHANGELOG.md b/CHANGELOG.md index d08f359..8347018 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.4.2 +Fix +* Add customer as a parameter in restorePurchase + ## 0.4.1 Fix * Fixes multiple callback diff --git a/README.md b/README.md index 94517e5..e06bc43 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ To use Chargebee SDK in your Flutter app, follow these steps: ``` dart dependencies: - chargebee_flutter: ^0.4.1 + chargebee_flutter: ^0.4.2 ``` 2. Install dependency. diff --git a/android/build.gradle b/android/build.gradle index 9b8f988..5ad0548 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,5 +1,5 @@ group 'com.chargebee.flutter.sdk' -version '0.4.1' +version '0.4.2' buildscript { ext.kotlin_version = '1.6.0' diff --git a/android/src/main/kotlin/com/chargebee/flutter/sdk/ChargebeeFlutterSdkPlugin.kt b/android/src/main/kotlin/com/chargebee/flutter/sdk/ChargebeeFlutterSdkPlugin.kt index 676199c..9d00bbc 100644 --- a/android/src/main/kotlin/com/chargebee/flutter/sdk/ChargebeeFlutterSdkPlugin.kt +++ b/android/src/main/kotlin/com/chargebee/flutter/sdk/ChargebeeFlutterSdkPlugin.kt @@ -95,8 +95,9 @@ class ChargebeeFlutterSdkPlugin : FlutterPlugin, MethodCallHandler, ActivityAwar } } "restorePurchases" -> { - val params = call.arguments() as? Map? - restorePurchases(result, params) + if (args != null) { + restorePurchases(args, result) + } } "validateReceipt" -> { if (args != null) { @@ -161,10 +162,17 @@ class ChargebeeFlutterSdkPlugin : FlutterPlugin, MethodCallHandler, ActivityAwar }) } - private fun restorePurchases(resultCallback: Result, queryParams: Map?) { - val includeInactivePurchases = queryParams?.get("includeInactivePurchases") as Boolean + private fun restorePurchases(args: Map, resultCallback: Result) { + val includeInactivePurchases = args["includeInactivePurchases"] as Boolean + val customer = CBCustomer( + args["customerId"] as String, + args["firstName"] as String, + args["lastName"] as String, + args["email"] as String + ) CBPurchase.restorePurchases( context = activity, + customer = customer, includeInActivePurchases = includeInactivePurchases, completionCallback = object : CBCallback.RestorePurchaseCallback { override fun onSuccess(result: List) { diff --git a/example/lib/main.dart b/example/lib/main.dart index 2524a54..026a789 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -408,7 +408,13 @@ class _MyHomePageState extends State { Future restorePurchases() async { try { - final result = await Chargebee.restorePurchases(true); + final customer = CBCustomer( + 'Test123', + 'CB', + 'Test', + 'cbTest@chargebee.com', + ); + final result = await Chargebee.restorePurchases(true, customer); if (mProgressBarUtil.isProgressBarShowing()) { mProgressBarUtil.hideProgressDialog(); } diff --git a/ios/Classes/SwiftChargebeeFlutterSdkPlugin.swift b/ios/Classes/SwiftChargebeeFlutterSdkPlugin.swift index ce336c3..97423c1 100644 --- a/ios/Classes/SwiftChargebeeFlutterSdkPlugin.swift +++ b/ios/Classes/SwiftChargebeeFlutterSdkPlugin.swift @@ -249,9 +249,20 @@ public class SwiftChargebeeFlutterSdkPlugin: NSObject, FlutterPlugin { } } case "restorePurchases": - let params = call.arguments as? [String: Bool] - let includeInactivePurchases = params?["includeInactivePurchases"] ?? false - CBPurchase.shared.restorePurchases(includeInActiveProducts: includeInactivePurchases) { result in + guard let params = call.arguments as? [String: Any?] else { + return _result(FlutterError.noArgsError) + } + + let includeInactivePurchases: Bool = params["includeInactivePurchases"] as? Bool ?? false + + let customer: CBCustomer = CBCustomer( + customerID: params["customerId"] as? String, + firstName:params["firstName"] as? String, + lastName: params["lastName"] as? String, + email:params["email"] as? String + ) + + CBPurchase.shared.restorePurchases(includeInActiveProducts: includeInactivePurchases, customer: customer) { result in switch result { case .success(let response): var array = [String]() diff --git a/ios/chargebee_flutter.podspec b/ios/chargebee_flutter.podspec index af80794..9b0fa7c 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 = '0.4.1' + s.version = '0.4.2' s.summary = 'This is the official Software Development Kit (SDK) for Chargebee Flutter.' s.description = <<-DESC A new Flutter plugin. @@ -14,7 +14,7 @@ A new Flutter plugin. s.dependency 'Flutter' s.platform = :ios, '12.0' - s.dependency 'Chargebee', '1.0.26' + s.dependency 'Chargebee', '1.0.28' # Flutter.framework does not contain a i386 slice. s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' } diff --git a/lib/src/chargebee.dart b/lib/src/chargebee.dart index 350ed67..03964bb 100644 --- a/lib/src/chargebee.dart +++ b/lib/src/chargebee.dart @@ -327,11 +327,19 @@ class Chargebee { /// Throws an [PlatformException] in case of failure. static Future> restorePurchases([ bool includeInactivePurchases = false, + CBCustomer? customer, ]) async { final restorePurchases = []; + final params = { + Constants.customerId: customer?.id ?? '', + Constants.firstName: customer?.firstName ?? '', + Constants.lastName: customer?.lastName ?? '', + Constants.email: customer?.email ?? '', + Constants.includeInactivePurchases: includeInactivePurchases, + }; final List result = await platform.invokeMethod( Constants.mRestorePurchase, - {Constants.includeInactivePurchases: includeInactivePurchases}, + params, ); debugPrint('result $result'); if (result.isNotEmpty) { diff --git a/pubspec.yaml b/pubspec.yaml index dcc6f77..42d48fb 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: 0.4.1 +version: 0.4.2 homepage: 'https://chargebee.com' repository: 'https://github.com/chargebee/chargebee-flutter' diff --git a/test/chargebee_test.dart b/test/chargebee_test.dart index 70250aa..1948993 100644 --- a/test/chargebee_test.dart +++ b/test/chargebee_test.dart @@ -694,11 +694,24 @@ void main() { channelResponse = restorePurchaseResult; debugDefaultTargetPlatformOverride = TargetPlatform.android; try { - final result = await Chargebee.restorePurchases(true); + final customer = CBCustomer( + 'test-user', + 'test', + 'user', + 'test-user@email.com', + ); + final result = await Chargebee.restorePurchases(true, customer); + final expectedArguments = { + Constants.customerId: 'test-user', + Constants.firstName: 'test', + Constants.lastName: 'user', + Constants.email: 'test-user@email.com', + Constants.includeInactivePurchases: true, + }; expect(callStack, [ isMethodCall( Constants.mRestorePurchase, - arguments: {Constants.includeInactivePurchases: true}, + arguments: expectedArguments, ) ]); expect(result.isNotEmpty, true); @@ -710,11 +723,24 @@ void main() { test('returns the list of Restored Subscription for iOS', () async { channelResponse = restorePurchaseResult; debugDefaultTargetPlatformOverride = TargetPlatform.iOS; - final result = await Chargebee.restorePurchases(true); + final customer = CBCustomer( + 'test-user', + 'test', + 'user', + 'test-user@email.com', + ); + final expectedArguments = { + Constants.customerId: 'test-user', + Constants.firstName: 'test', + Constants.lastName: 'user', + Constants.email: 'test-user@email.com', + Constants.includeInactivePurchases: true, + }; + final result = await Chargebee.restorePurchases(true, customer); expect(callStack, [ isMethodCall( Constants.mRestorePurchase, - arguments: {Constants.includeInactivePurchases: true}, + arguments: expectedArguments, ) ]); expect(result.isNotEmpty, true);