I have been recently studying code for In-App-Billing v2. And have found some issues with it.
I have earlier implemented In-App-Billing but wish to upgrade to subscription. On my research I found that Purchase token is recieved along with the JSON(Signed data) on successful purchase for subscription.
The demo’s Security.java on successful verification of signature parses Json however the parsing of element Purchase-token is missing here.
JSONObject jElement = jTransactionsArray.getJSONObject(i);
int response = jElement.getInt("purchaseState");
PurchaseState purchaseState = PurchaseState.valueOf(response);
String productId = jElement.getString("productId");
String packageName = jElement.getString("packageName");
long purchaseTime = jElement.getLong("purchaseTime");
String orderId = jElement.optString("orderId", "");
String notifyId = null;
// purchaseToken part that I have added
String purchaseToken = jElement.optString("purchaseToken", "");
I haven’t yet run the code since subscription doesn’t have test product-ids and requires actual purchase.What I want to know is this token be parsed here or is the sample code provided has this part correctly implemented.
Vincent, that is correct. You have to modify Security.java as well as BillingService.java and ResponseHandler.java if you need the purhcaseToken to be validated.
Here it is:
Security.java:
Now in VerifyPurchase:
BillingService.java:
In purchaseStateChanged, modify:
ResponseHandler.java:
Finally, change the definition of purchaseResponse to:
Here you can make your app related logic changes as you here will have the purchaseToken.
If everything works, please accept!