Facepunch.Steamworks Wiki

Revision Difference

Item_Store_Cart#523914

<cat>code.inventory</cat>⤶ <title>Item Store Cart</title>⤶ ⤶ <upload src="1/8d7b609ca2ece75.png" size="487095" name="image.png" />⤶ ⤶ ⤶ ```⤶ ⤶ //⤶ // Our cart item⤶ //⤶ public List<InventoryDef> Cart = new List<InventoryDef>();⤶ ⤶ ⤶ public void Start()⤶ {⤶ //⤶ // Tell this callback to tell us when something has been purchased⤶ //⤶ SteamUser.OnMicroTxnAuthorizationResponse += OnPurchaseFinished;⤶ }⤶ ⤶ //⤶ // Add an item to our cart⤶ //⤶ public void AddToCart( InventoryDef item )⤶ {⤶ Cart.Add( item );⤶ }⤶ ⤶ //⤶ // Called when they want to check out⤶ //⤶ public async Task CheckoutAsync()⤶ {⤶ ShowPurchaseInProgressScreen();⤶ ⤶ // This tries to open the steam overlay to commence the checkout⤶ var result = await Steamworks.SteamInventory.StartPurchaseAsync( Cart.ToArray() );⤶ ⤶ Log( $"Result: {r.Value.Result}" );⤶ Log( $"TransID: {r.Value.TransID}" );⤶ Log( $"OrderID: {r.Value.OrderID}" );⤶ }⤶ ⤶ //⤶ // Called from the callback SteamUser.OnMicroTxnAuthorizationResponse⤶ //⤶ private void OnPurchaseFinished( AppId appid, ulong orderid, bool success )⤶ {⤶ HidePurchaseInProgressScreen();⤶ ⤶ if ( success )⤶ {⤶ // Purchase was successful⤶ }⤶ else⤶ {⤶ // They probably pressed cancel or something⤶ }⤶ }⤶ ⤶ ```⤶ ⤶