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

  • 2 years later...


  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

I am writing to request the sample project mentioned in your blog post, "Integrating Samsung IAP in Your Unity Game." I am currently working on integrating Samsung IAP into my own Unity game and would find the sample project incredibly helpful in understanding the process and implementation details.

I have already followed the steps outlined in the blog post, including:

  • Importing the Samsung IAP Unity plugin package
  • Enabling Samsung IAP functionalities in my project
  • Attaching the "SamsungIAP.cs" script to a game object

However, having a complete sample project to reference would provide invaluable insights into how these elements work together in a practical scenario. It would be especially beneficial to see how the code interacts with different aspects of the IAP process, such as product initialization, purchase requests, and transaction handling.

I would be grateful if you could share the sample project or provide any alternative resources that offer a similar level of detail. I am confident that having access to this information will significantly accelerate my development process and ensure the successful integration of Samsung IAP into my game.

Thank you for your time and consideration.

Link to comment
Share on other sites

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 Samsung Newsroom
      “I know my pieces are influencing AI models and millions of digital paintings. While I’m not sure where this trend will lead, I do know that original art created by humans will always be the basis of any technology in the future.”
      – Erin Hanson, painter
       
      Erin Hanson’s artistic journey is as vivid as the landscapes she paints. Drawing from the dramatic hues of Red Rock Canyon in Nevada and the Pacific coast, Hanson uses bold colors and textured brushstrokes in her signature style of “Open Impressionism.”
       
      Through Samsung’s long-standing partnership with Saatchi Art, customers can access her unique works and access her colorful world on Samsung Art Store. Samsung Newsroom sat down with Hanson to discuss the scenery that inspires her and hear how technology is blurring boundaries in the art world by merging the physical with the digital.
       
      ▲ Erin Hanson
       
       
      Letting Creativity Bloom
      Q: Tell us a bit about your artistic journey. When did you begin painting?
       
      For as long as I can remember, I’ve always wanted to be an artist. I started with oil paintings when I was 8 years old and explored other mediums — but I was always drawn back to oils since that’s what the masters painted in. When I hold a brush full of buttery paint and breathe in the smell of oils, I feel directly connected to the great painters of the past.
       
       
      Q: Please tell us more about Open Impressionism.
       
      People kept telling me that my paintings were distinctive and instantly recognizable, so I formed the term Open Impressionism after I had crafted about 400 paintings in this unique style. My focus is on color, light and the feeling of being surrounded by beauty in the outdoors. I call my style “open” because my inspiration comes from open-air landscapes. I use the impasto technique and keep my impressionistic paintings highly textured without smearing or blending colors. Through decisive brushstrokes, I let the underpainting peek out to give my works the appearance of stained glass or a mosaic.
       
      ▲ Dawning Saguaro (2021)
       
       
      Q: Your paintings often feature stunning natural landscapes. What are your favorite locations? How have they influenced your creative process?

      My first muses were the rocky landscapes of Nevada and southern Utah — the saturated colors of the scenic desert gave me endless subject matter whenever I went rock climbing at Red Rock Canyon. I’ve now explored many national parks and monuments including Zion, Bryce Canyon, Arches, Monument Valley, the Grand Canyon and Canyon de Chelly.
       
      When I moved back to California, I started exploring Carmel and Mendocino on the Pacific coast. I fell in love with painting the vineyards, oak trees and rolling hills of California’s wine country. Yosemite and Lake Tahoe always draw me in with their dramatic colors and seasons.
       
      “When I hold a brush full of buttery paint and breathe in the smell of oils, I feel directly connected to the great painters of the past.”
       
       
      Framing Nature’s Beauty
      Q: Your painting “Coastal Poppies II” is a favorite among users of The Frame. How did you translate this captivating piece for a digital platform?
       
      “Coastal Poppies II” is inspired by one of my favorite coastal views in California, near Heart Castle and Big Sur. The painting brings me back to a time when the poppies were in full bloom, and I was standing alongside Highway 1 on the edge of the Pacific Coast — looking down into the rich aquamarine water with the salty ocean air blowing into my face. The contrast in colors and textures was so breathtaking that I completed four paintings in this series. The most recent was “Coastal Poppies IV” in 2022.
       
      ▲ Coastal Poppies II (2020)
       
      “I formed the term Open Impressionism after I had crafted about 400 paintings in this unique style. My focus is on color, light and the feeling of being surrounded by beauty in the outdoors. I’ve [now] painted more than 3,000 oil pieces in [this] style”
       
       
      Q: Can you share how you feel about your work being displayed on The Frame?
       
      I like The Frame because the art is displayed on a wall, right where a real painting would hang. My fans and collectors can experience the brushstrokes and rhythms of texture within the painting which can be difficult to see on smaller displays.
       
      I am also amazed at how well the Frame recreates the vibrant colors of my artwork. My impressionist paintings are all about color, and I love how the Frame captures the colors so accurately!
       
      *Editor’s note: In 2024, The Frame became the first in the industry to earn the Pantone® Validated ArtfulColor certification. The Matte Display also minimizes light reflection to help viewers admire art under overhead room lights or even daylight.
       
       
      Q: Out of all your pieces that users can display on The Frame, which are your top three picks?
       
      My favorites are “Coastal Poppies II,” “Apple Blossoms” and “Cherry Blossoms.”
       
      ▲ Apple Blossoms (2023)
       
      “Apple Blossoms” was inspired by a 30-year-old apple tree on my property. Since I moved up to the Willamette Valley in the Oregon wine country, I’ve been attracted to the four seasons in the Northwest.
       
      ▲ Cherry Blossom (2023)
       
      “Cherry Blossom” captures a grove of blooming cherry trees near my gallery in McMinnville, Oregon. With pink cherry blossoms against a perfect blue sky, the painting is truly a harbinger of spring.
       
       
      Q: “Apple Blossoms” will be part of Samsung Art Store’s April curated collection, “Spring in Bloom.” What can users expect?
       
      The “Spring in Bloom” collection will capture everything there is to love about springtime. I live in Oregon, where spring arrives after a long, cold and wet winter. It feels like that moment in “The Wizard of Oz” when the world turns to technicolor — almost like someone flipped a switch one night, and the world is suddenly full of daffodils, mustard fields and flowering plum and cherry trees. I hope users get to experience that same kind of wonder and magic when they see this collection.
       
      “My dream is to create an immersive Erin Hanson experience where people can step right into my paintings [in a digital environment] and be surrounded by moving pictures of my artwork”
       
       
      Embracing Immersive Art Through Technology
      Q: Can you share more about what drew you to work with Saatchi Art, a longtime partner of the Art Store?
       
      Beyond showing its works on The Frame, Saatchi Art is the best online hub for showcasing original artwork. The art collection is well-curated, with, and there is an amazing variety of styles and mediums. The fact that there is something for everyone makes it a great way for collectors to find new artwork, again and again. I have been selling my work through Saatchi Art for over a decade now. The Saatchi team is always helpful and easy to work with.
       
       
      Q: Traditional art galleries allow viewers to experience paintings in person and fully appreciate the texture, brushstrokes and scale. How do you think digital formats impact the way people engage with art?
       
      I’ve painted more than 3,000 oil pieces in my Open Impressionism style — and truthfully, I struggled to find ways to share my work with fans and collectors. Although I have several coffee table books and many paper prints, the best way to share my collections is through digital formats.
       
      For digital formats, we typically look for compositions that work well on a long, horizontal layout. To obtain such high-resolution images of my paintings, we use a large scanner in my gallery that takes up the entire room. The scanner photographs the paintings from above using five different light angles, so we can control the amount of shadow that is visible in the final images. This variation gives the illusion of three dimensions, so you can almost reach out and feel the brushstrokes.
       
      In addition, we map my oil paintings to produce high-resolution, three-dimensional textured prints. They’re so lifelike that most people can’t tell the difference between the replica and the original.
       
      My dream is to create an immersive Erin Hanson experience where people can step right into my paintings and be surrounded by moving pictures of my artwork. In a digital environment like this, visitors can appreciate a larger quantity of art than the dozen or so pieces they might see hanging in a gallery or festival setting.
       
       
      Q: Do you see technology playing an increasingly significant role in the art world? If so, how do you anticipate this trend to unfold in the years to come?
       
      I am sure technical innovators will continue to find new ways to create and share artwork. For example, bigger The Frame TVs would allow art lovers to display even larger works of art on their walls. I know my pieces are influencing AI models and millions of digital paintings. While I’m not sure where this trend will lead, I do know that original art created by humans will always be the basis of any technology in the future. A computer may be able to alter and combine different paintings to create a new piece, but the original images were all created by individual artists who viewed the world in their own distinct ways.
       
       
      Q: Can you tell us about any upcoming projects?
       
      This year, I am traveling to France to follow in the footsteps of the impressionists and visit all the famously painted locations in Paris, following the Seine to Arles and Le Havre in southern France. I will be visiting the windowsill where Van Gogh sat and painted “Starry Night” and exploring the gardens that Monet so famously painted. This has been a dream of mine for several years, and it is finally coming true. Afterward, I plan to create a collection of French-inspired works in homage to the 150th anniversary of the first impressionist exhibition.
       
      The works from this collection, “Reflections of the Seine,” will be released in September. You can read more here: erinhanson.com/Event/ReflectionsoftheSeine.
      View the full article
    • By Samsung Newsroom
      Samsung Art Store is today welcoming the arrival of 12 of Jean-Michel Basquiat’s most striking works, in partnership with Artestar and The Estate of Jean-Michel Basquiat. This is the first time the iconic artist’s work has been officially released for digital display, and joins works from leading museums, collections and artists around the world available from Samsung Art Store.
       
      ▲ Pez Dispenser (1984), one of Basquiat’s most recognizable artworks, displayed on The Frame
       
      Samsung Art Store is a subscription service that enables owners of The Frame to continuously transform any space with over 2,500 pieces of digital art, including works from the most renowned artists, museums and industry tastemakers.
       
      Jean-Michel Basquiat was a beacon of innovation and social commentary, with his work not only featured in galleries and museums worldwide, but also igniting a powerful conversation on cultural complexities. Artestar and The Estate of Jean-Michel Basquiat continue to honor his prolific legacy by showcasing his art and its underlying messages, striving to engage with audiences worldwide to ensure his visionary work remains accessible and influential.
       
      “The ability to bring Basquiat’s iconic artwork directly into your home with Samsung Art Store is an exciting opportunity for global audiences to experience his work in a new and powerful way,” said David Stark, Founder and President of Artestar, the international brand licensing and consulting agency representing the Estate of Jean-Michel Basquiat. “Basquiat’s work continues to spark important conversations and encourages us to look at our worlds differently. This partnership on The Frame’s digital canvas allows his pieces to be experienced in anyone’s home, helping to share his work and honor his legacy.”
       
      The new collection features unique pieces from throughout Basquiat’s career. Among the works available to Art Store subscribers are Bird on Money (1982), a stunning tribute to Charlie Parker. Also included is Boy and Dog in a Johnnypump (1982), King Zulu (1986), which offers a large color block of blue in his more refined late style; and a dual portrait with Andy Warhol, Dos Cabezas (1982), which like many of his works pulls inspiration from his Puerto Rican heritage.
       
      This body of work was curated specifically for Samsung Art Store, adapted for a 16×9 format and were chosen based on their ability to be reproduced accurately, in keeping with Basquiat’s legacy.
       
      Jean-Michel Basquiat emerged as one of the most significant artists of the 20th century, his work rich with themes of heritage, identity and the human experience. Beginning his career as a graffiti artist in New York City under the pseudonym SAMO, Basquiat later transitioned to canvas to express his unique blend of symbolic, abstract and figurative styles. His art, characterized by intense colors, dynamic figures and cryptic texts, delves into topics such as societal power structures, racial inequality and the quest for identity. Basquiat’s impact was monumental, leaving a lasting legacy in the art world that explores social issues through his interest in pop culture and his own deeply refined neo-expressionist style.
       
      ▲ Mitchell Crew (1983), shown on The Frame via Samsung Art Store
       
      Since its founding in 2019, Samsung Art Store has been committed to bringing art from the world’s most renowned museums and important artists into homes across the world. The addition of the Basquiat collection significantly broadens the range of contemporary American artists whose works are now globally accessible for display.
       
      “Jean-Michel Basquiat’s work stands completely alone in the history of contemporary art, which is why it was essential that some of his most brilliant pieces were represented in Samsung Art Store,” said Daria Greene, Global Curator at Samsung Art Store. “Basquiat’s preeminent place in our culture and unique message to the world is as necessary today as it ever was, and we’re so proud to help share that message and expand on his legacy.”
       
      Basquiat’s work has been celebrated with numerous retrospectives and is held in prestigious collections globally, including those of the Museum of Modern Art, New York; The Metropolitan Museum of Art, New York; The Whitney Museum of American Art, New York; The Menil Collection, Houston; and the Museum of Contemporary Art, Los Angeles. His work continues to inspire new generations, embodying a bridge between street art and high art and challenging societal norms.
       
       
      Explore Thousands of Works From Artists and Institutions Around the World
      Alongside these new Basquiat pieces, viewers can explore thousands of additional artworks from masters such as Dalí and Van Gogh in Samsung Art Store,1 available for instant display on The Frame. Additionally, in Samsung’s Art Store you will find work from major global institutions including The Metropolitan Museum of Art, Tate Collection, the National Palace Museum in Taiwan, the Prado Museum in Madrid and the Belvedere Museum in Vienna.
       
      Samsung also recently refreshed The Frame line-up, with the new series now available for purchase. The 2024 line-up offers Pantone Art Validated Colors, so that every piece of art appears even more realistic, plus new Samsung Art Store – Streams, a complimentary set of regularly curated artworks sampled from Samsung Art Store. The Frame is even more energy efficient when in Art Mode, automatically adjusting the refresh rate so you can enjoy high-quality art, while conserving energy.2
       
       
      ABOUT JEAN-MICHEL BASQUIAT
      Jean-Michel Basquiat is one of the best-known artists of his generation and is widely considered one of the most important artists of the 20th century. His career in art spanned the last 1970s through the 1980s until his death in 1988 at the age of 27. Basquiat’s works are edgy and raw, and through a bold sense of color and composition, he maintains a fine balance between seemingly contradictory forces such as control and spontaneity, menace and wit, urban imagery, and primitivism.
       
      ABOUT ARTESTAR
      This partnership was done in collaboration with Artestar, a global licensing agency and creative consultancy representing high-profile artists, photographers, designers and creatives. Artestar connects brands with artists — curating and managing some of the world’s most recognizable creative collaborations. Learn more at artestar.com.
       
       
      1 A single user subscription for Art Store costs $4.99/month or $49.90/year.
      2 This feature applies to the 55’’ display and above.
      View the full article
    • By Samsung Newsroom
      View the full blog at its source





×
×
  • Create New...