【问题标题】:Unable to get updated Purchase object after Acknowledging the purchase in new Google billing Api 2.0在新的 Google billing Api 2.0 中确认购买后无法获取更新的购买对象
【发布时间】:2019-05-30 16:52:01
【问题描述】:

我正在实施具有此购买确认方法的新 billing API 2.0。 之前我使用 AIDL 进行购买,我有以下用例是我在开始购买时传递开发人员有效负载,并用于在响应中取回我的开发人员有效负载作为购买对象的一部分。

Bundle bundle = mService.getBuyIntent(3, "com.example.myapp",
   MY_SKU, "subs", developerPayload);

PendingIntent pendingIntent = bundle.getParcelable(RESPONSE_BUY_INTENT);
if (bundle.getInt(RESPONSE_CODE) == BILLING_RESPONSE_RESULT_OK) {
   // Start purchase flow (this brings up the Google Play UI).
   // Result will be delivered through onActivityResult().
   startIntentSenderForResult(pendingIntent, RC_BUY, new Intent(),
       Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));
}

在我的活动结果中,我曾经获得购买对象

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
   if (requestCode == 1001) {           
      int responseCode = data.getIntExtra("RESPONSE_CODE", 0);
      String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA");
      String dataSignature = data.getStringExtra("INAPP_DATA_SIGNATURE");

      if (resultCode == RESULT_OK) {
         try {
            JSONObject jo = new JSONObject(purchaseData);
            String sku = jo.getString("productId");
            alert("You have bought the " + sku + ". Excellent choice, 
               adventurer!");
          }
          catch (JSONException e) {
             alert("Failed to parse purchase data.");
             e.printStackTrace();
          }
      }
   }
}

这个购买对象有一个开发者有效载荷,我将它发送到服务器进行验证。

现在在新的 API 中,开发人员有效负载只能在购买完成后或我们消费购买时添加,所以 问题是在确认购买后我需要更新的购买对象但如何获取它强>?

 if (!purchase.isAcknowledged()) {
            AcknowledgePurchaseParams acknowledgePurchaseParams =
                AcknowledgePurchaseParams.newBuilder()
                    .setPurchaseToken(purchase.getPurchaseToken())
                    .setDeveloperPayload(/* my payload */)
                    .build();
            client.acknowledgePurchase(acknowledgePurchaseParams, acknowledgePurchaseResponseListener);
        }

acknowledgePurchaseResponseListener 中,无论是成功还是失败,我都只得到响应代码。但我需要使用 developerPayloadisAcknowledged 标志更新购买对象对象。

有没有办法做到这一点?在文档中找不到任何内容。

【问题讨论】:

    标签: android in-app-billing android-billing


    【解决方案1】:

    本地购买缓存会在您调用 acknowledgePurchaseResponseListener 时更新,因此您可以使用 https://developer.android.com/reference/com/android/billingclient/api/BillingClient.html#querypurchases 从缓存中查询购买。我们将考虑将更新购买添加到侦听器中,以便将来的库版本更方便。

    【讨论】:

      猜你喜欢
      • 2019-09-11
      • 2022-06-16
      • 2012-12-27
      • 2014-03-27
      • 2022-01-05
      • 2014-11-25
      • 2012-09-15
      • 2021-08-19
      • 2014-03-25
      相关资源
      最近更新 更多