简体   繁体   English

Android应用内购买空白订单ID

[英]Android In-App purchase blank order id

I am developed an app in which user purchases will registered on the server. 我开发了一个应用程序,用户购买将在服务器上注册。 And on the server side OrderId of Purchase class is a primary key. 在服务器端, Purchase类的OrderId是主键。

In android documentation, I have read that order Id will be blank for test purchases. 在Android文档中,我已经读过,测试购买的订单ID将为空。 However, my server will not accept blank order id. 但是,我的服务器不接受空白订单ID。 So I tried this workaround: 所以我尝试了这个解决方法:

public static final boolean IS_TEST_PURCHASES = true;

// Before updating to server
if (IS_TEST_PURCHASES && Util.isBlank(purchaseId))
    purchaseId = "Test." + TimeUtils.getCurrentUnixTime();

This solved my problem for some time. 这解决了我的问题已有一段时间了。 But, in Beta mode the same problem appeared as I cannot release APK with IS_TEST_PURCHASES = true . 但是,在Beta模式下出现同样的问题,因为我无法使用IS_TEST_PURCHASES = true发布APK。

I checked the JSON retrned after purchase in which only OrderId is blank and rest of the feilds like signature, token are available. 我检查了购买后重新启动的JSON,其中只有OrderId为空,其余的部分如签名,令牌可用。 I was thinking if I can make a condition like: 我在想,如果我能做出如下条件:

if OrderId is empty and Signature or Token is not empty, then this purchase is a test purchase and assign some dummy order id to it. 如果OrderId为空并且SignatureToken不为空,则此购买是测试购买并为其分配一些虚拟订单ID。

But I am confused whether this condition will cause any future problems. 但我很困惑这种情况是否会引起任何未来的问题。

I need to differentiate real purchase and test purchase so that I can set some dummy OrderId if and only if purchase is made through sandbox testing. 我需要区分真实购买和测试购买,以便我可以设置一些虚拟OrderId,当且仅当通过沙箱测试购买时。

Any help is appreciated. 任何帮助表示赞赏。

I don't know if this will help you, but what I did to differentiate between a test purchase and a real purchase was to use both the orderId and the purchaseToken as keys. 我不知道这是否会对你有所帮助,但我所做的是区分测试购买和实际购买是使用orderId和purchaseToken作为键。

If it is a real purchase, there will be an order ID present that follows the pattern of something like GPA.ORDER_ID. 如果是真正的购买,则会出现一个订单ID,该订单ID遵循GPA.ORDER_ID之类的模式。 If it's a test purchase, you are right there will be no order ID, but there will still be a purchase token that is a long string of random numbers / letters. 如果是测试购买,那么您将没有订单ID,但仍然会有一个购买令牌,这是一长串随机数字/字母。 So I know in my DB if it was a real purchase, the order ID will have GPA.ORDER_ID. 所以我知道在我的数据库中,如果是真正的购买,订单ID将具有GPA.ORDER_ID。 If it doesn't follow that pattern, then it was a test purchase. 如果它不遵循这种模式,那么这是一次测试购买。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM