-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from cb-amutha/feature/add_customer
Pass customer object to purchaseProduct method
- Loading branch information
Showing
11 changed files
with
194 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
group 'com.chargebee.flutter.sdk' | ||
version '0.1.0' | ||
version '0.2.0' | ||
|
||
buildscript { | ||
ext.kotlin_version = '1.6.0' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,8 @@ void main() { | |
await chargebeeTest.retrieveProductIdentifiersWithoutParam(); | ||
await chargebeeTest.retrieveProductIdentifiersWithParam(); | ||
await chargebeeTest.retrieveProducts(); | ||
await chargebeeTest.purchaseProducts_withCustomerInfo(); | ||
await chargebeeTest.purchaseProducts_withCustomerId(); | ||
await chargebeeTest.purchaseProduct_withCustomerInfo(); | ||
await chargebeeTest.purchaseProducts_withoutCustomerInfo(); | ||
await chargebeeTest.retrieveSubscriptions(); | ||
await chargebeeTest.retrieveEntitlements(); | ||
|
@@ -111,8 +112,14 @@ class ChargebeeTest { | |
'currencyCode', | ||
SubscriptionPeriod.fromMap( | ||
{'periodUnit': 'month', 'numberOfUnits': 3},),); | ||
|
||
Future<void> purchaseProducts_withCustomerInfo() async { | ||
final customer = CBCustomer( | ||
'abc_flutter_test', | ||
'fn', | ||
'ln', | ||
'[email protected]', | ||
); | ||
|
||
Future<void> purchaseProducts_withCustomerId() async { | ||
tester.printToConsole('Starting to subscribe the product'); | ||
|
||
if (platformName == 'ios') { | ||
|
@@ -141,7 +148,24 @@ class ChargebeeTest { | |
} | ||
|
||
try { | ||
final result = await Chargebee.purchaseProduct(product, 'abc'); | ||
final result = await Chargebee.purchaseProduct(product); | ||
debugPrint('purchase result: $result'); | ||
expect(result.status, 'true'); | ||
tester.printToConsole('Product subscribed successfully!'); | ||
} on PlatformException catch (e) { | ||
fail('Error: ${e.message}'); | ||
} | ||
} | ||
|
||
Future<void> purchaseProduct_withCustomerInfo() async { | ||
tester.printToConsole('Starting to subscribe the product'); | ||
if (platformName == 'ios') { | ||
_getProduct(productIdForiOS); | ||
} else { | ||
_getProduct(productIdForAndroid); | ||
} | ||
try { | ||
final result = await Chargebee.purchaseStoreProduct(product, customer: customer); | ||
debugPrint('purchase result: $result'); | ||
expect(result.status, 'true'); | ||
tester.printToConsole('Product subscribed successfully!'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,7 +86,8 @@ class ProductListViewState extends State<ProductListView> { | |
if (product.subscriptionPeriod.unit.isNotEmpty && | ||
product.subscriptionPeriod.numberOfUnits != 0) { | ||
mProgressBarUtil.showProgressDialog(); | ||
purchaseProduct(product); | ||
// purchaseProduct(product); | ||
purchaseStoreProduct(product); | ||
} else { | ||
_showDialog(context, product); | ||
} | ||
|
@@ -97,7 +98,46 @@ class ProductListViewState extends State<ProductListView> { | |
|
||
Future<void> purchaseProduct(Product product) async { | ||
try { | ||
final result = await Chargebee.purchaseProduct(product, 'customerId'); | ||
final result = await Chargebee.purchaseProduct(product, 'abc'); | ||
debugPrint('subscription result : $result'); | ||
debugPrint('subscription id : ${result.subscriptionId}'); | ||
debugPrint('plan id : ${result.planId}'); | ||
debugPrint('subscription status : ${result.status}'); | ||
|
||
mProgressBarUtil.hideProgressDialog(); | ||
|
||
if (result.status == 'true') { | ||
_showSuccessDialog(context, 'Success'); | ||
} else { | ||
_showSuccessDialog(context, result.subscriptionId); | ||
} | ||
} on PlatformException catch (e) { | ||
debugPrint( | ||
'Error Message: ${e.message}, Error Details: ${e.details}, Error Code: ${e.code}'); | ||
mProgressBarUtil.hideProgressDialog(); | ||
if (e.code.isNotEmpty) { | ||
final responseCode = int.parse(e.code); | ||
if (responseCode >= 500 && responseCode <= 599) { | ||
/// Cache the productId in SharedPreferences if failed synching with Chargebee. | ||
final prefs = await SharedPreferences.getInstance(); | ||
prefs.setString('productId', product.id); | ||
|
||
/// validate the receipt | ||
validateReceipt(product.id); | ||
} | ||
} | ||
} | ||
} | ||
|
||
Future<void> purchaseStoreProduct(Product product) async { | ||
try { | ||
final customer = CBCustomer( | ||
'abc_flutter_test', | ||
'fn', | ||
'ln', | ||
'[email protected]', | ||
); | ||
final result = await Chargebee.purchaseStoreProduct(product, customer: customer); | ||
debugPrint('subscription result : $result'); | ||
debugPrint('subscription id : ${result.subscriptionId}'); | ||
debugPrint('plan id : ${result.planId}'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.