<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.co.kr/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)
常數
值
VERBOSE
2
DEBUG
3
INFO (default)
4
WARN
5
ERROR
6
發行版本網絡安全比較弱,本選項需要刪除。
錯誤處理
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. }}