Using the ONE Store In-App Library in Flutter
Overview
The ONE store payment plugin provides access to the latest features of the ONE Store payment library within applications developed in the Flutter environment.
This guide will explain how to use the plugin and implement the functions of the ONE store payment library.
Plugin Installation
How to add the plugin to your ‘pubspec.yaml’ file:
Click on 'pub get' to download the package, or run 'flutter pub get' from the command line.
Adding dependencies to build.gradle
Add the maven address to your project's build.gradle.
Add the configuration dependencies to your app's build.gradle.
Adding <queries> to AndroidManifest.xml
If you have set the Target SDK version to 30 (OS 11) or higher, you must add the following <queries> to ensure the in-app library functions correctly.
Requesting Login:
The ONE store in-app payment operates on a login basis. When the app starts for the first time, it prompts the user to log in before calling the API of the purchase library. This can prevent various issues, such as token expiration, before they occur when requesting the purchase library.
Updating Purchase Data and Listening for Error Responses in the App
Implementing the ‘PurchasesUpdatedStream’ response:
This object should listen for purchase updates immediately when the app starts. Therefore, use 'lazy: false' to disable ‘Lazy Loading’ for this object.
Issuing a license key:
When you register your app through the ONE store developer center, a license key is generated.
Initialize the object for the first time once with PurchaseClientManager.initialize() call.
Prepare to receive purchase completion responses by 'listening' to the 'purchasesUpdatedStream'. Receive purchase data responses for successful transactions through _listenToPurchasesUpdated. For failed purchases, responses are conveyed through _updateStreamOnError.
Upon closing the app, you should call 'PurchaseClientManager.dispose()' to release memory and disconnect. Also, dispose () of the _purchaseUpdatedStream that you have been listening to in order to disconnect.
Searching for Detailed Product Information:
Utilize 'await _clientManager.queryProductDetails(List<String>, ProductType)' to request detailed information for in-app products registered through the One store developer center.
Initiating Purchase Request:
Use 'await _clientManager.launchPurchaseFlow(ProductDetail)' to request the purchase of a product.
Post-purchase processing
If the purchase has been successfully completed, you can receive a response through '_listenToPurchasesUpdated' which you registered in 'Updating Purchase Data and Listening for Error Responses in the App'.
Of course, you can also receive responses for failed purchases through '_updateStreamOnError'.
Once you have received a purchase completion response from the store, it is crucial to perform a consume or acknowledge action.
If you do not acknowledge or consume the purchase within 3 days, it will be considered that the product has not been delivered to the user and will automatically be refunded.
Consumption:
Use '_clientManager.consumePurchase(PurchaseData)' to request the consumption of a managed product.
Purchase Acknowledgement:
Use '_clientManager.acknowledgePurchase(PurchaseData)' to request confirmation for managed or subscription products.
For managed products (ProductType.inapp), if you do not immediately consumed, it can be used like a subscription product.
Subscription product: Acknowledge → Response → acknowledgePurchase → After a certain period → consumePurchase
Consumable product: Acknowledge → Response → consumePurchase
For subscription products (ProductType.subs), they can be used only for acknowledgePurchase.
Retrieving Purchase History:
Use '_clientManager.queryPurchases(ProductType)' to request a list of unconsumed purchases.
Upgrading and Downgrading Subscription:
Use '_clientManager.launchUpdateSubscription(ProductDetail, PurchaseData, ProrationMode)' to change the purchased subscription product to a new one.
Upgrade or Downgrade follows the same flow as the “Initiating Purchase Request,” so the response handling is the same as when requesting a purchase.
You can receive responses through '_listenToPurchasesUpdated'.
Opening the Subscription Management Screen:
Use '_clientManager.launchManageSubscription(PurchaseData?)' to navigate to the detailed page of the purchased subscription product.
Changing the subscription settings are up to the user, and the following can be managed in the subscription menu:
Change payment methods
Change subscription status (schedule cancellation, revoke cancellation)
Agreement to price changes for already subscribed products
If you request with the PurchaseData as ‘null,’ you will be directed to the subscription list screen instead of a specific subscription product's detail page.
Installing ONE Store Service:
If ONE store service is not installed or is not the minimum version required by the v21 SDK, a RESULT_NEED_UPDATE error will occur. If you receive this error, use '_clientManager.launchUpdateOrInstall()' to request the installation of the service.
Last updated