Quantcast
Jump to content


Integrating Samsung IAP in Your Unity Game


Recommended Posts

2021-05-11-01-banner.jpg

The Galaxy Store is one of the top app stores to sell your Android games in many different countries. You can also sell various in-app purchase (IAP) items inside your games using the Samsung IAP SDK. As many of you now use the Unity engine to develop your games, Samsung has introduced a Unity plugin for the Samsung IAP SDK that enables you to implement IAP features. Follow the steps outlined in this blog to easily implement the Unity plugin into your project and utilize the Samsung IAP functionalities.

Prerequisites

It is assumed you are already familiar with the Samsung IAP procedure. If not, please read the IAP Helper programming guide carefully before proceeding further. After that, download the Samsung IAP Unity plugin package and go through its documentation. To avoid compatibility issues, make sure you meet the system requirements.

There are three types of IAP items:

  1. Consumable: can be used only one time and re-purchasable
  2. Non-consumable: can be used any number of times and not re-purchasable
  3. Subscription: can be used any number of times while it is active

For this example, we have developed a basic coin collecting game in Unity for Android and added UI buttons that allow users to buy IAP items (consumable and non-consumable), and a subscription. The “Buy Super Jump” button initiates purchasing a super jump item from the Galaxy Store using the Samsung IAP SDK. Super jump is a consumable item which enables the player to jump higher than normal. Similarly, the “Upgrade Player” button initiates purchasing a player upgrade, which is a non-consumable item. This blog only covers consumable and non-consumable purchases, we’ll discuss subscriptions in a future blog.


2021-05-11-01-01.jpgFigure 1: Preview of the sample game developed in Unity.


Note: You are required to develop your game/application in Unity beforehand to integrate the IAP Unity plugin into it.

Integrate the Samsung IAP Unity plugin

After creating the game in Unity, you need to enable Samsung IAP functionalities in your project. Follow the steps below:

  1. Import the Samsung IAP Unity plugin package into the project. In Unity, click Assets -> Import Package -> Custom Package and select the downloaded plugin package.
  2. You can now see the Plugins folder under your Assets folder and the “SamsungIAP.cs” script at Assets/Plugins/Script.
  3. Copy or move the “SamsungIAP.cs” script into the default scripts folder (where all the scripts are kept together) of your project so that other scripts can access it easily. If you don’t already have a scripts folder, create a new one and keep all your project scripts together along with “SamsungIAP.cs”.
  4. Create an empty game object in the Hierarchy tab and drag-and-drop the “SamsungIAP.cs” script onto it. In our sample project, we have renamed the game object as “SamsungIAP”.
  5. Click on the “SamsungIAP” game object and check whether the IAP functionality is enabled in the Inspector, as shown below:

2021-05-11-01-02-v2.jpgFigure 2: Samsung IAP is enabled for the project.


Set the IAP operation mode

IAP supports three operational modes. The production mode is for enabling billing for item purchases and the other two are for testing IAP functions without billing the game users for item purchases. The default operation mode is set to OPERATION_MODE_TEST with the return value as Success, but you can set the return value to Failure instead, or switch to OPERATION_MODE_PRODUCTION by checking (√) the Production Build checkbox in the Inspector as shown in figure 2. You can learn more about the IAP operation modes and how they work from here.

Register the game and IAP items in the Seller Portal

To process/test the Samsung IAP operations, both your game and any IAP items need to be registered in the Seller Portal. Follow the steps below:

  1. Ensure you have switched the platform of your game to Android and the package name is different from the apps registered in other app stores. You can rename the package name of your project from Player Settings -> Other Settings.
  2. Save your Unity project and build the APK file. In Unity, go to File -> Build Settings and then click the Build button.
  3. Follow the steps listed in Register an app and in-app items in Seller Portal and complete the registration of your game and IAP items accordingly. For our sample game, we have registered a consumable and a non-consumable item with the IDs “BuySuperJump” and “BuyUpgradedPlayer” respectively. Keep the item IDs in mind as they will be required when initiating the purchases.
  4. You can add testers (non-licensed and licensed) in the Binary tab of the Seller Portal while registering your game in the manner covered in the previous step. Licensed testers are not be charged for purchasing any IAP items. You can register the licensed testers in your Seller Portal profile. See IAP Testing for more information.

Get previously purchased items

