question

andreighinea1 avatar image
andreighinea1 asked

How could I setup Steam Sandbox mode in unity?

I'm trying to setup steam iap for a unity game, but I don't know how could I setup steam sandbox mode (if that is the problem)

I've uploaded the game on steam, and I'm getting the steam gui, but after I authorize the payment I receive this error from the steam callback: "Invalid input parameters". I thought it might be because my balance is 0€.

unity3dIn-Game Economy
1 comment
10 |1200

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

andreighinea1 avatar image andreighinea1 commented ·

Here's how I register the callback:

void Start()
{
	if (SteamManager.Initialized)
	{
		m_MicroTxnAuthorizationResponse = Callback<MicroTxnAuthorizationResponse_t>.Create(OnMicroTxnAuthorizationResponse);


		PlayFabClientAPI.LoginWithSteam(new LoginWithSteamRequest
		{
			CreateAccount = true,
			SteamTicket = GetSteamAuthTicket()
		}, OnComplete, OnFailed);
	}
}


private void OnMicroTxnAuthorizationResponse(MicroTxnAuthorizationResponse_t pCallback)
{
	text.text = "Here";

	if (pCallback.m_bAuthorized == 1)
	{
		text.text += "\n Authorized Payment";

		Debug.Log("Authorized Payment");

		ConfirmPurchase(pCallback.m_ulOrderID.ToString());
	}
	else
	{
		text.text += "\n Failed to authorize payment";
		// Player didn't authorize the payment
		Debug.Log("Failed to authorize payment");
	}
}

private void ConfirmPurchase(string orderId)
{
	PlayFabClientAPI.ConfirmPurchase(new ConfirmPurchaseRequest()
	{
		OrderId = orderId
	}, result =>
	{
		text.text += "\n CONFIRM PURCHASE";
		Debug.Log("CONFIRM PURCHASE");
	}, error =>
	{
		text.text += "\n PURCHASE FAILED: " + error.ErrorMessage;
		Debug.Log("PURCHASE CONFIRM FAILED: " + error.ErrorMessage);
	});
}
0 Likes 0 ·
Andy avatar image
Andy answered

Is the orderId you're passing into the ConfirmPurchase call the same one you received in the response from StartPurchase? It looks like you're just throwing it away after passing it into PayForPurchase. If those ids don't align, you'll get an error.

2 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.

brendan avatar image brendan commented ·

Yep, I should have spotted that in the first post - the callback's m_ulOrderID is not the same thing as the Order ID in PlayFab. If you use the one from the StartPurchase flow, you should be fine.

0 Likes 0 ·
andreighinea1 avatar image andreighinea1 commented ·

Thank you, now it works perfectly. It makes much more sense to pass the order id from PlayFab than the one from steam, because it's a function that calls the PlayFab API.

0 Likes 0 ·
brendan avatar image
brendan answered

There's a "Use Steam Payments sandbox endpoint for test transactions" option on the Steam add-on page. Can you make sure that's enabled?

Also, can you share the full flow? How are you calling StartPurchase and PayForPurchase, and can you confirm that the Order ID you're using in ConfirmPurchase is the one you got from that flow?

Finally, you're saying you get "Invalid input parameters" from the Steam callback, which would imply you're getting it from Steam in the MicroTxnAuthorizationResponse_t. Can you also confirm where that's showing up in your flow, if you meant something else?

10 |1200

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

andreighinea1 avatar image
andreighinea1 answered

Yes, the "Use Steam Payments sandbox endpoint for test transactions" option is enabled.

The error comes from the "ConfirmPurchase" function. It enters the error function and it gives me the error message "Invalid input parameters"

Here's my full code:

protected Callback<MicroTxnAuthorizationResponse_t> m_MicroTxnAuthorizationResponse;
public Text text;
	
public string GetSteamAuthTicket()
{
	byte[] ticketBlob = new byte[1024];
	uint ticketSize;


	HAuthTicket hTicket = SteamUser.GetAuthSessionTicket(ticketBlob, ticketBlob.Length, out ticketSize);
		
	Array.Resize(ref ticketBlob, (int)ticketSize);
		
	StringBuilder sb = new StringBuilder();
	foreach (byte b in ticketBlob)
	{
		sb.AppendFormat("{0:x2}", b);
	}
	return sb.ToString();
}


void Start()
{
	if (SteamManager.Initialized)
	{
		m_MicroTxnAuthorizationResponse = Callback<MicroTxnAuthorizationResponse_t>.Create(OnMicroTxnAuthorizationResponse);


		PlayFabClientAPI.LoginWithSteam(new LoginWithSteamRequest
		{
			CreateAccount = true,
			SteamTicket = GetSteamAuthTicket()
		}, OnComplete, OnFailed);
	}
}


private void OnMicroTxnAuthorizationResponse(MicroTxnAuthorizationResponse_t pCallback)
{
	text.text += "\nID3:" + pCallback.m_ulOrderID.ToString();


	if (pCallback.m_bAuthorized == 1)
	{
		text.text += "\nAuthorized Payment";


		Debug.Log("Authorized Payment");


		ConfirmPurchase(pCallback.m_ulOrderID.ToString());
	}
	else
	{
		text.text += "\nFailed to authorize payment";
		// Player didn't authorize the payment
		Debug.Log("Failed to authorize payment");
	}
}


private void ConfirmPurchase(string orderId)
{
	PlayFabClientAPI.ConfirmPurchase(new ConfirmPurchaseRequest()
	{
		OrderId = orderId
	}, result =>
	{
		text.text += "\nCONFIRM PURCHASE";
		Debug.Log("CONFIRM PURCHASE");
	}, error =>
	{
		text.text += "\nPURCHASE FAILED: " + error.ErrorMessage;
		Debug.Log("PURCHASE CONFIRM FAILED: " + error.ErrorMessage);
	});
}


public void OnGUI()
{
	GUIStyle customTextSize = new GUIStyle("button");
	customTextSize.fontSize = 30;


	float count = 0.0f;
	float itemOriginX = 40.0f;
	float itemWidth = Screen.width / 2;
	float itemStartY = 60.0f;
	float itemHeightOffset = 120.0f;
	float itemHeight = 90.0f;


	if (GUI.Button(new Rect(itemOriginX, itemStartY + (count * itemHeightOffset), itemWidth, itemHeight), "Log In", customTextSize))
	{
		if (SteamManager.Initialized)
		{
			// Execute PlayFab API call to log in with steam ticket
			PlayFabClientAPI.LoginWithSteam(new LoginWithSteamRequest
			{
				CreateAccount = true,
				SteamTicket = GetSteamAuthTicket()
			}, OnComplete, OnFailed);
		}
	}


	++count;
	if (GUI.Button(new Rect(itemOriginX, itemStartY + (count * itemHeightOffset), itemWidth, itemHeight), "Buy", customTextSize))
	{
		Buy();
	}
}


void Buy()
{
	PlayFabClientAPI.StartPurchase(new StartPurchaseRequest()
	{
		CatalogVersion = "1.0",
		StoreId = "purchase_store",
		Items = new List<ItemPurchaseRequest>() {
				new ItemPurchaseRequest() {
					ItemId = "purchase",
					Quantity = 1,
					Annotation = "Purchased full game"
				}
			}
	}, result => {
		text.text += "\nID1:" + result.OrderId.ToString();
		PlayFabClientAPI.PayForPurchase(new PayForPurchaseRequest()
		{
			OrderId = result.OrderId,
			ProviderName = "Steam",
			Currency = "RM"
		},
		OnPurchaseComplete,
		OnPurchaseFailed);
	}, error => {
		Debug.Log("Purchase failed1: " + error.ErrorMessage);
	});
}


void OnPurchaseComplete(PayForPurchaseResult startPurchaseResult)
{
	Debug.Log("PayForPurchase OnPurchaseComplete");
	text.text += "\nID2:" + startPurchaseResult.OrderId.ToString();
}


void OnPurchaseFailed(PlayFabError playFabError)
{
	Debug.Log("Purchase failed2: " + playFabError.ErrorMessage);
}


// Utility callbacks to log the result
private void OnComplete(LoginResult obj)
{
	Debug.Log("Success!");
}


private void OnFailed(PlayFabError error)
{
	Debug.Log("Failed: " + error.GenerateErrorReport());
}
10 |1200

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

zaminfareed76 avatar image
zaminfareed76 answered

i wanna switch to sandbox to real transaction how i do this?? when i make build it give sand box i need real what i can do??

10 |1200

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

kakatoto avatar image
kakatoto answered

Hey

@andreighinea1

and , Sorry I arrive very late but I am trying to create a transaction system with steamworks and Godot. I use C#. I am tryong to POST a a InitTxn request with the sandbox. I am trying to do taht for several days but i dont receive the confirm order. I dont see what is wrong with my post request. Do you have an example of a POST request to do the

InitTxn ?

Thanks a lot.

,

Hey

@andreighinea1

and , Sorry I arrive very late but I am trying to create a transaction system with steamworks and Godot. I use C#. I am tryong to POST a a InitTxn request with the sandbox. I am trying to do taht for several days but i dont receive the confirm order. I dont see what is wrong with my post request. Do you have an example of a POST request to do the

InitTxn ?

Thanks a lot.

10 |1200

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

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.