<manifest><!-- if your binary use ONE store's In-app SDK, Please make sure to declare the following query on Androidmanifest.xml. Refer to the notice for more information. https://dev.onestore.net/devpoc/support/news/noticeView.omp?noticeId=32968 --> <queries> <intent> <actionandroid:name="com.onestore.ipc.iap.IapService.ACTION" /> </intent> <intent> <actionandroid:name="android.intent.action.VIEW" /> <dataandroid:scheme="onestore" /> </intent> </queries> ... <application> ... </application></manifest>
发行全球store的测试选项设置
此是强制SDK和全球store联动的选项。本功能从SDK v21.01.00版本开始适用。
<manifest> ... <application> <activity> ... </activity> ...<!-- Options for in-app testing on your global store --> <meta-dataandroid:name="onestore:dev_option"android:value="global" /> </application></manifest>
/** * Set the log level.<br/> * {@link Log#VERBOSE}, {@link Log#DEBUG}, {@link Log#INFO}, * {@link Log#WARN}, {@link Log#ERROR} * @param level int */com.gaa.sdk.base.Logger.setLogLevel(2)
发行组建版本网络安全比较弱,本选项需要删除。
错误处理
ONE store 支付程序库以IapResult形式反馈错误。IapResult包含分类App内可能出现的支付相关错误的ResponseCode。例如,如果IapResult收到RESULT_NEED_LOGIN 或 RESULT_NEED_UPDATE等错误代码(code),应用软件需要做出相应的处理。
privateval listener =PurchasesUpdatedListener { iapResult, purchases ->// To be implemented in a later section.}privatevar purchaseClient = PurchaseClient.newBuilder(activity) .setListener(listener) .setBase64PublicKey(/*your public key*/) // optional .build()
privatePurchasesUpdatedListener listener =new PurchasesUpdatedListener { @OverridepublicvoidonPurchasesUpdated(IapResult iapResult,List<PurchaseData>) {// To be implemented in a later section. }};privatePurchaseClient purchaseClient =PurchaseClient.newBuilder(activity).setListener(listener).setBase64PublicKey(/*your public key*/) // optional.build();
purchaseClient.startConnection(object : PurchaseClientStateListener {overridefunonSetupFinished(iapResult: IapResult) {if (iapResult.isSuccess) {// The PurchaseClient is ready. You can query purchases here. } }overridefunonServiceDisconnected() {// Try to restart the connection on the next request to// PurchaseClient by calling the startConnection() method. }})
purchaseClient.startConnection(new PurchaseClientStateListener { @OverridepublicvoidonSetupFinished(IapResult iapResult) {if (iapResult.isSuccess()) {// The PurchaseClient is ready. You can query purchases here. } } @OverridepublicvoidonServiceDisconnected() {// Try to restart the connection on the next request to// PurchaseClient by calling the startConnection() method. }});
val params = ProductDetailsParams.newBuilder() .setProductIdList(productIdList) .setProductType(ProductType.INAPP) .build()purchaseClient.queryProductDetailsAsync(params) { iapResult, productDetails ->// Process the result.}
ProductDetailsParams params =ProductDetailsParams.newBuilder().setProductIdList(productIdList).setProductType(ProductType.INAPP).build();purchaseClient.queryProductDetailsAsync(params,newProductDetailsListener() { @OverridepublicvoidonProductDetailsResponse(IapResult iapResult,List<ProductDetail>) {// Process the result. }});
funhandlePurchase(purchase: PurchaseData) {// Purchase retrieved from PurchaseClient#queryPurchasesAsync// or your PurchasesUpdatedListener.val purchase: PurchaseData=...// Verify the purchase.// Ensure entitlement was not already granted for this purchaseToken.// Grant entitlement to the user.val consumeParams = ConsumeParams.newBuilder() .setPurchaseData(purchase) .build() purchaseClient.consumeAsync(consumeParams) { iapResult, purchaseData ->// Process the result. }}
privatevoidhandlePurchase(PurchaseData purchase) {// Purchase retrieved from PurchaseClient#queryPurchasesAsync or your PurchasesUpdatedListener.PurchaseData purchase =...// Verify the purchase.// Ensure entitlement was not already granted for this purchaseToken.// Grant entitlement to the user.ConsumeParams consumeParams =ConsumeParams.newBuilder().setPurchaseData(purchase).build();purchaseClient.consumeAsync(consumeParams,newConsumeListener() { @OverridepublicvoidonConsumeResponse(IapResult iapResult,PurchaseData purchaseData) {// Process the result. } });}
purchaseClient.getStoreInfoAsync { iapResult, storeCode ->// Save storecode and use it in Server to Server API.}
purchaseClient.getStoreInfoAsync(newStoreInfoListener() { @OverridepublicvoidonStoreInfoResponse(IapResult iapResult,String storeCode) {// Save storecode and use it in Server to Server API. }});
安装ONE store服务
ONE store服务的版本低或者没有时,无法使用app内支付。 通过PurchaseClient.startConnection()连接时,可以在IapResult.getResponseCode()确认。如果发生RESULT_NEED_UPDATE,需要调用launchUpdateOrInstallFlow()方法。
val activity: Activity=...purchaseClient.launchUpdateOrInstallFlow(activity) { iapResult ->if (iapResult.isSuccess) {// If the installation is completed successfully,// you should try to reconnect with the ONE store service. // PurchaseClient by calling the startConnection() method. }}