Make sure to retrieve any previously purchased non-consumable and unconsumed items every time the user starts the game. Use the GetOwnedList() method of the IAP plugin to get information about the items the user has already purchased. However, please note there is a script “player.cs” in our project which is added to the main player game object as a component. From now on we will be editing the codes into this “player.cs” script to enable all the Samsung IAP functions for this project. Follow the steps below:

  1. Add the following line at the beginning to access the Samsung IAP libraries in this script.
    using Samsung; 
    
  2. Call the GetOwnedList() method whenever the game launches, by adding the following line at the beginning of the Start() method. Learn more about the GetOwnedList() method here.
  3. After the processing of the GetOwnedList() method is completed, the OnGetOwnedList callback is triggered, which receives information about the specified purchased items and API call processing. We need to implement this callback method under the same class as in the following;
    void OnGetOwnedList(OwnedProductList _ownedProductList){
            if(_ownedProductList.errorInfo != null){
                if(_ownedProductList.errorInfo.errorCode == 0){// 0 means no error
                    if(_ownedProductList.results != null){
                        foreach(OwnedProductVo item in _ownedProductList.results){
                        if(item.mConsumableYN == "Y"){
                        //consume the consumable items and OnConsume callback is triggered afterwards                                                                       SamsungIAP.Instance.ConsumePurchasedItems(item.mPurchaseId, OnConsume);
                        }
                        if(item.mItemId == "BuySuperJump"){
                             superJump++;
                        }
                        else if(item.mItemId == "BuyUpgradedPlayer"){                         
                        playerMaterial = Resources.Load<Material>("playerMaterial");
                        MeshRenderer meshRenderer = GetComponent<MeshRenderer>();
                        meshRenderer.material = playerMaterial;                        
                        }                    
                    }
                } 
            }
        }
    }
    

As you can see, some actions have been taken inside the game depending on the respective item IDs. For example, the super jump counter has been increased and the material of the player gets changed. If there is any consumable item which has not been reported as consumed, then the ConsumePurchasedItems() method is invoked. We describe this method in the next section.

Consume purchased consumable items

Use the ConsumePurchasedItems() method to report the purchased consumable item as consumed, which enables the item to be purchased again. See Acknowledge a purchased consumable item to understand this process better. When the process of the ConsumePurchasedItems() method in the previous section is finished, the item data and processing results are returned to the OnConsume callback method. We need to implement this method in the same way under the same class as we implemented the OnGetOwnedList method earlier.

void OnConsume(ConsumedList _consumedList){
         if(_consumedList.errorInfo != null){
             if(_consumedList.errorInfo.errorCode == 0){
                 if(_consumedList.results != null){
                     foreach(ConsumeVo item in _consumedList.results){
                             if(item.mStatusCode == 0){
                                 //successfully consumed and ready to be purchased again.
                             }
                     }
                 }
             }
         }
}

Get purchasable IAP items

The users may want to see details of the available IAP items in the store for the game. The GetProductsDetails() method helps to retrieve detailed information (for example, item name, price, ID, etc.) about the IAP items registered in your game that are available for users to purchase. There is a UI button “Available Items” in our sample game for querying the purchasable items. After clicking this button, brief information for each item is presented in a simple dropdown list next to the button (see figure 3). To get the list of available items:

  1. Declare a button variable and a dropdown variable in the beginning of the “player.cs” script.
    public Button getProductsButton;
    public Dropdown itemList;
    
  2. Add a listener method for the “Available Items” button at the end of the Start() method.
    getProductsButton.onClick.AddListener(OnGetProductsButton);
    
  3. To initiate the GetProductsDetails() method, we need to implement the listener OnGetProductsButton() method.
    void OnGetProductsButton(){
             //get all the product details
             SamsungIAP.Instance.GetProductsDetails("", OnGetProductsDetails); 
    }  
    
  4. After the processing is completed on the server side, the OnGetProductsDetails callback is triggered, which contains information about the available IAP items. Implement this callback method and add information of each item to the dropdown method so that the users can see them easily. In the example, we show only the item name and price.
    void OnGetProductsDetails(ProductInfoList _productList){
             if (_productList.errorInfo != null){
                  if (_productList.errorInfo.errorCode == 0){// 0 means no error
                       if (_productList.results != null){
                            itemList.ClearOptions();
                            List<string> optionItems = new List<string>();
                            int i = 1;
                            foreach (ProductVo item in _productList.results){
                                   string temp = i+ ". " + item.mItemName + ": $ " + item.mItemPrice;
                                   optionItems.Add(temp);
                                   i++;
                            }
                            itemList.AddOptions(optionItems);
                       }
                  }
             }
    }
    

