Skip to content
Open
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
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ Initialize the Chargebee Flutter SDK with your Chargebee site, Publishable API K
```dart
import 'package:chargebee_flutter/chargebee_flutter.dart';
try {
await Chargebee.configure("SITE_NAME", "API-KEY", "iOS SDK Key", "Android SDK Key");
await Chargebee.configure(
site: "SITE_NAME",
publishableApiKey: "API_KEY",
iosSdkKey: "iOS_SDK_Key",
androidSdkKey: "Android_SDK_Key",
);
} on PlatformException catch (e) {
print('${e.message}, ${e.details}');
}
Expand Down
7 changes: 6 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,12 @@ class _MyHomePageState extends State<MyHomePage> {
Future<void> authentication(String siteName, String apiKey, [String? iosSdkKey="",
String? androidSdkKey = ""]) async {
try {
await Chargebee.configure(siteName, apiKey, iosSdkKey, androidSdkKey);
await Chargebee.configure(
site: siteName,
publishableApiKey: apiKey,
androidSdkKey: androidSdkKey,
iosSdkKey: iosSdkKey,
);
} on PlatformException catch (e) {
print('${e.message}, ${e.details}');
}
Expand Down
2 changes: 1 addition & 1 deletion example/lib/product_listview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ProductListViewState extends State<ProductListView> {
color: Colors.black54,
fontWeight: FontWeight.bold,
fontSize: 18)),
subtitle: Text(listProducts[pos].price,
subtitle: Text(listProducts[pos].price + " (currencyCode: "+ listProducts[pos].currencyCode + ")",
style: const TextStyle(
fontWeight: FontWeight.normal,
fontSize: 15)),
Expand Down
10 changes: 8 additions & 2 deletions lib/src/chargebee.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@ import 'package:flutter/services.dart';
import 'dart:convert';

class Chargebee {
Chargebee._();

static const platform = MethodChannel(Constants.methodChannelName);
static bool get _isIOS => defaultTargetPlatform == TargetPlatform.iOS;

/* Configure the app details with chargebee system */
static Future<void> configure(String site, String publishableApiKey,
[String? iosSdkKey = "", androidSdkKey = ""]) async {
static Future<void> configure({
required String site,
required String publishableApiKey,
String? iosSdkKey = "",
String? androidSdkKey = "",
}) async {
if (_isIOS) {
final args = {
Constants.siteName: site,
Expand Down
16 changes: 14 additions & 2 deletions lib/src/utils/product.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ class Product {
String id;
String price;
String title;
Product(this.id, this.price, this.title);
String currencyCode;

Product(this.id, this.price, this.title, this.currencyCode);

factory Product.fromJson(dynamic json) {
print(json);

return Product(json['productId'] as String, json['productPrice'] as String,
json['productTitle'] as String);
json['productTitle'] as String, json['currencyCode'] as String);
}

@override
String toString() {
return 'Product(id: $id, price: $price, title: $title, currencyCode: $currencyCode)';
}
}

Expand All @@ -22,6 +29,11 @@ class PurchaseResult {
factory PurchaseResult.fromJson(dynamic json) {
return PurchaseResult(json['subscriptionId'] as String, json['planId'] as String, json['status'] as String);
}

@override
String toString() {
return 'PurchaseResult(subscriptionId: $subscriptionId, planId: $planId, $status)';
}
}

class Subscripton {
Expand Down
19 changes: 16 additions & 3 deletions test/chargebee_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ void main() {
test('works for iOS', () async {
channelResponse = true;
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
await Chargebee.configure(siteName, apiKey, iosSDKKey);
await Chargebee.configure(
site: siteName,
publishableApiKey: apiKey,
iosSdkKey: iosSDKKey,
);
expect(callStack, <Matcher>[
isMethodCall(
Constants.mAuthentication,
Expand All @@ -50,7 +54,11 @@ void main() {
test('works for android', () async {
channelResponse = true;
debugDefaultTargetPlatformOverride = TargetPlatform.android;
await Chargebee.configure(siteName, apiKey, "", androidSDKKey);
await Chargebee.configure(
site: siteName,
publishableApiKey: apiKey,
androidSdkKey: androidSDKKey,
);
expect(callStack, <Matcher>[
isMethodCall(
Constants.mAuthentication,
Expand All @@ -68,7 +76,12 @@ void main() {
throw PlatformException(code: "Dummy");
});
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
await expectLater(() => Chargebee.configure(siteName, apiKey, iosSDKKey),
await expectLater(
() => Chargebee.configure(
site: siteName,
publishableApiKey: apiKey,
iosSdkKey: iosSDKKey,
),
throwsA(isA<PlatformException>()));
channel.setMockMethodCallHandler(null);
});
Expand Down