Forum Discussion

Blenchik's avatar
Blenchik
MHCP Partner
7 months ago
Solved

In-World Purchase (IWPSeller) Gizmo question

I have been experimenting with the in world shop gizmo with the commerce mechanics. While the World shop itself works fine, I'm confused about the IWPSeller gizmo.

When putting the IWPSeller gizmo into my world and configuring it to a single item and setting it as a trigger/button.

I get this menu pop-up when triggering the interaction with the IWPSeller:

I don't see any options to purchase the single item in-world and it just tells me to load it on a VR headset. Is this intentions? Are we only supposed to use this Gizmo for VR worlds?

Note: I am testing this within the Horizon World Desktop editor.

10 Replies

  • It will work on mobile and VR but yes it seems like it doesn't show up when previewing on desktop or the web. You'll need to connect the purchasing via scripting. Documentation is here. Though I've been having trouble testing it. It inconsistently works and it is hard to tell if it is Horizon Worlds being buggy or bad implemenation on my part. 
    https://developers.meta.com/horizon-worlds/learn/documentation/mhcp-program/monetization/meta-horizon-worlds-inworld-purchase-guide

  • Depending on what you are going for, this video tutorial and provided script from Vidyuu may be helpful. 
    This tutorial is particularly useful for a single consumable that is set to auto-use.
    Consumables used from the Horizon Worlds inventory would be handled differently as would durables and packs (which have some special sku variant that I haven't identified yet). 
    https://www.youtube.com/watch?v=WQpkSzU20xI

  • Ben.SH's avatar
    Ben.SH
    Community Manager

    IWPs only work on VR and Mobile, you will not be able to make any purchases or tests using the web client.

  • The code in the attached youtube link for IWPSeller gizmo does not work today. Could anyone provide a code that actually works. I have tried different things but none of them trigger the Codeblock OnItemPurchase Event when I buy or cancel. I tried listening for Local/Network Broadcast, listening to the entity, including the gizmo entity. Nothing seems to work.

    • OverTheEdge's avatar
      OverTheEdge
      MHCP Member

      Can you describe more specifically what you are trying to do? In my case I had trouble getting "Item Packs" to work but I was able to get sale of individual items to work. Is this what you might be having trouble with? 

      The problem in the case of "Item Packs" is that the SKU did not end up matching the packs so the sale would fail. There is probably a way around this by first using script to identify the actual SKU of that IWP item pack. 

      However, my approach was just to fall back on the sale of an individual auto-consumed In World Purchase item that upon purchase would add 10 of the consumable (effectively the same as an item pack). This worked using the youtube video for reference. 

      edit: added working script sample

    • OverTheEdge's avatar
      OverTheEdge
      MHCP Member
      import * as hz from "horizon/core";
      
      export class AutoConsumeHandler extends hz.Component<typeof AutoConsumeHandler> {
        static propsDefinition = {
        pvarName: { type: hz.PropTypes.String, default: "YOUR_VARIABLE_GROUP_NAME:YOUR_PVAR NAME" },// Replace with actual variable group and persitance variable name
      };
        
      preStart() {
          this.connectCodeBlockEvent(this.entity, hz.CodeBlockEvents.OnItemPurchaseComplete, (player, item, success) => { this.purchase(player, item, success); });
        }
        
      start() {}
      
        //this works for auto-consumed items but the naming for the sku does not end up matching for IWP packs so we fall back on making our own packs
        purchase(player: hz.Player, item: string, success: boolean) {
      
          switch (item) {
            case 'YOUR_IWP_ITEM_SKU': // Replace with actual item SKU
              if (success) {
                console.log('Purchase succeeded for item: ' + item);
      
                const current = this.world.persistentStorage.getPlayerVariable(player, this.props.pvarName) ?? 0;//accounts for undefined - when a user hasn't scored yet
                const playerBalance = current + 10;
                this.world.persistentStorage.setPlayerVariable(player, this.props.pvarName, playerBalance);
              }
              else {
                console.log('Purchase failed for item: ' + item);
              }
              break;
            case 'ANOTHER_IWP_ITEM_SKU': // Replace with actual item SKU - The below is just adding 10 to the PVAR same as above so you'll want to do something different if you implement a second case. 
              if (success) {
                console.log('Purchase succeeded for item: ' + item);
                
                const current = this.world.persistentStorage.getPlayerVariable(player, this.props.pvarName) ?? 0;//accounts for undefined - when a user hasn't scored yet
                const playerBalance = current + 10;
                this.world.persistentStorage.setPlayerVariable(player, this.props.pvarName, playerBalance);
              }
              else {
                console.log('Purchase failed for item: ' + item);
              }
              break;
            default:
              console.log('Case for item not found: ' + item);
              break;
          }
        }
      }
      
      hz.Component.register(AutoConsumeHandler);

       

      • izukingz's avatar
        izukingz
        MHCP Partner

        OverTheEdge​ , thanks for replying. Yes I am referring to the exact code you pasted above. I just copied your code and replaced with my auto-consumed sku. And when I try to purchase or cancel, the purchase callback is not called. A related issue I am currently seeing is that Quests callback codeblocks are not called when  setAchievementComplete is set for a player. Can you verify that this works for you currently. Could be broken?