Microsoft Azure PlayFab logo
    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Add-ons
    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA
  • Runs on PlayFab
  • Pricing
    • Blog
    • Forums
    • Contact us
  • Sign up
  • Sign in
  • Ask a question
  • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges
  • Home /
  • API and SDK Questions /
avatar image
Question by Alex Girgis · Jul 22, 2021 at 02:46 AM · In-Game Economy

ValidateIOSReceipt - how to get base64 receipt for ReceiptData?

Hi Guys,

Apologies for my inexperience here. I know this question has been asked and I've read many answers which explain that (As I understand it) I need to parse the receipt from Apple before passing it to Playfab, but I'm having trouble understanding exactly how to do that.

Can anyone point me to any actual code for unity that parses the receipt which I'm currently getting from UnityEngine.Purchasing.Product.receipt and allows me to pass it here:

public void OnPurchasecomplete(UnityEngine.Purchasing.Product product) {

PlayFabClientAPI.ValidateIOSReceipt(new ValidateIOSReceiptRequest() {

CurrencyCode = product.metadata.isoCurrencyCode,

PurchasePrice = (int)(product.metadata.localizedPrice * 100),

// Pass in the receipt

ReceiptData = ???, // not sure how to get this exactly

I tried passing through product.receipt but it didn't work which I assume is because that's JSON format not base64?

The error was:

Validation failed: /Client/ValidateIOSReceipt: iTunes Sandbox validation result: 21002 (InvalidReceiptData) from https://sandbox.itunes.apple.com/verifyReceipt

I'm currently using codeless IAP.

Any help is much appreciated.

Comment

People who like this

0 Show 0
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Jay Zuo · Aug 10, 2021 at 02:59 AM

As you are using Unity IAP, you can refer to Unity docs to get more details: Unity - Manual: Purchase Receipts (unity3d.com). Thus, the receipt you've got is a JSON string. You will need to deserialize it to get the base 64 encoded App Receipt. You can refer to the code in Getting started with PlayFab, Unity IAP, and Android - PlayFab. Although the code is written for Google Play, getting iOS payload would be similar.

public class iOSPurchase {
    // JSON Fields, ! Case-sensitive
    public string Store;
    public string TransactionID;
    public string Payload;

    public static iOSPurchase FromJson(string json) {
        var purchase = JsonUtility.FromJson<iOSPurchase>(json);
        return purchase;
    }
}
Comment

People who like this

0 Show 0 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by Rick Chen · Jul 22, 2021 at 09:41 AM

You may refer to this thread: https://answers.unity.com/questions/1191677/getting-unity-iap-receipt-data-to-validate-with-pl.html where you could parse the receipt using MiniJSON, then get the “Payload” field from the result. Or this thread: https://community.playfab.com/questions/16098/ios-purchase-validation-no-matching-catalogue-item.html, in the first codesnippet, at line 98, use the JsonMapper.ToObject to parse the receipt, then get the “Payload” field for the ReceiptData argument at line 103.

Comment

People who like this

0 Show 0 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Navigation

Spaces
  • General Discussion
  • API and SDK Questions
  • Feature Requests
  • PlayStream
  • Bugs
  • Add-on Marketplace
  • LiveOps
  • Follow this Question

    Answers Answers and Comments

    3 People are following this question.

    avatar image avatar image avatar image

    Related Questions

    Reward Players with Decrease Recharge Time,Change virtual currency recharge time per user 1 Answer

    Don't receive UserInventory 1 Answer

    Who spent the most real money and virtual currency in my titles shop? 1 Answer

    Grant Items On Client? 2 Answers

    ios receipt validation returns 1098 error 1 Answer

    PlayFab

    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Runs on PlayFab
    • Pricing

    Solutions

    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA

    Engineers

    • Documentation
    • Quickstarts
    • API Reference
    • SDKs
    • Usage Limits

    Resources

    • Forums
    • Contact us
    • Blog
    • Service Health
    • Terms of Service
    • Attribution

    Follow us

    • Facebook
    • Twitter
    • LinkedIn
    • YouTube
    • Sitemap
    • Contact Microsoft
    • Privacy & cookies
    • Terms of use
    • Trademarks
    • Safety & eco
    • About our ads
    • © Microsoft 2020
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Create an article
    • Post an idea
    • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Explore
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges