question

Niall Muldoon avatar image
Niall Muldoon asked

Unity Editor Test Purchase - Best Practice

H,

I have successfully setup real money iAPs for virtual currency on Android and iOS. The implementation uses UnityIAP, receipt validation and PlayFab bundles to award the currency on the server. This is all great!

I would now like to be able to test the client code surrounding my real money iAPs without having to build to device. I need the code paths to be as similar as possible between the Unity Editor and a device build.

When making a purchase in the Unity Editor UnityIAP will accept a valid item purchase request without requiring any payment, it just fires ProcessPurchase (just like on device when the iAP has actually been purchased). On device I then call PlayFabClientAPI.ValidateGooglePlayPurchase() or similar, which verifies the receipt and awards the currency automatically.

What I think I need is a way of awarding the player with the currency based off of this fake Unity Editor purchase, essentially something like PlayFabClientAPI.ValidateUnityEditorPurchase() that is somehow secure from being called from real devices...

I have created my own pretend receipt validation function intended to only be used by the Unity Editor (that doesn't actually validate anything!) using CloudScript and GrantItemsToUser, it takes the bundle item ID as the args parameter. This seems very insecure to me though as a hacked device client could potentially route all receipt validation calls to this piece of CloudScript!

handlers.EditorGrantItem = function(args)
{
	var itemID = null;
	if (args && args.itemID)
	{
		log.info("Attempting to grant item: " + itemID);

		itemID = args.itemID;
  
		var grantItemResult = server.GrantItemsToUser({
			PlayFabId: currentPlayerId,
			CatalogVersion: "iAP",
			ItemIds: [itemID]
		});
      
		return grantItemResult;
	}
  
	return [];
}

Is there a way to make this more secure? Perhaps I'm just going about this the wrong way?

Thank you,

Niall

unity3dCloudScriptIn-Game Economy
10 |1200

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

1 Answer

·
Seth Du avatar image
Seth Du answered

The thing is you have to validate the transaction in the Cloud Script before you grant the item or virtual currency.

As I notice in your codes, it is just a simple granting action, which is very unsafe. There are 3 main things you should implement in your Cloud Script, validating the transaction, find out the items user has traded, grant the item(remove related VC if needed). If it was Google Play service, there will be a external secure sever to validate the transaction. Server to server validation is far more safe. The transaction will generate a receipt that can tell the transaction status and it can be used for validation. There is no very safe “fake Unity Editor purchase” way and you may have to build to your device and go through the process. Please see the document here: https://blog.playfab.com/blog/show-me-money-receipt-validation-ios-and-android.

We also recommend you to send a thread on Unity or Android/iOS community forum where you can get helps from other perspectives.

5 comments
10 |1200

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

Niall Muldoon avatar image Niall Muldoon commented ·

Hi

Thanks for the reply

AsI mentioned I already have receipt validation flows setup for Android and iOS, I am just looking for a way to easily test things in the editor that make use of as much of the same code as possible. It decreases iteration time and makes fixing bugs a lot easier.

Perhaps it would be useful to have a development section of CloudScript that is not available in live builds of the game. The editor alone could have a secret key that is used to access this restricted section.

I'm surprised that this isn't something that is already possible given that PlayFab is being used in so many games. Do people really not have the desire for this kind of behaviour?

Niall

0 Likes 0 ·
brendan avatar image brendan Niall Muldoon commented ·

In general, developers use separate Title IDs for the development and test instances of their titles. You can use the specific revision option in the ExecuteCloudScript call to make a call to a specific revision, rather than the live one, but why are you doing testing that way? The common use case for testing iOS/Google receipts is to generate sandbox receipts.

0 Likes 0 ·
Niall Muldoon avatar image Niall Muldoon brendan commented ·

Hi Brendan,

I'm not testing the receipt validation in this way.

I'm trying to mimic the device code paths in the editor as closely as possible for testing and debugging other areas of the game that rely on the awarding of currency via PlayFab bundles (on device they cost real money).

I'm thinking of scenarios like triggering the fanfare that occurs after you make a real money purchase. I would like the whole team to be able to work with the game in the editor just as they would a real device build.

I have thought about having them access the backend and editing player currency balances but that sounds dangerous. Creating a custom tool using the admin API or similar to change their VC balance sounds clunky. Changing currency balances outside the game also means they cannot test the purchase flows properly. Imagine an artist changing a fanfare icon, they want to see it in context but they have to do a device build, that seems overkill and would hamper productivity.

How feasible is using a separate TitleID in practice?

*Continued below*

0 Likes 0 ·
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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