Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Changing IAP prices after publishing

Discussion in 'General Discussion' started by Job_MTalha, Apr 20, 2021.

  1. Job_MTalha

    Job_MTalha

    Joined:
    Jan 14, 2021
    Posts:
    61
    Can we Change the Unity IAP prices at runtime? What I have in mind is to fetch the prices from the server and use those prices after the game is published. I want to tweak those prices according to seasons without having to update the app.
     
  2. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    9,686
    Prices are always fetched from the server unless you're doing something extremely wrong.
     
    Joe-Censored likes this.
  3. Job_MTalha

    Job_MTalha

    Joined:
    Jan 14, 2021
    Posts:
    61
    I am using playfab as a backend server. So What i can do is to make bundles there and fetch them in game. Instead of hardcoding them in the game.
     
  4. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    9,686
    Yes. What do you need help with then? This is exactly how you're supposed to do things.
     
  5. Job_MTalha

    Job_MTalha

    Joined:
    Jan 14, 2021
    Posts:
    61
    I want help regarding how to do it coding wise. Once I get the Bundle and its price, How should I equate it to the IAP button throught Script.
     
  6. xjjon

    xjjon

    Joined:
    Apr 15, 2016
    Posts:
    587
    I think you should fetch your price from the app stores. It will include the correct localized currency and currency code.

    You can use Unity IAP to do that for you automatically.

    Then when you purchase IAP, use unityIAP to handle it -

    Verify receipt with playfab after to grant reward.

    Some sample code for android for you..

    Code (CSharp):
    1. public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs e)
    2.         {
    3.             var productId = e.purchasedProduct.definition.id;
    4.             var googleReceipt = GooglePurchase.FromJson(e.purchasedProduct.receipt);
    5.             var request = new ValidateGooglePlayPurchaseRequest
    6.             {
    7.                 CurrencyCode = e.purchasedProduct.metadata.isoCurrencyCode,
    8.                 PurchasePrice = (uint) (e.purchasedProduct.metadata.localizedPrice * 100),
    9.                 ReceiptJson = googleReceipt.PayloadData.json,
    10.                 Signature = googleReceipt.PayloadData.signature
    11.             };
    12.             PlayFabClientAPI.ValidateGooglePlayPurchase(request, result =>
    13.                 {
    14.                     //handle success
    15.                 },
    16.                 error =>
    17.                 {
    18.                     // handle errors
    19.                 });
    20. }
     
    Job_MTalha likes this.
  7. Job_MTalha

    Job_MTalha

    Joined:
    Jan 14, 2021
    Posts:
    61
    Thanks alot man. I'll try this out.