gpt4 book ai didi

安卓计费;如何解决 "The item you were attempting to purchase could not be found"

转载 作者:行者123 更新时间:2023-12-04 15:31:57 26 4
gpt4 key购买 nike

由于最近对 Google Billing 库和开发者控制台进行了所有更改,因此很难应用 2014 年的答案,因此我再次发帖讨论这个主题,希望能找到一个现代的答案。

我正在使用 Google 结算库 2.2.0

问题: enter image description here


我已经设置了许可证: subscriptions


我还设置了许可证测试: license testing


我还向内部测试轨道发布了一个发布版本(使用发布证书签名): release build


相关代码示例:

private final String SKU_TEST_PROD_1YR = "test_prod_id_1_year";
private final String SKU_TEST_PROD_6MN = "test_prod_id_6_month";
private final String SKU_TEST_PROD_1MN = "test_prod_id_1_month";
private BillingClient billingClient;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

List<String> iapProdIdList = Arrays.asList(SKU_TEST_PROD_1YR, SKU_TEST_PROD_6MN, SKU_TEST_PROD_1MN);
setupBillingClient(this, iapProdIdList);
}

@Override
protected void onDestroy() {
super.onDestroy();
billingClient.endConnection();
}

private void setupBillingClient(Context context, List<String> iapProdList) {
billingClient = BillingClient.newBuilder(context).setListener(this).build();
billingClient.startConnection(new BillingClientStateListener() {
@Override
public void onBillingSetupFinished(BillingResult billingResult) {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
loadAllSubscriptionProductIdDetails(iapProdList);
}
}

@Override
public void onBillingServiceDisconnected() { }
});
}

private void loadAllSubscriptionProductIdDetails(List<String> iapProdList) {
if (billingClient.isReady()) {
SkuDetailsParams params = SkuDetailsParams.newBuilder().setSkusList(iapProdList).setType(BillingClient.SkuType.SUBS).build();

billingClient.querySkuDetailsAsync(params, (billingResult, prodDetailList) -> {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK && !prodDetailList.isEmpty()) {

for (SkuDetails prodDetail : prodDetailList) {

String productSku = prodDetail.getSku();

switch(productSku) {
case SKU_TEST_PROD_1YR : {
final BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder().setSkuDetails(prodDetail).build();
buttonIap1Yr.setOnClickListener(v -> {
// trigger purchase - Google needs the parent activity to overlay with their UI
billingClient.launchBillingFlow(this, billingFlowParams);
});
break;
}
case SKU_TEST_PROD_6MN : {
final BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder().setSkuDetails(prodDetail).build();
buttonIap6mth.setOnClickListener(v -> {
// trigger purchase - Google needs the parent activity to overlay with their UI
billingClient.launchBillingFlow(this, billingFlowParams);
});
break;
}
case SKU_TEST_PROD_1MN : {
final BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder().setSkuDetails(prodDetail).build();
buttonIap1mth.setOnClickListener(v -> {
// trigger purchase - Google needs the parent activity to overlay with their UI
billingClient.launchBillingFlow(this, billingFlowParams);
});
break;
}
default :
Toast.makeText(this, "Did not find Product in-app: "+ productSku, Toast.LENGTH_SHORT).show();
}
}//end of FOR
}//end of IF
});
} else {
Toast.makeText(this, "billingClient is NOT ready", Toast.LENGTH_SHORT).show();
}
}

@Override
public void onPurchasesUpdated(BillingResult billingResult, List<Purchase> list) {

if (billingResult != null && list != null) {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
for (Purchase purchase : list) {
if(!purchase.isAcknowledged()) acknowledgePurchase(purchase.getPurchaseToken());
}
}
else if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.USER_CANCELED) {
Toast.makeText(this, "User Canceled", Toast.LENGTH_SHORT).show();
}
else if(billingResult.getResponseCode()== BillingClient.BillingResponseCode.ITEM_ALREADY_OWNED) {
Toast.makeText(this, "Already Purchased", Toast.LENGTH_SHORT).show();
}
}
}

private void acknowledgePurchase(String purchaseToken) {
AcknowledgePurchaseParams params = AcknowledgePurchaseParams.newBuilder().setPurchaseToken(purchaseToken).build();
billingClient.acknowledgePurchase(params, billingResult -> {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
Toast.makeText(this, "Purchase Acknowledged", Toast.LENGTH_SHORT).show();
}
});
}

当我点击任何 [购买订阅] 按钮时,billingClient.launchBillingFlow(this, billingFlowParams); 被正确触发并且 SKU 正确。

据我所知,所有开发控制台都已正确设置。我想向我的经理演示 IAP,但是,“无法找到您尝试购买的商品”让我的风格受到限制!我做错了什么?

最佳答案

我在问题中发布的代码功能齐全。问题是 100% 由于开发者控制台配置:

修复它:

1) 最低限度将应用提升到 alpha 版(内部测试轨道不起作用!)

2) 单击 Alpha 轨道上的 [管理] 并将选择加入链接通过电子邮件发送给您的测试人员

3) 您的测试人员会说“当我点击此链接时,Play 商店说找不到该应用程序”。告诉他们放松 30 分钟 - Google 控制台需要 30 分钟来处理这种复杂情况。

让他们下载早期发布版本,IAP 突然就可以使用了!

关于安卓计费;如何解决 "The item you were attempting to purchase could not be found",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61090660/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com