2021-05-11-01-03.jpgFigure 3: Showing the available IAP items in the game.


The information of all IAP items is shown in the dropdown menu as a list. You can show only one specific item or more items by specifying their IDs in the GetProductsDetails() method if you want. Learn more about the method here.

View the full blog at its source

Link to comment
Share on other sites



  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Similar Topics

    • By BGR
      Samsung makes the best Android tablets on the market right now. It would be difficult to argue otherwise. Amazon’s lineup of Fire tablets is impressive, but it’s mostly comprised of low-cost models for people on a budget. Meanwhile, Samsung’s lineup of Galaxy tablets spans everything from entry-level models to high-end flagships.
      Today, for one day only, Amazon is running an impressive sale on Samsung Galaxy tablets. The Samsung Galaxy S6 Lite is down to $269.99 instead of $430, and the high-end Galaxy Tab S8+ is $300 off at $599.99. Both of these deals are only available until the end of the day on Friday.

      SAMSUNG Galaxy Tab S6 Lite 10.4" 128GB Android Tablet, S Pen Included, Slim Metal Design, AKG D…
      Price: $269.99 (reg. $430)
      You Save: $160.00 (37%)
      Buy Now
      SAMSUNG Galaxy Tab S8+ 12.4” 128GB WiFi 6E Android Tablet, Large AMOLED Screen, S Pen Included,…
      Price: $599.99 (reg. $900)
      You Save: $300.00 (33%)
      Buy Now
      I’m an iPad user, and I have been ever since Apple released the first-generation model back in 2010. If you’re in the market for a new iPad, you’ll find plenty of discounts in our guide on the best Apple deals. That being said, I use the term “iPad user” lightly since I have never really found that tablets fit into my workflow.
      If I want to look something up on the web or email my email, I use my smartphone. If I want to stream a movie or TV show, I use a television. And if I need to get some work done, I use a computer. As you can see, I pretty much have all the bases covered.
      But not everyone is like me, of course. Plenty of valid use cases exist for tablets, and millions of people buy them each year. They’re great for families to share or for streaming movies if you don’t have a TV in your bedroom. The list goes on and on.
      If I was going to buy an Android tablet, it would definitely be a Samsung Galaxy tablet. And today, Amazon is running a fantastic one-day sale on two different Samsung Galaxy tablet models.
      SAMSUNG Galaxy Tab S6 Lite 10.4" 128GB Android Tablet, S Pen Included, Slim Metal Design, AKG D…
      Price: $269.99
      You Save: $160.00 (37%)
      Buy Now First, we have the Samsung Galaxy Tab S6 Lite.
      This model is perfect for people who want premium features at a mid-range price. It aligns best with Apple’s iPad Air, and the 128GB model has a retail price of $429.99. Right now, the Samsung Galaxy Tab S6 Lite is on sale for $269.99, which is a huge 37% discount.
      Key Samsung Galaxy Tab S6 Lite features include a 10.4-inch LCD display with 2000 x 1000 resolution, a Qualcomm Snapdragon 720G processor, AKG stereo speakers for outstanding sound, an S Pen stylus, and excellent battery life.
      SAMSUNG Galaxy Tab S8+ 12.4” 128GB WiFi 6E Android Tablet, Large AMOLED Screen, S Pen Included,…
      Price: $599.99
      You Save: $300.00 (33%)
      Buy Now If you want something on the higher end of the tablet spectrum, Samsung’s Galaxy Tab S8+ tablet is $300 off today. That slashes the price from $899.99 to just $599.99.
      The Samsung Galaxy Tab S8+ is more like Apple’s iPad Pro, featuring flagship specs and a price tag to match. Highlights include a 12.4-inch sAMOLED display, Wi-Fi 6E support, an ultra-wide-angle camera, an S Pen stylus, DeX multitasking, and more.
      Don't Miss: Today’s deals: Memorial Day sales, $20 Fire Stick, Bose ANC headphones, $264 treadmill, moreThe post Samsung Galaxy tablets are up to $300 off, today only appeared first on BGR.
      View the full article
    • By STF News
      Since its launch in 2017, Samsung Art Store has been at the forefront of driving significant changes in the way we experience and appreciate art. With vast collections of artwork, The Frame and the Art Store offer different ways for consumers to enjoy diverse forms of artwork from the comfort of their homes.
       
      Street art — which often incorporates elements of its surroundings and nature — has been finding its place in digital media as display technology and picture quality have rapidly evolved in recent years. Through partnerships with artists like Logan Hicks, Samsung Art Store has been bridging the gap between public art and everyday consumers, bringing intricate details, expressions and impressions closer to users than ever.
       
      Samsung Newsroom had the privilege of connecting with Logan to discuss his creative process and inspiration and how his partnership with Samsung Art Store helped push the boundaries of his craft.
       
      Logan Hicks is a highly acclaimed artist based in New York, renowned for his intricate photorealistic urban landscapes. By using multiple layers of stencils, he seamlessly blends urban aesthetics with extreme precision and detail.  
       ▲ Logan Hicks’ artistic process (video courtesy of Logan Hicks)
       
       
      Inspiration and Influences: From Baltimore to California and Beyond
      Q: Could you tell us a bit about yourself and your career as an artist? How did you come to work with stencils?
       
      After running a successful commercial screen printing business, I decided to focus on my art and moved from Baltimore to California. I tried hand-cut stenciling and fell in love. The process is similar, but stencils are painstaking and not exact. I embraced this challenge and learned to create deep detail with multiple layers.
       
      ▲ Logan Hicks
       
       
      Q: What is your passion that inspires your art?
       
      Travel is both my inspiration and antidepressant. Seeing new countries, people, places and cultures has always helped keep my eyes open to how utterly fantastic the world is. After I travel, I am always excited to get back into the studio.
       
      I also find a lot of inspiration in New York City. The way the city changes throughout the day and year — it has a life of its own. During the pandemic, it was especially interesting to see a vibrant city empty. It was eerily beautiful.
       
       
      Q: Could you walk us through your artistic process from the photographs you start with to the final product?
       
      I don’t usually go into detail about my process just because it’s easy to confuse the process for the product. About 75% of my time making art is the laborious process of image preparation, stencil cutting, bridging the stencils, etc. To explain briefly, I take photos, break them down into various levels of contrast, cut them out, spray them on top of each other and then carefully paint the lights. My stencils aren’t the kind that you can just roll over a solid coat of paint — I slowly bring out the image with small sprays of paint that I build up.
       

       
       
      Q: What is your favorite step in your artistic process?
       
      My favorite step is creating and choosing a mood for my artwork. Will my scene be exacting or painterly? Will it depict the solitude of the evening or the vibrancy of a bright day? One set of stencils can be painted in many ways, and I like figuring out which one is best.
       
       
      Q: What partnerships have you worked on over the years that stand out to you?
       
      I find that the most successful partnerships are the ones that have the least direction, at least for me. Finding a company that grants freedom to do what I want is paramount for a successful collaboration. A few that come to mind are the Bowery Wall I painted for the Goldman family in New York and a partnership with Porsche for their electric car at Scope Art Fair.


      Logan Hicks X Samsung Art Store
      Q: Why did you choose to partner with the Art Store?
       
      An artist only has two reasons to continue: to make art and to present the art to an audience. For me, Samsung Art Store was an outlet to showcase my art — it was a new approach to displaying my art, and for that reason, I found it interesting. Living spaces these days continue to get smaller and smaller, so I saw this as a way of sharing multiple artworks instead of hanging them on limited walls.
       

       
       
      Q: How does displaying your work on The Frame compare to other media you’ve worked with (e.g., canvas, brick/concrete walls, billboards)?
       
      Good art should be able to translate to various mediums: canvas, walls or digital. The Frame was an interesting platform just because you don’t have control over where it will be hung or what household will download what artwork — it was fun to find out which of my pieces had the most universal appeal. When you make work for a specific location (like with a mural), you have to consider the neighborhood, lighting, surface of the wall, etc. The success of a mural is based on your ability to adapt to the environment. With The Frame, though, it was a case of plucking those works off the wall and putting them into a digital space — the attention was 100% on the artwork that was created instead of the environment that it lives in.
       

       
       
      Q: How does your signature technique of blending colors through aerosol contribute to the visual appeal of your work when displayed digitally?
       
      I hope the audience can appreciate my work on multiple levels. For example, you only observe the subject matter at a distance before you start noticing the details as you get closer. Once you’re inches from it, the execution becomes clear — from the way the colors blend to the tiny dots of aerosol paint that make up the surface of the image.
       
      My work has nuances that are difficult to see on traditional digital displays. I’ve been happy with how the matte display of The Frame picks up details of the spray paint and the subtle color changes.  The display offers the opportunity to experience the work from various distances as if it exists on a wall or canvas.
       
       
      Q: You already have experience in creating large-scale murals worldwide in places like Istanbul, Miami, Baltimore, New York, Tunisia, Paris, etc. How does the Art Store partnership expand the global reach and accessibility of your work to audiences beyond that?
       
      I easily forget that 99.9% of the world won’t have the opportunity to see my work in person. When I paint a mural, it’s usually in larger metropolitan areas and in cities where I already have some sort of connection. So, I like to extend my reach to people who may not live in the places I paint. With this approach, someone in the rural outback of Australia has access to my pieces just as someone in the heart of Manhattan does.
       
       
      Q: What are your top three picks you would recommend to consumers to display on The Frame? Please give us a very brief explanation of each.
       
      ▲ The Entrance, 2019
       
      This painting is the front of Monet’s house. I visited Monet’s Garden for the first time and instantly felt like I was in a different land — flowers surrounded me like a green fog, and the smell of flowers filled the air. Standing in front of Monet’s house, I imagined what it would have been like to live there. I think about how this was what Monet saw every morning as he walked the garden and returned to his house.
       
      ▲ Giverny, 2019
       
      This piece is also from Monet’s Garden. What I loved the most about the garden is that it’s very rare that you can stand in the same place where a masterpiece was created. I’ve grown up seeing Monet’s paintings in my art history books, on TV and in movies. But when I visited the garden, I realized that I was in the painting. I was standing where Monet once stood as he painted, and suddenly his artwork made more sense to me. Of course, he painted his garden! How can you visit heaven and not memorialize it in a painting?
       
      ▲ Axon, 2018
       
      I have a soft spot for Paris: the culture, food, art and architecture. I love it all. This painting is a scene that you see when you walk outside the Gare De Lyon train station. I can remember when I took the photo that I used as inspiration for this piece. My friend asked me, “Why would you take a picture of the street? It’s ugly. It is the train station that is beautiful.” The wonderful thing about being a tourist is that everything is new and fresh.  To me, the street was just as beautiful as the train station. That is the power of a good painting — it can enchant the most boring scenes.
       
       
      The Intersection of Technology and Creativity
      Q: As an artist known for your traditional artistic techniques, how do you navigate the intersection between traditional art forms and the digital world?
       
      Art is a language, and learning to speak it in different arenas is critical to the success of an artist. I don’t put too much thought into what is traditional and what isn’t. I just try to consider what the work will look like scaled down to the size of The Frame. I try to think about what pieces have enough complexity to remain on the screen in someone’s space for an extended period.
       
       
      Q: What unique opportunities does the digital art platform offer for artists like yourself?
       
      The main opportunity I see for the digital space is access to a new audience. Someone may not spend thousands on my painting, but they may download an image of it. I’d like to think that sometimes that may even translate into someone then going out and buying a physical copy of a painting.
       
      It’s also a great way to reach an audience that does not traditionally go to galleries. Art is most successful when people can see a little bit of themselves in it, regardless of whether that is a feeling, experience, thought or mood. That isn’t limited to an art museum attendee. Finding people and connecting with them through art is something that can be done on a much larger scale through a digital platform.
       
      I love the opportunity to reach new audiences who may not have appreciated art before. The art world can sometimes be guarded; The Frame gives new fans an opportunity to consider living with art.
       
      Visit the Samsung Art Store in The Frame to explore more of Logan Hicks’s collection.
      View the full article
    • By BGR
      It’s render season, people!
      As reported by MySmartPrice, renowned leaker OnLeaks has released a number of new renders showing off what the Galaxy Watch 6 Classic will look like. According to the report and the renders, the new Classic will “feature a rotating bezel around the circular display.” It also says that the “Pro” name is going away in favor of the new “Classic” name.
      The report also speculates that the Galaxy Watch 6 Classic will feature multiple strap options, a likely feature that is popular with most smartwatches these days.
      The Galaxy Watch 6 Classic is expected to debut at Samsung’s Galaxy Unpacked event this summer. It’s still unclear when the event will kick off, but the last event in 2022 happened at the beginning of August, so it’s likely that this year will be close to the same.
      I’m personally still good with my Apple Watch Ultra, but that’s also because the Classic is definitely not being sold as an adventure device. It looks like a pretty sick watch, though, so I’m sure people in the Samsung ecosystem will be really happy with the level of style the company could bring to it.
      Don't Miss: Uber will now let you book a Waymo self-driving car through its appThe post Samsung Galaxy Watch 6 Classic leaks, but I’m still good with my Apple Watch Ultra appeared first on BGR.
      View the full article





×
×
  • Create New...