Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add customer as a parameter in restorePurchase for beta #84

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
## 1.0.0-beta.2
Fix
* Add customer as a parameter in restorePurchase for beta SDK

## 1.0.0-beta.1
* Handles Android Billing library 5 changes to handle base plan and offer tokens

## 0.4.2
Fix
* Add customer as a parameter in restorePurchase

## 0.4.1
Fix
* Fixes multiple callback

## 0.4.0
Chore
* Updates Android Billing library version from 4.x to 5.2.1
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ To use Chargebee SDK in your Flutter app, follow these steps:

``` dart
dependencies:
chargebee_flutter: ^1.0.0-beta.1
chargebee_flutter: ^1.0.0-beta.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 '1.0.0-beta.1'
version '1.0.0-beta.2'

buildscript {
ext.kotlin_version = '1.6.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,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 @@ -150,10 +151,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 = '1.0.0-beta.1'
s.version = '1.0.0-beta.2'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the SDK version to 1.0.28?

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 @@ -291,11 +291,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: 1.0.0-beta.1
version: 1.0.0-beta.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 @@ -705,11 +705,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 @@ -721,11 +734,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
Loading