Sign In Register

How can we help you today?

Start a new topic
Answered

How to get "INAPP_PURCHASE_DATA" and "INAPP_DATA_SIGNATURE" in Unity

Hi!


I have been implementing the In-App system, only using GameSparks plugin, purchasing with currency is working fine, but I have a problem for implementing purchasing with real money with Google Play.


In tutorial,  appears this:


String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA");

String dataSignature = data.getStringExtra("INAPP_DATA_SIGNATURE");


How I am suppose to get that info? I need an external plugin for that? I thought that I could do all of the game using only GameSparks plugin, if I have to use an external plugin for billing, where is the benefit of using GameSparks?


Best Answer

SOOMLA plugin was the solution.


No body knows??

Hi Alejandro

You will need to set up the items you want to sell on your app's google play development account.You must have a google developer account to publish your game to the play store.
You can find more information about in app purchase's on google play here
You can find out about setting up a google developer account here

Thanks
Katie

 

Please, read my question before answer an automatic reply, I´m developer for long time ago and I know how to do that, I need to know what external plugin I can use and how I can use it to get this info:


String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA");

String dataSignature = data.getStringExtra("INAPP_DATA_SIGNATURE");

 Hi Alejandro


Very sorry I misunderstood the question.There are a many  plugins for in app purchase's.If you are using Unity these can be found on the asset store or online on github like OpenIAB.


Thanks

Katie

Thanks for the answer!


I´ve been trying that plugin, but a can´t get it working, when using GooglePlayBuyGoodsRequest I get Error 2, so I´m not getting well the data, even I don´t understand the inexistent documentation of the plugin, its really poor info in the web.

Answer

SOOMLA plugin was the solution.

Hi


We are using Unity In-App services. This returns a UnityEngine.Purchasing.Product when a product has been bought independently if it was for IOS or GooglePlay.


    public class Product

    {

        public bool availableToPurchase { get; }

        public ProductDefinition definition { get; }

        public bool hasReceipt { get; }

        public ProductMetadata metadata { get; }

        public string receipt { get; }

        public string transactionID { get; }

    }


For IOSBuyGoodsRequest we can just use the receipt. Why would we need an extra plugin in order to retrieve the correct parameters to send GooglePlayBuyGoodsRequest?


Shouldn't we just be able to use the receipt as well since Unity returns that for Googleplay?


Thanks

Helana




1 person likes this

I find the documentation for GooglePlayBuyGoodsRequest very incomplete. You can use the receipt and avoid adding a plugin with some extra code, based on the documentation at https://docs.unity3d.com/Manual/UnityIAPPurchaseReceipts.html. The class below will get you INAPP_PURCHASE_DATA and INAPP_DATA_SIGNATURE:

  

class GooglePurchaseData {
	// INAPP_PURCHASE_DATA
	public string inAppPurchaseData;
	// INAPP_DATA_SIGNATURE
	public string inAppDataSignature;

	[System.Serializable]
	private struct GooglePurchaseReceipt {
		public string Payload;
	}
	[System.Serializable]
	private struct GooglePurchasePayload {
		public string json;
		public string signature;
	}

	public GooglePurchaseData(string receipt) {
		try {
			var purchaseReceipt = JsonUtility.FromJson<GooglePurchaseReceipt> (receipt);
			var purchasePayload = JsonUtility.FromJson<GooglePurchasePayload> (purchaseReceipt.Payload);
			inAppPurchaseData = purchasePayload.json;
			inAppDataSignature = purchasePayload.signature;
		} catch {
			Debug.Log("Could not parse receipt: " + receipt);
			inAppPurchaseData = "";
			inAppDataSignature = "";
		}
	}
}

 Here's a sample that you can put in ProcessPurchase:

 

GooglePurchaseData data = new GooglePurchaseData (args.purchasedProduct.receipt);
new GameSparks.Api.Requests.GooglePlayBuyGoodsRequest ()
	.SetSignature (data.inAppDataSignature)
	.SetSignedData (data.inAppPurchaseData)
	.Send ((response) => {
		if (!response.HasErrors) {
			Debug.Log("Successful purchase");
		} else {
			Debug.Log("Purchase error: " + response.Errors.JSON);
		}	
	});

 


4 people like this

Thank you Martin, that's just what I needed!

Hi all,

Thx for the answer,


Just a small question: When trying to use your sample, args in "GooglePurchaseData data = new GooglePurchaseData(args.purchasedProduct.receipt);" is underlined in red.

It seems not declared? I missed something?


Thx in advance for your answer,

Nico.

Hi Nico,


args refers to the argument passed to ProcessPurchase, see the Unity documentation here:

https://docs.unity3d.com/ScriptReference/Purchasing.IStoreListener.ProcessPurchase.html


Hope that helps,

Vicky

I tried the Martin's code but when I run it in the editor (as Android) it gives me the signature and the data both null. Should I run it on mobile?

Thanks Martin. It worked with Codeless IAP.

Thanks Martin for the code.

I used it but I get this error:


{"storeError":"java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: IOException: Short read of DER length","verificationError":"2"}


I logged the inAppDataSignature and inAppPurchaseData and everything look OK.


I know "verificationError":"2 means The signature does not match the signed data. How can I fix this?


Thanks

Kaan



Login to post a comment