メインコンテンツまでスキップ

レガシー AppCoins SDK から新しい Aptoide SDK への移行

概要

この移行では、レガシーの AppCoins Billing SDKio.catappult:android-appcoins-billing)を最新の Aptoide Billing SDKcom.aptoide:android-aptoide-billing)に置き換えます。新しい SDK は、モダン化された API、よりクリーンな構造、Android の機能との互換性の向上、そして業界の課金標準との緊密な整合性をもたらします。以下の手順では、依存関係の入れ替え、AptoideBillingClient の採用、ならびに購入およびプロダクトのクエリの更新について説明します。

移行手順の概要

移行を成功させるための主な手順は次のとおりです。

  1. SDK 依存関係の更新
    Gradle ファイル内の AppCoins SDK 依存関係を新しい Aptoide SDK に置き換えます。

  2. Billing Client の初期化のリファクタリング
    新しいビルダーパターンを使用して、AppcoinsBillingClientAptoideBillingClient に置き換えます。

  3. 購入リスナーの更新
    ResponseCode に整数の代わりに BillingResult を扱うように PurchasesUpdatedListener を更新します。

  4. 購入クエリロジックの更新
    queryPurchases(SkuType)queryPurchasesAsync(QueryPurchasesParams) に置き換えます。

  5. プロダクトクエリロジックの移行
    querySkuDetailsAsyncqueryProductDetailsAsync に置き換えます。検索するプロダクトのタイプを定義するために QueryProductDetailsParams を使用し、SkuDetails の代わりに ProductDetails を受け取ります。

  6. 購入フローの更新
    SKU ベースの直接購入を、ProductDetailsParams を使用する BillingFlowParams に置き換えます。

  7. 消費ロジックのリファクタリング
    従来の consumeAsync(token) メソッドを、ConsumeParams を使用する新しいメソッドに置き換えます。


1. SDK 依存関係の更新

AppCoins SDK:

implementation("io.catappult:android-appcoins-billing:0.9.+")

Aptoide SDK:

implementation("com.aptoide:android-aptoide-billing:1.+")

build.gradle を更新し、プロジェクトを同期します。
プロジェクトの同期が完了したら、次の例のように appcoinsaptoide に置き換えて、レガシーの AppCoins Billing SDK のすべてのインポートを新しい Aptoide Billing SDK に更新します。

レガシーのインポート:

import com.appcoins.sdk.billing.Purchase

新しいインポート:

import com.aptoide.sdk.billing.Purchase

2. Billing Client の初期化のリファクタリング

レガシーの初期化:

val cab = CatapultBillingAppCoinsFactory.BuildAppcoinsBilling(context, publicKey, listener)  
cab.startConnection(appCoinsBillingStateListener)
CatappultAppcoinsBilling cab = CatapultBillingAppCoinsFactory.BuildAppcoinsBilling(context, publicKey, listener)  
cab.startConnection(appCoinsBillingStateListener)

新しい初期化:

val billingClient = AptoideBillingClient.newBuilder(context)  
.setListener(purchasesUpdatedListener)
.setPublicKey(publicKey)
.build()

billingClient.startConnection(aptoideBillingClientStateListener)
AptoideBillingClient billingClient = AptoideBillingClient.newBuilder(context)
.setListener(purchasesUpdatedListener)
.setPublicKey(publicKey)
.build();

billingClient.startConnection(aptoideBillingClientStateListener);

必要な変更:

  • AppcoinsBillingClientAptoideBillingClient に置き換えます
  • AppCoinsBillingStateListenerAptoideBillingClientStateListener に置き換えます
  • レスポンスコードには生の整数の代わりに BillingResult を使用します

3. 購入リスナーの更新

レガシー:

val purchasesUpdatedListener = PurchasesUpdatedListener { responseCode, purchases ->
if (responseCode == ResponseCode.OK.value) {
for (purchase in purchases) {
// Apply here your Purchase result logic
}
}
}
PurchasesUpdatedListener purchasesUpdatedListener = (responseCode, purchases) -> {
if (responseCode == ResponseCode.OK.getValue()) {
for (Purchase purchase : purchases) {
// Apply here your Purchase result logic
}
}
};

新規:

val purchasesUpdatedListener = PurchasesUpdatedListener { billingResult, purchases ->
if (billingResult.responseCode == BillingResponseCode.OK) {
for (purchase in purchases) {
// Apply here your Purchase result logic
}
}
}
PurchasesUpdatedListener purchasesUpdatedListener = (billingResult, purchases) -> {
if (billingResult.getResponseCode() == BillingResponseCode.OK) {
for (Purchase purchase : purchases) {
// Apply here your Purchase result logic
}
}
};

ハイライト:

  • レスポンスコードは billingResult.responseCode から取得するようになりました
  • トークンの抽出および配信・消費の処理については同じロジックを維持します

4. 購入クエリロジックの更新

レガシー:

