gpt4 book ai didi

java - 所有应用内购买都会在五分钟内取消并退款(Alpha 测试)

转载 作者:行者123 更新时间:2023-12-02 01:11:57 27 4
gpt4 key购买 nike

这是我第一次为我的应用程序实现应用内计费,并且我已经设置了通过单击按钮即可购买的一美元捐赠。以下是我的 Activity ,其中发生了所有购买流程:

public class DonationsActivity extends AppCompatActivity implements PurchasesUpdatedListener{

private BillingClient billingClient;
ConsumeResponseListener listener;
private SkuDetails oneDetails;

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

billingClient = BillingClient.newBuilder(DonationsActivity.this).setListener(this).enablePendingPurchases().build();
billingClient.startConnection(new BillingClientStateListener() {
@Override
public void onBillingSetupFinished(BillingResult billingResult) {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
List<String> skuList = new ArrayList<> ();
skuList.add("one_dollar_donation");
SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
params.setSkusList(skuList).setType(BillingClient.SkuType.INAPP);
billingClient.querySkuDetailsAsync(params.build(),
new SkuDetailsResponseListener() {
@Override
public void onSkuDetailsResponse(BillingResult billingResult,
List<SkuDetails> skuDetailsList) {
for(SkuDetails theDetails : skuDetailsList)
{
if(theDetails.getSku().equals("one_dollar_donation"))
{
oneDetails = theDetails;
}
}
}
});
}
}
@Override
public void onBillingServiceDisconnected() {

}
});

listener = new ConsumeResponseListener() {
@Override
public void onConsumeResponse(BillingResult billingResult, String outToken) {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {

}
}
};
}

@Override
public void onPurchasesUpdated(BillingResult billingResult, List<Purchase> purchases) {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK
&& purchases != null) {
for (Purchase purchase : purchases) {
handlePurchase(purchase);
}
} else if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.USER_CANCELED) {
Toast.makeText(this, getString(R.string.canceled_donation), Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, getString(R.string.error_donation), Toast.LENGTH_LONG).show();
}
}

private void handlePurchase(Purchase purchase)
{
if (!purchase.isAcknowledged())
{
ConsumeParams consumeParams = ConsumeParams.newBuilder().build();
billingClient.consumeAsync(consumeParams, listener);
}
}

public void donateOneDollar(View view)
{
BillingFlowParams flowParams = BillingFlowParams.newBuilder()
.setSkuDetails(oneDetails)
.build();

BillingResult responseCode = billingClient.launchBillingFlow(DonationsActivity.this, flowParams);
}

我的问题是,每次我进行测试购买时,都会在接下来的五分钟内取消并退款。当购买被取消时,我也无法在五分钟内进行更多购买。

根据我的理解,这个问题是因为购买未被确认(这就是它在 5 分钟内获得退款的原因)而引起的,并且我无法在此期间进行更多购买,因为 Google 认为我已经拥有该商品项目(我没有消费它,即同样的问题)

我以为我从内部确认并消费了购买的产品:

private void handlePurchase(Purchase purchase)
{
if (!purchase.isAcknowledged())
{
ConsumeParams consumeParams = ConsumeParams.newBuilder().build();
billingClient.consumeAsync(consumeParams, listener);
}
}

但是我显然犯了一个错误,任何人都可以帮助我了解我的错误是什么,以及如何解决它?

最佳答案

经过很长时间试图找出错误后,我意识到我错过了 ConsumeParams 中的 setPurchaseToken 方法,这就是 Play 商店不知道我消费了什么购买的原因。

关于java - 所有应用内购买都会在五分钟内取消并退款(Alpha 测试),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57680330/

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