Android InApp购买

编程入门 行业动态 更新时间:2024-10-25 14:31:51
本文介绍了Android InApp购买 - 如何处理待处理状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在将Android应用内购买与Android Native应用集成。我使用以下代码启动In-App购买意图!

I am integrating Android In-App purchase with Android Native application. I used following code to start In-App purchase intent!

Bundle buyIntentBundle = mService.getBuyIntent(3, getPackageName(),"product_sku", "inapp","Some Developer Payload"); PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT"); startIntentSenderForResult(pendingIntent.getIntentSender(),REQUEST_CODE, new Intent(),Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));

以上代码正在使用并打开Goog​​le Play以进行应用内购买。我重写了onActivityResult以获取应用内购买的结果(以下是代码)

Above code is working with and open Google Play for In-app purchase. I overridden the onActivityResult for getting the result of In-App Purchase (following is code)

protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 1001) { if (resultCode == RESULT_OK) { try { final JSONObject jo = new JSONObject(purchaseData); String orderId = jo.getString("orderId"); String productId = jo.getString("productId"); String state = String.valueOf(jo.getInt("purchaseState")); //POST purchase result to my server for my record! //Finally Consume the product } catch (JSONException e) { e.printStackTrace(); } } } }

以下是我们从InApp购买收到的回复

Following is response we received from InApp purchase

'{ "orderId":"12999763169054705758.1371079406387615", "packageName":"com.example.app", "productId":"exampleSku", "purchaseTime":1345678900000, "purchaseState":0, "developerPayload":"bGoa+V7g/yqDXvKRqq+JTFn4uQZbPiQJo4pf9RzJ", "purchaseToken":"rojeslcdyyiapnqcynkjyyjh" }'

我的问题是如何识别应用内购买交易处于待处理状态,因为purchaseState(JSON中的整数值)只有三个值已购买,取消和退款。

My questions is that how to identify that the in-app purchase transaction is in "Pending" status because "purchaseState" (Integer value in JSON) having only three values "purchased"," canceled" and "refunded".

我来自印度,谷歌钱包在购买完成后立即接受任何交易。

I am from india and google wallet is accepting any transaction immediately after inapp purchase completed.

它始终处于Pending状态,然后需要48小时才能接受或rej等交易!

It is always in Pending status first and then takes upto 48 hours to accept or reject the transaction!

我想只允许我的客户在Google waltet成功付款后才能使用In app购买的产品。

I want only allow my customer to use In app purchased product only after successfully payment in Google waltet.

我遇到了我的一位客户从我的应用程序购买了inapp产品,但不知何故他们的数据没有发布在服务器上。客户告诉我,该购买交易最初处于待定状态,并在两天后完成,即使我在我的商家帐户中获得了这笔付款,因此我得出结论:Android没有响应在购买的onActivityResult中,resultCode == RESULT_OK正在等待处理。

I faced that My one customer purchased inapp product from my application but somehow their data is not posted on server. Customer told me that that purchase transaction was in pending status initially and completed after two days, even I got that payment in my Merchant account so I concluded that Android is not responding resultCode == RESULT_OK in onActivityResult is purchased is in pending.

所以如果有人遇到同样的问题,那么请向我解释处理待处理状态的解决方案或流程!我是否必须将APN用于待处理状态?但我需要将待处理的状态订单详细信息存储在我的服务器上! 先谢谢!

So If anyone faced same problem then please explain me the solution or flow to handle the pending status! Should I have to use APN for pending status? But I need that pending status order details to store on my server! Thanks in Advance!

推荐答案

我知道很久以前就问过这个问题了。但是我面临同样的问题(使用巴西市场的应用程序)。

I know this question was asked a long time ago. But I am facing the very same issue (with an App for the Brazilian market).

我注意到立即处理的购买,一切正常。

I noticed that purchases which got processed right away, everything works fine.

但是,有些购买会进入待付款状态,最多可能需要48小时才能更改状态。但是,我的服务器永远不会被调用 - 正如OP所说,我怀疑谷歌播放服务器返回不同的状态(除了RESULT_OK),我的应用程序没有捕获它。 然后,我的用户收费,但无法访问PREMIUM功能 - 因为我的服务器从未收到通知。

But, some purchases get into the 'pending payment' status and it can take up to 48 hours to change status. But, my server never gets called - as OP stated, I suspect Google play server returns a different status (other than RESULT_OK) and my app doesn't capture that. Then, my user gets charged, but has no access to the PREMIUM features - since my server never got notified.

因此,截至2018年,我读过我们可能有另一种选择。以下链接提供了有关如何处理订阅的一些信息

So, as of 2018, I read that we might have an alternative. The following link has some information on how to deal with subscriptions

developer.android/google/play/billing/billing_subscriptions

..并指向以下内容:

.. and points to the following:

https:// developer.android/google/play/billing/realtime_developer_notifications

实时开发者通知

这样,每次用户订阅状态发生变化时,Google都会向您的服务器发送通知。因此,如果您的用户付款需要48小时才能完成,您的服务器将收到通知,您可以使用户使用PREMIUM或您需要的任何逻辑。

this allows Google play to send your server a notification, every time a user subscription status changes. So, if your user's payment took 48h to complete, your server would receive a notification and you could make the user PREMIUM or whatever logic you need.

希望它有所帮助。

更多推荐

Android InApp购买

本文发布于:2023-11-09 20:21:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1573338.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Android   InApp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!