val purchasesResult = cab.queryPurchases(SkuType.inapp)
PurchasesResult purchasesResult = cab.queryPurchases(SkuType.inapp)

新規:

val params = QueryPurchasesParams.newBuilder()
.setProductType(ProductType.INAPP)
.build()

billingClient.queryPurchasesAsync(params) { billingResult, purchases ->
// Handle results
}
QueryPurchasesParams params = QueryPurchasesParams.newBuilder()
.setProductType(ProductType.INAPP)
.build();

billingClient.queryPurchasesAsync(params, (billingResult, purchases) -> {
// Handle results
});

5. プロダクトクエリロジックの移行

レガシー:

cab.querySkuDetailsAsync(SkuDetailsParams(...), listener)
cab.querySkuDetailsAsync(new SkuDetailsParams(...), listener)

新規:

val params = QueryProductDetailsParams.newBuilder()
.setProductList(
listOf(
Product.newBuilder()
.setProductId("your_product_id")
.setProductType(ProductType.INAPP)
.build()
)
).build()

billingClient.queryProductDetailsAsync(params) { billingResult, productDetailsResult ->
if (billingResult.responseCode == BillingResponseCode.OK) {
for (product in productDetailsResult.productDetailsList) {
// Use product details here
}
}
}
QueryProductDetailsParams params = QueryProductDetailsParams.newBuilder()
.setProductList(
List.of(
Product.newBuilder()
.setProductId("your_product_id")
.setProductType(ProductType.INAPP)
.build()
)
).build();

billingClient.queryProductDetailsAsync(params, (billingResult, productDetailsResult) -> {
if (billingResult.getResponseCode() == BillingResponseCode.OK) {
for (ProductDetails product : productDetailsResult.getProductDetailsList()) {
// Use product details here
}
}
});

注意事項:

  • SkuDetailsParamsQueryProductDetailsParams に置き換えます
  • SkuTypeProductType に置き換えます

6. 購入フローの更新

レガシー:

val billingFlowParams = BillingFlowParams(...)  
cab.launchBillingFlow(activity, billingFlowParams)
BillingFlowParams billingFlowParams = new BillingFlowParams(...);
cab.launchBillingFlow(activity, billingFlowParams);

新規:

val productDetailsParams = BillingFlowParams.ProductDetailsParams.newBuilder()
.setProductDetails(productDetails)
.build()

val billingFlowParams = BillingFlowParams.newBuilder()
.setProductDetailsParamsList(listOf(productDetailsParams))
.setObfuscatedAccountId(userId)
.setFreeTrial(true)
.build()

billingClient.launchBillingFlow(activity, billingFlowParams)
BillingFlowParams.ProductDetailsParams productParams =
BillingFlowParams.ProductDetailsParams.newBuilder()
.setProductDetails(productDetails)
.build();

BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder()
.setProductDetailsParamsList(List.of(productParams))
.setObfuscatedAccountId(userId)
.setFreeTrial(true) // Use this to initiate Free Trials
.build();

billingClient.launchBillingFlow(activity, billingFlowParams);

主な変更点:

  • 生の SKU 文字列の代わりに ProductDetails を使用します
  • ユーザー単位のトラッキングのために setObfuscatedAccountId() を追加します
  • setFreeTrial() がトライアルのロジックを処理します

7. 消費ロジックのリファクタリング

レガシー:

cab.consumeAsync(purchase.token, consumeResponseListener)
cab.consumeAsync(purchase.getToken(), consumeResponseListener);

新規:

val consumeParams = ConsumeParams.newBuilder()
.setPurchaseToken(purchase.purchaseToken)
.build()

billingClient.consumeAsync(consumeParams, consumeResponseListener)
ConsumeParams consumeParams = ConsumeParams.newBuilder()
.setPurchaseToken(purchase.getPurchaseToken())
.build();

billingClient.consumeAsync(consumeParams, consumeResponseListener);

重要:

  • 購入は必ず 48 時間以内に消費してください
  • サブスクリプションも消費または承認する必要があります(Backend API 経由

変更点の比較表

機能レガシー AppCoins SDK新しい Aptoide SDK
Billing Client クラスAppcoinsBillingClientAptoideBillingClient
プロダクトのクエリquerySkuDetailsAsyncqueryProductDetailsAsync
購入フローのパラメータSKU を使用する BillingFlowParamsProductDetails を使用する BillingFlowParams
課金アクションの結果ResponseCode としての Int 値BillingResponseCode と Debug Message を含む BillingResult を使用
消費consumeAsync(token)consumeAsync(ConsumeParams)

FAQ

Aptoide Billing SDK 統合のドキュメント全体はどこで確認できますか?

新しい Aptoide Billing SDK 統合に関するドキュメント全体はこちらで確認できます。当社の課金システムを完全かつ成功裏に統合するための最も重要な手順が記載されています。


レガシー AppCoins Billing SDK 統合のドキュメントはどこで確認できますか?

レガシーの Aptoide Billing SDK 統合に関するドキュメントはこちらで確認できます。