question

Justin Enayat avatar image
Justin Enayat asked

Steam purchase works, but also throws an error?

I set up my microtransactions system with Steam integration. Everything works, the item is added to the inventory, and the funds are withdrawn (using sandbox mode, the Value To Date in my player profile updates accordingly). I'm just concerned because it also throws an error. Usually, I wouldn't care since it appears to work, but I want to be thorough since we're dealing with people's money here. When the purchase goes through, these are the two console entries that pop up in this order:

Purchase error:Invalid input parameters


Purchase confirmed

Here is (all the relevant code in) my script:

protected Callback<MicroTxnAuthorizationResponse_t> m_MicroTxnAuthorizationResponse;
string transientOrderID;


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


    public void StartPurchase()
    {
        PlayFabClientAPI.StartPurchase(new StartPurchaseRequest()
        {
            CatalogVersion = "CloutCoinBundles",
            Items = new List<ItemPurchaseRequest>()
            {
                new ItemPurchaseRequest()
                {
                    ItemId = "1000CC",
                    Quantity = 1,
                    Annotation = "Purchased via in-game store"
                }
            }
        }, result =>
        {
            PayForPurchase(result);
        }, error =>
        {
            Debug.Log("Start purchase error" + error.ErrorMessage);
        });
    }


    void PayForPurchase(StartPurchaseResult purchase)
    {
        PlayFabClientAPI.PayForPurchase(new PayForPurchaseRequest()
        {
            OrderId = purchase.OrderId,
            ProviderName = "Steam",
            Currency = "RM"
        }, result =>
        {
            transientOrderID = purchase.OrderId;
        }, error =>
        {
            Debug.Log("Pay for purchase error:" + error.ErrorMessage);
        });
    }


    void OnMicroTxnAuthorizationResponse(MicroTxnAuthorizationResponse_t callback)
    {
        if (callback.m_bAuthorized == 1)
            ConfirmPurchase(transientOrderID);
        else
            Debug.Log("Not authorized");
    }


    void ConfirmPurchase(string purchase)
    {
        PlayFabClientAPI.ConfirmPurchase(new ConfirmPurchaseRequest()
        {
            OrderId = purchase
        }, result =>
        {
            Debug.Log("Purchase confirmed");
        }, error =>
        {
            Debug.Log("Purchase error:" + error.ErrorMessage);
        });
        transientOrderID = "";
    }
apisIn-Game EconomypricingPlayer Inventory
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.

Justin Enayat avatar image Justin Enayat commented ·

Oh, forgot to ask, is it possible to add a playstream event on purchase confirmation?

0 Likes 0 ·

1 Answer

·
Sarah Zhang avatar image
Sarah Zhang answered

The built-in PlayStream event player_realmoney_purchase will be triggered when a player makes the real money purchase. But please note the failed purchase confirmation won’t trigger the event. For your case, the “Invalid input parameters” error may be caused by the empty OrderId, could you please debug the script to check whether the API ConfirmPurchase is called twice?

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.

Justin Enayat avatar image Justin Enayat commented ·

You're right, it does get called twice. I just put this in to check:

    void OnMicroTxnAuthorizationResponse(MicroTxnAuthorizationResponse_t callback)
    {
        if (callback.m_bAuthorized == 1)
        {
            ConfirmPurchase(transientOrderID);
            Debug.Log("Authorized");
        }
}

And I get 2 "authorized" console entries. Any idea why?

0 Likes 0 ·
Sarah Zhang avatar image Sarah Zhang Justin Enayat commented ·

We are not sure why it happened. Could you please provide more details, for example, how you wrote the MicroTxnAuthorizationResponse_t?

0 Likes 0 ·

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.