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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Question SetApplicationUsername Confirmation Inquiry

Discussion in 'Unity IAP' started by Hoya127, Mar 10, 2022.

  1. Hoya127

    Hoya127

    Joined:
    Dec 18, 2021
    Posts:
    34
    I want to leave that information on the IOS receipt using SetApplicationUsername.
    I wrote the following, but there is no information in the receipt contents.



    private static IAppleExtensions m_iappleextensions;
    public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
    {
    // Purchasing has succeeded initializing. Collect our Purchasing references.
    BuyLog("OnInitialized: PASS");

    // Overall Purchasing system, configured with products for this application.
    m_StoreController = controller;
    // Store specific subsystem, for accessing device-specific store features.
    m_StoreExtensionProvider = extensions;

    m_iappleextensions = m_StoreExtensionProvider.GetExtension<IAppleExtensions>();
    if(m_iappleextensions!=null)
    {
    string profileID = string.Format("{0}_{1}", "Check",1001);

    byte[] bytesUTF8 = System.Text.Encoding.UTF8.GetBytes(profileID);
    string base64UTF8 = Convert.ToBase64String(bytesUTF8);
    m_iappleextensions.SetApplicationUsername(base64UTF8);
    }
    }

    If I set it in SetApplicationUsername, is it possible to check the receipt?

    We look forward to help from those who have used it.

    thank you.
     
  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    @Hoya127 Please show the contents of the subsequent purchase receipt after you call this method. Just use the string "HelloWorld" as a test before adding your extra UTF8 code, get the basics working first. Also, please describe why you are using SetApplicationUsername.
     
  3. Hoya127

    Hoya127

    Joined:
    Dec 18, 2021
    Posts:
    34

    This is to provide items when the logged-in accounts in the game match.

    Accounts 'A' and 'B' on the same device log in.
    This is to prevent the payment of 'A' from being incorrectly paid to 'B' in the future.
     
  4. AdamLiu

    AdamLiu

    Joined:
    Mar 19, 2014
    Posts:
    71
    Can you please update on this? We have the exact need as the original post - To get the username set in SetApplicationUsername() from the information returned from the store. Thanks
     
  5. AdamLiu

    AdamLiu

    Joined:
    Mar 19, 2014
    Posts:
    71
    Hi, we have the same need as you. May I ask how you solved it?
     
  6. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Please show your code. The name appears in the returned receipt, I have confirmed. This would be in ProcessPurchase, from the product object passed in as the argument. The Sample IAP Project demonstrates how to examine the receipt https://forum.unity.com/threads/sample-iap-project.529555/#post-7922275
     
  7. Hoya127

    Hoya127

    Joined:
    Dec 18, 2021
    Posts:
    34
    'Set ApplicationUsername'
    Do you have an example using it?

    The sample in the link is
    Not code using SetApplicationUsername of 'IAppleExtensions'.
    Please confirm.
     
  8. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    You provided the code already, in the first post. I have confirmed it works. I used it in the Sample IAP Project, and saw the name returned within the receipt.
     
  9. Hoya127

    Hoya127

    Joined:
    Dec 18, 2021
    Posts:
    34
    'IAP_Project.zip' does not use this function.

    'My_Sample_IAP_Project_v3.zip' does not have that feature either.

    Which posts and which files should I get?

    'AppleExtensions' An example using SetApplicationUsername is invisible.
     
  10. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    You posted the correct code yourself, in the very first post. I had asked for the resulting receipt, you have not provided it yet.
     
  11. Hoya127

    Hoya127

    Joined:
    Dec 18, 2021
    Posts:
    34
    I think you're misunderstanding the question.

    in AOS
    of 'IGooglePlayConfiguration'
    I know that SetObfuscatedAccountId works.

    what i ask is
    It is from iOS.

    m_AppleExtensions = extensions.GetExtension<IAppleExtensions>();
    there is only
    SetApplicationUsername does not exist.



    builder.Configure<IGooglePlayConfiguration>().SetObfuscatedAccountId("test1");
    Are you saying this also works on iOS?
     
  12. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
  13. Hoya127

    Hoya127

    Joined:
    Dec 18, 2021
    Posts:
    34
  14. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    I'm not sure what you are asking. It's the one line of code that I just shared, there is nothing else to it, there are no settings The name will then show in the receipt, which you have not provided. Look for the word "receipt" in the Sample project for the places it is referenced. For example, in ProcessPurchase.

    MyDebug("Receipt:" + test_product.receipt.ToString());
     
  15. Hoya127

    Hoya127

    Joined:
    Dec 18, 2021
    Posts:
    34
    m_AppleExtensions.SetApplicationUsername("testuser123");
    when done with

    It's asking how you found it on the receipt.

    The report you mentioned only contains "Payload", "Store", and "TransactionID" information.

    I can't find "testuser123"
     
  16. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Upon inspection, the receipt contents are indeed encoded. I'm checking with the team here and will follow up.
     
  17. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Upon inspection, the receipt contents are indeed encoded. I'm checking with the team here and will follow up. This may take some time, the name does not seem to appear in a Sandbox decoded receipt at any rate. It's possible that the name is actually not available client side, but is a server-side fraud detection feature from Apple. We will continue to check here
     
  18. EnisAdemov

    EnisAdemov

    Joined:
    Oct 8, 2022
    Posts:
    1
    Any news on this issue? Is there a way to get applicationUsername in client-side?
     
  19. Yannick_D

    Yannick_D

    Unity Technologies

    Joined:
    Feb 21, 2022
    Posts:
    218
    Hello,
    There's currently no way to obtain this via Unity's IAP. The receipt we get from Apple doesn't contain that information.

    There are alternatives if you use Apple's receipt validation or their API which will return it.

    Was there a specific case for which you wanted to use the applicationUsername?
     
  20. John_Corbett

    John_Corbett

    Unity Technologies

    Joined:
    May 17, 2019
    Posts:
    151
    Hello @EnisAdemov,

    I dropped the receipt payload into a public ASN1 parser, such as the one here: https://lapo.it/asn1js/ (our code does the same thing). I don't see the username in the output anywhere.

    As Yannick metioned abouve, apparently it's only possible to get this from Apple's receipt validation service and we have no implementation using that within the IAP SDK for the moment.
     
    Last edited: Dec 5, 2022
  21. Mk_dd

    Mk_dd

    Joined:
    Oct 4, 2022
    Posts:
    2
    For those who are doing server side validation (on your own game server) this is what worked for me.

    IAppleExtensions.SetApplicationUsername
    • the input string MUST be a uuid format ( XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX )
    In Unity, there is no way to retrieve this from the receipt - only possible using the In the App Store Server API.
    details here:
    https://developer.apple.com/documentation/storekit/skmutablepayment/1506088-applicationusername

    I did it all using https://github.com/awa/go-iap
    1. verify the receipt to retrieve the original transaction Id
    2. GetTransactionInfo to retrieve the signedTransactionInfo
    3. ParseSignedTransactions to parse the signedTransactionInfo
    4. the result JWSTranction.AppAccountToken will contain the uuid that you set


    I spent alot of time going in circles with various documentation. I hope this is useful for anyone.
     
  22. lhw001

    lhw001

    Joined:
    Jun 16, 2023
    Posts:
    1
    you need input a UUID string,it will works.