From 8bf5e35c09f5a5bd287b42a14c0ee1348ba73d33 Mon Sep 17 00:00:00 2001 From: cb-pravin Date: Thu, 21 Dec 2023 16:19:56 +0530 Subject: [PATCH 1/4] add test customer --- .../flutter/sdk/ChargebeeFlutterSdkPlugin.kt | 16 ++++++++++++---- example/lib/main.dart | 8 +++++++- .../SwiftChargebeeFlutterSdkPlugin.swift | 17 ++++++++++++++--- ios/chargebee_flutter.podspec | 2 +- lib/src/chargebee.dart | 10 +++++++++- 5 files changed, 43 insertions(+), 10 deletions(-) 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..57825e8 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( + '', + '', + '', + '', + ); + 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..4f5725f 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 includeInActiveProducts: 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: includeInActiveProducts, 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..2059b6d 100644 --- a/ios/chargebee_flutter.podspec +++ b/ios/chargebee_flutter.podspec @@ -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) { From 38d3c36ded1c6a59e7562fb26e24d60eedd6ce78 Mon Sep 17 00:00:00 2001 From: cb-pravin Date: Thu, 21 Dec 2023 17:18:32 +0530 Subject: [PATCH 2/4] add test case for customer in restore purchase --- CHANGELOG.md | 4 ++++ README.md | 2 +- android/build.gradle | 2 +- ios/chargebee_flutter.podspec | 2 +- pubspec.yaml | 2 +- test/chargebee_test.dart | 34 ++++++++++++++++++++++++++++++---- 6 files changed, 38 insertions(+), 8 deletions(-) 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 56fa82d..1d3e68b 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/ios/chargebee_flutter.podspec b/ios/chargebee_flutter.podspec index 2059b6d..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. 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); From e2a83f770cecdc0043fb453a0a705ef627c5610f Mon Sep 17 00:00:00 2001 From: cb-pravin Date: Thu, 21 Dec 2023 17:19:55 +0530 Subject: [PATCH 3/4] refactor includeInActiveProducts name --- ios/Classes/SwiftChargebeeFlutterSdkPlugin.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ios/Classes/SwiftChargebeeFlutterSdkPlugin.swift b/ios/Classes/SwiftChargebeeFlutterSdkPlugin.swift index 4f5725f..97423c1 100644 --- a/ios/Classes/SwiftChargebeeFlutterSdkPlugin.swift +++ b/ios/Classes/SwiftChargebeeFlutterSdkPlugin.swift @@ -253,7 +253,7 @@ public class SwiftChargebeeFlutterSdkPlugin: NSObject, FlutterPlugin { return _result(FlutterError.noArgsError) } - let includeInActiveProducts: Bool = params["includeInactivePurchases"] as? Bool ?? false + let includeInactivePurchases: Bool = params["includeInactivePurchases"] as? Bool ?? false let customer: CBCustomer = CBCustomer( customerID: params["customerId"] as? String, @@ -262,7 +262,7 @@ public class SwiftChargebeeFlutterSdkPlugin: NSObject, FlutterPlugin { email:params["email"] as? String ) - CBPurchase.shared.restorePurchases(includeInActiveProducts: includeInActiveProducts, customer: customer) { result in + CBPurchase.shared.restorePurchases(includeInActiveProducts: includeInactivePurchases, customer: customer) { result in switch result { case .success(let response): var array = [String]() From 6edbe58591479a1cb66482cca9cfaacb7702ec21 Mon Sep 17 00:00:00 2001 From: cb-pravin Date: Thu, 21 Dec 2023 18:00:56 +0530 Subject: [PATCH 4/4] update test customer value --- example/lib/main.dart | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 57825e8..026a789 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -409,10 +409,10 @@ class _MyHomePageState extends State { Future restorePurchases() async { try { final customer = CBCustomer( - '', - '', - '', - '', + 'Test123', + 'CB', + 'Test', + 'cbTest@chargebee.com', ); final result = await Chargebee.restorePurchases(true, customer); if (mProgressBarUtil.isProgressBarShowing()) {