How to get "INAPP_PURCHASE_DATA" and "INAPP_DATA_SIGNATURE" in Unity
A
Alejandro Barceló
started a topic
about 7 years ago
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.
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?
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
A
Alejandro Barceló
said
about 7 years ago
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:
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
A
Alejandro Barceló
said
about 7 years ago
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.
A
Alejandro Barceló
said
about 7 years ago
Answer
SOOMLA plugin was the solution.
H
Helana Santos
said
almost 6 years ago
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
M
Martin Wellman
said
almost 6 years ago
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);
}
});
5 people like this
V
Vicky Smalley
said
almost 6 years ago
Thank you Martin, that's just what I needed!
C
Castaing Nicolas
said
over 5 years ago
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.
V
Vicky Smalley
said
over 5 years ago
Hi Nico,
args refers to the argument passed to ProcessPurchase, see the Unity documentation here:
{"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?
Alejandro Barceló
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?
SOOMLA plugin was the solution.
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstAlejandro Barceló
No body knows??
Customer Support
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
Alejandro Barceló
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");
Customer Support
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
Alejandro Barceló
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.
Alejandro Barceló
SOOMLA plugin was the solution.
Helana Santos
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
Martin Wellman
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:
Here's a sample that you can put in ProcessPurchase:
5 people like this
Vicky Smalley
Thank you Martin, that's just what I needed!
Castaing Nicolas
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.
Vicky Smalley
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
Andrea Marchetti
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?
Kleber Silva
Thanks Martin. It worked with Codeless IAP.
Kaan Tosunoglu
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
-
Documentation Notes
-
Design issues with user events
-
Using NoSQL
-
Runtime Collections vs Metadata Collections
-
Anonymous authentication from browser app
-
Modules
-
Movement With Unity
-
Problem with url parameters for downloadables
-
Querying NoSql GameSparks database
-
Challenge accesType
See all 2487 topics