In my Xamarin Forms 5 app, I'm using the in-app purchase plugin. I'm now trying to verify this purchase in my ASP.NET backend API by calling the AppStore API.
When a purchase goes through, the response object I receive looks like below:
The AppStore API documentation indicates that the request body for the POST
call I need to make should include the following properties:
I'm trying to figure out what I need to send as receipt-data
which is supposed to be of type byte
.
So far, I tried sending the PurchaseToken
property I receive in the response object -- using the In-App Plugin -- see first image above. That failed. I then converted the PurchaseToken
value to a byte array using the following conversion and that failed too.
var byteValue = Encoding.ASCII.GetBytes(purchaseTokenValue);
I keep getting { "status": 21002 }
from AppStore API which apparently means malformed according to this post.
Has anyone called AppStore API for purchase verification using the data from the In-App Billing plugin? I'd appreciate some pointers here. Thanks!
UPDATE:
I also installed the beta version of the plugin (6.3.2 Beta). Even though the response object has changed, I still don't see any data about the receipt e.g. receipt-data
.
The final solution is as follows. First, I upgraded to the latest (pre-release) Beta version of the plugin. In my case that ended up being 6.3.2-beta
.
In the case of iOS, the receipt data does NOT come in the transaction object we get for the purchase. I'm providing the code including the purchase call and platform specific steps so that it's clear for everyone:
// First, make the purchase call and get transaction data
var purchase = await billing.PurchaseAsync(productId, ItemType.Subscription);
// We then handle platform specific steps
if (Device.RuntimePlatform == Device.Android)
{
// Must call AcknowledgePurchaseAsync else the purchase will be refunded
await billing.AcknowledgePurchaseAsync(purchase.PurchaseToken);
}
else if(Device.RuntimePlatform == Device.iOS)
{
// Grab receipt data
var receiptData = CrossInAppBilling.Current.ReceiptData;
}