Skip to content

Commit

Permalink
Merge branch 'main' into added_namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
ciriousjoker committed Jan 26, 2024
2 parents 5cfcfa8 + c04b3a1 commit 38ea843
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.4.2
Fix
* Add customer as a parameter in restorePurchase

## 0.4.1
Fix
* Fixes multiple callback
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'com.chargebee.flutter.sdk'
version '0.4.1'
version '0.4.2'

buildscript {
ext.kotlin_version = '1.6.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ class ChargebeeFlutterSdkPlugin : FlutterPlugin, MethodCallHandler, ActivityAwar
}
}
"restorePurchases" -> {
val params = call.arguments() as? Map<String, Boolean>?
restorePurchases(result, params)
if (args != null) {
restorePurchases(args, result)
}
}
"validateReceipt" -> {
if (args != null) {
Expand Down Expand Up @@ -161,10 +162,17 @@ class ChargebeeFlutterSdkPlugin : FlutterPlugin, MethodCallHandler, ActivityAwar
})
}

private fun restorePurchases(resultCallback: Result, queryParams: Map<String, Boolean>?) {
val includeInactivePurchases = queryParams?.get("includeInactivePurchases") as Boolean
private fun restorePurchases(args: Map<String, Any>, 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<CBRestoreSubscription>) {
Expand Down
8 changes: 7 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,13 @@ class _MyHomePageState extends State<MyHomePage> {

Future<void> restorePurchases() async {
try {
final result = await Chargebee.restorePurchases(true);
final customer = CBCustomer(
'Test123',
'CB',
'Test',
'[email protected]',
);
final result = await Chargebee.restorePurchases(true, customer);
if (mProgressBarUtil.isProgressBarShowing()) {
mProgressBarUtil.hideProgressDialog();
}
Expand Down
17 changes: 14 additions & 3 deletions ios/Classes/SwiftChargebeeFlutterSdkPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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]()
Expand Down
4 changes: 2 additions & 2 deletions ios/chargebee_flutter.podspec
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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' }
Expand Down
10 changes: 9 additions & 1 deletion lib/src/chargebee.dart
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,19 @@ class Chargebee {
/// Throws an [PlatformException] in case of failure.
static Future<List<CBRestoreSubscription>> restorePurchases([
bool includeInactivePurchases = false,
CBCustomer? customer,
]) async {
final restorePurchases = <CBRestoreSubscription>[];
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) {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
34 changes: 30 additions & 4 deletions test/chargebee_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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',
'[email protected]',
);
final result = await Chargebee.restorePurchases(true, customer);
final expectedArguments = {
Constants.customerId: 'test-user',
Constants.firstName: 'test',
Constants.lastName: 'user',
Constants.email: '[email protected]',
Constants.includeInactivePurchases: true,
};
expect(callStack, <Matcher>[
isMethodCall(
Constants.mRestorePurchase,
arguments: {Constants.includeInactivePurchases: true},
arguments: expectedArguments,
)
]);
expect(result.isNotEmpty, true);
Expand All @@ -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',
'[email protected]',
);
final expectedArguments = {
Constants.customerId: 'test-user',
Constants.firstName: 'test',
Constants.lastName: 'user',
Constants.email: '[email protected]',
Constants.includeInactivePurchases: true,
};
final result = await Chargebee.restorePurchases(true, customer);
expect(callStack, <Matcher>[
isMethodCall(
Constants.mRestorePurchase,
arguments: {Constants.includeInactivePurchases: true},
arguments: expectedArguments,
)
]);
expect(result.isNotEmpty, true);
Expand Down

0 comments on commit 38ea843

Please sign in to comment.