Make a store for my game using playfab

i want to make a store, sort of like a battle pass, but i can’t figure out how. i have tried to use playfab, but the javascript tutorials on playfab do not help me at all. how would i add my playfab store to my game?

Make a callback then a body and head constructor and then send it. You can customize the following in any way you need.

function buyitemcall(response,error){
  if(error){
    console.log(error);
    alert("Not Enough Random Tokens!");
  }else{
    var data= response.data;
    var items = data.Items;
    for (i of items){
      alert("Purchased "+i.DisplayName+" for "+i.UnitPrice+" Random Tokens");
    }
  }
}

Body

        var cost=100;
        var itemid = "rainbowskin";
        var auth = {"X-Authorization":session ticket from login};
        var body = {"ItemId":itemid,"Price":cost,"VirtualCurrency":"RT","CatalogVersion":"SKINS"};

Then send it

PlayFabClientSDK.PurchaseItem(body,buyitemcall,extraHeaders=auth);

Make sure that you have the title id set in the body or settings using this PlayFab.settings.titleId = “titleid”;
I would also suggest that you read the playfab docs for whatever type of sdk you are using and also make sure that you have the sdk downloaded to your game for javascript or linked through the cdn in external scripts.

1 Like

thanks! i will give it a try!

i ran it, but i got an error: ReferenceError: session is not defined

Make sure that you store the session ticketfrom the login example login callback

var logincallback=function(response,error){
if(error){
console.log(error)
}else{
var data=response.data;
localStorage.SessionTicket=data.SessionTicket;
//Your code here
}
}

ok