简体   繁体   中英

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.

In android documentation, I have read that order Id will be blank for test purchases. However, my server will not accept blank order 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 .

I checked the JSON retrned after purchase in which only OrderId is blank and rest of the feilds like signature, token are available. 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.

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.

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.

If it is a real purchase, there will be an order ID present that follows the pattern of something like 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. So I know in my DB if it was a real purchase, the order ID will have GPA.ORDER_ID. If it doesn't follow that pattern, then it was a test purchase.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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