レガシー AppCoins SDK から新しい Aptoide SDK への移行
概要
この移行では、レガシーの AppCoins Billing SDK(io.catappult:android-appcoins-billing)を最新の Aptoide Billing SDK(com.aptoide:android-aptoide-billing)に置き換えます。新しい SDK は、モダン化された API、よりクリーンな構造、Android の機能との互換性の向上、そして業界の課金標準との緊密な整合性をもたらします。以下の手順では、依存関係の入れ替え、AptoideBillingClient の採用、ならびに購入およびプロダクトのクエリの更新について説明します。
移行手順の概要
移行を成功させるための主な手順は次のとおりです。
-
SDK 依存関係の更新
Gradle ファイル内の AppCoins SDK 依存関係を新しい Aptoide SDK に置き換えます。 -
Billing Client の初期化のリファクタリング
新しいビルダーパターンを使用して、AppcoinsBillingClientをAptoideBillingClientに置き換えます。 -
購入リスナーの更新
ResponseCode に整数の代わりにBillingResultを扱うようにPurchasesUpdatedListenerを更新します。 -
購入クエリロジックの更新
queryPurchases(SkuType)をqueryPurchasesAsync(QueryPurchasesParams)に置き換えます。 -
プロダクトクエリロジックの移行
querySkuDetailsAsyncをqueryProductDetailsAsyncに置き換えます。検索するプロダクトのタイプを定義するためにQueryProductDetailsParamsを使用し、SkuDetailsの代わりにProductDetailsを受け取ります。 -
購入フローの更新
SKU ベースの直接購入を、ProductDetailsParamsを使用するBillingFlowParamsに置き換えます。 -
消費ロジックのリファクタリング
従来の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 を更新し、プロジェクトを同期します。
プロジェクトの同期が完了したら、次の例のように appcoins を aptoide に置き換えて、レガシーの 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);
必要な変更:
AppcoinsBillingClientをAptoideBillingClientに置き換えますAppCoinsBillingStateListenerをAptoideBillingClientStateListenerに置き換えます- レスポンスコードには生の整数の代わりに
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
}
}
});
注意事項:
SkuDetailsParamsをQueryProductDetailsParamsに置き換えますSkuTypeをProductTypeに置き換えます
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 クラス | AppcoinsBillingClient | AptoideBillingClient |
| プロダクトのクエリ | querySkuDetailsAsync | queryProductDetailsAsync |
| 購入フローのパラメータ | SKU を使用する BillingFlowParams | ProductDetails を使用する BillingFlowParams |
| 課金アクションの結果 | ResponseCode としての Int 値 | BillingResponseCode と Debug Message を含む BillingResult を使用 |
| 消費 | consumeAsync(token) | consumeAsync(ConsumeParams) |
FAQ
Aptoide Billing SDK 統合のドキュメント全体はどこで確認できますか?
新しい Aptoide Billing SDK 統合に関するドキュメント全体はこちらで確認できます。当社の課金システムを完全かつ成功裏に統合するための最も重要な手順が記載されています。
レガシー AppCoins Billing SDK 統合のドキュメントはどこで確認できますか?
レガシーの Aptoide Billing SDK 統合に関するドキュメントはこちらで確認できます。