question

ritsthedeveloper avatar image
ritsthedeveloper asked

Getting INVALID_SKU in grantSubscriptionPurchase() in IAP version 2

I am working on implementing subscription using Amazon IAP version 2. I am referring to the sample subscription application provided by them, for implementation. Currently, I am testing in Sandbox environment. For this I have set up 1. Amazon App tester in my device. 2. placed amazon.sdktester.json file in "mnt/sdcard" directory. Currently in my json I have only one subscription to be purchased. Hence I am not using the enum MySKU provided in the sample, instead i am simply using a SKU as string. My SKU at Amazon developer portal, the json I am using for testing, and in my code is same. When I make a purchase request, I send the child sku in the purchase request as shown in sample. The request status I get in response in onPurchaseResponse(),is SUCCESSFUL. Hence i send the receipt id and other data to my backend server for verification. After receipt verification at backend server when I try to grant the subscription purchase, I get INVALID_SKU. When I print the value of SKU, it gives me Parent SKU. And in this case I have to call PurchasingService.notifyFulfillment(receipt.getReceiptId(), FulfillmentResult.UNAVAILABLE); Could anyone please explain what exactly is going on here?
iap
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Hi, Can you please post full log? Thanks.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ritsthedeveloper avatar image
ritsthedeveloper answered
Hi, I don't get any exception or error, however I am posting the snipppet where I face this problem. This method is there in SampleIapManager, in the IAP version 2 sample provided by Amazon. private void grantSubscriptionPurchase(final Receipt receipt, final UserData userData) { final MySku mySku = MySku.fromSku(receipt.getSku(), userIapData.getAmazonMarketplace()); // Verify that the SKU is still applicable. if (mySku != MySku.MY_MAGAZINE_SUBS) { Log.w(TAG, "The SKU [" + receipt.getSku() + "] in the receipt is not valid anymore "); ///-------------------I get this line in logs. // if the sku is not applicable anymore, call // PurchasingService.notifyFulfillment with status "UNAVAILABLE" PurchasingService.notifyFulfillment(receipt.getReceiptId(), FulfillmentResult.UNAVAILABLE); return; } try { // Set the purchase status to fulfilled for your application saveSubscriptionRecord(receipt, userData.getUserId()); PurchasingService.notifyFulfillment(receipt.getReceiptId(), FulfillmentResult.FULFILLED); } catch (final Throwable e) { // If for any reason the app is not able to fulfill the purchase, // add your own error handling code here. Log.e(TAG, "Failed to grant entitlement purchase, with error " + e.getMessage()); } } Thanks
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Bipin@Amazon avatar image
Bipin@Amazon answered
Compare the SKU which you have hardcoded to the one in the sample MY_MAGAZINE_SUBS("com.amazon.sample.iap.subscription.mymagazine", "US"); In the grantSubscriptionPurchase method there is a if condition which verify that the SKU is still applicable
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ritsthedeveloper avatar image
ritsthedeveloper answered
I have hardcoded child SKU in my code and sending that in purchase request. However in sample code I never saw child SKU mentioned . MY_MAGAZINE_SUBS("com.amazon.sample.iap.subscription.mymagazine", "US"); this is also parent SKU value. So I am confused , which value to be hardcoded in application. In the grantSubscriptionPurchase method we get parent SKU.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
You are supposed to send the parent SKU in the purchase request. Please refer the below link to understand the flow better https://developer.amazon.com/public/apis/earn/in-app-purchasing/docs-v2/implement-consumables-entitlements-and-subscriptions-in-iap-2.0#10.%20Implementing%20the%20Purchasable Basically, you will be dealing with the parent SKU always. To know the subscription period (corresponding to children of the parent sku) of the purchased subscription item, you should look at getCancelDate() of the receipt.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.