Using the ONE Store In-App Library in Flutter
Last updated
Last updated
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.
Click on 'pub get' to download the package, or run 'flutter pub get' from the command line.
Add the maven address to your project's build.gradle.
Add the configuration dependencies to your app's build.gradle.
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.
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.
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.
Utilize 'await _clientManager.queryProductDetails(List<String>, ProductType)' to request detailed information for in-app products registered through the One store developer center.
Use 'await _clientManager.launchPurchaseFlow(ProductDetail)' to request the purchase of a product.
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.
Use '_clientManager.consumePurchase(PurchaseData)' to request the consumption of a managed product.
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.
Use '_clientManager.queryPurchases(ProductType)' to request a list of unconsumed purchases.
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'.
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.
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.
Parameter
Type
Description
productDetail
ProductDetail
Detailed information you wish to purchase
quantity
Int
For multiple purchases
Default Value: 1
developerPayload
String
When making a purchase request, send the necessary data input by the developer along with the request.
This data will also be included in the purchase result (PurchaseData.developerPayload).
Limitation: max 200byte
Parameter
Type
Description
productDetail
ProductDetail
Information on the subscription product to change
oldPurchseData
PurchaseData
Purchase information of the subscription product that is targeted to change
prorationMode
ProrationMode
The applicable mode when changing existing subscription purchase information (for detailed information, refer to the existing guide)