in_app_purchase_utils 0.0.4
in_app_purchase_utils: ^0.0.4 copied to clipboard
Utility package to easily handle all the functionalities of in_app_purchase plugin.
InApp Purchase Utils #
A simple and easy-to-use wrapper for the in_app_purchase
plugin in Flutter, providing a streamlined integration process for handling in-app purchases.
Features #
- Simplified methods for purchasing and managing subscriptions.
- Easy-to-follow integration flow.
- Supports both Android and iOS platforms.
- Fetch available products and subscriptions effortlessly.
- Handles purchase validation and transaction restoration.
Installation #
Add the dependency to your pubspec.yaml
:
$ flutter pub add in_app_purchase_utils
This will add a line in your pubspec.yaml file under dependencies block.
dependencies:
in_app_purchase_utils:
Usage #
Import the package #
import 'package:your_plugin_name/your_plugin_name.dart';
Add in_app_purchase plugin: #
You need to add in_app_purchase plugin in your project so that you can access some default classes like ProductDetails. To add the dependency in your pubspec.yaml, use the flutter command mentioned below.
$ flutter pub add in_app_purchase
Initialize the plugin #
To initialize the plugin, you need to call InAppPurchaseService.instance.initialize() method.
Before the initialisation, make sure you put below mentioned statement in the first line of main() method.
WidgetsFlutterBinding.ensureInitialized();
There are 2 required params in this method.
1. validationAPI - Pass default iTunes or SandBox API according to your flavor / mode
2. secretKey - Pass your InApp purchase secret key
await InAppPurchaseService.instance
.initialize(
validationAPI: "<receipt_validation_API>",
secretKey: "<secret_key>"
);
Fetch available products #
Pass the list of your products as List
List<ProductDetails> products = await InAppPurchaseService.instance
.fetchProducts(["<product_id_1>", "<product_id_2>", "<product_id_n>"]);
Purchase a product #
Make call to purchaseSubscription() inorder to purchase a subscription. There will be 3 input params in this method.
1. productId - Pass the productId which you want to make purchase of
2. onSuccess - Purchase success callback
3. onFailure - Purchase failure callback
InAppPurchaseService pInstance = InAppPurchaseService.instance;
pInstance.purchaseSubscription(
"<product_id>",
onPurchaseSuccess,
onPurchaseFailure,
);
Restore purchases #
Make call to purchaseSubscription() inorder to purchase a subscription. There will be 2 input params in this method.
1. onSuccess - Purchase success callback
2. onFailure - Purchase failure callback
InAppPurchaseService pInstance = InAppPurchaseService.instance;
pInstance.restorePurchases(
(statusMessage, purchaseDetails) {},
(statusMessage, purchaseDetails) {}
);
License #
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions #
Contributions are welcome! Feel free to open issues or submit pull requests to improve the plugin.
Support #
For any issues or feature requests, please open an issue on GitHub.