Skip to main content
Question

How to get the purchaseToken in iOS


Forum|alt.badge.img+5

I need the purchaseToken for our server. This field exsits in the Android API,

/**
  * Token that uniquely identifies a purchase.
  */
 val purchaseToken: String,

And it is received upon purchase. But iOS API of the purchase function below doesn't send it back

func purchase(package: Package) async throws -> PurchaseResultData

When I debug, I see a similar data inside this:

purchaseResultData.customerInfo.allPurchases.first?.value["id"]

But allPurchases is private so I can't get it this way.

Any ideas?

This post has been closed for comments

3 replies

cody
RevenueCat Staff
Forum|alt.badge.img+8
  • RevenueCat Staff
  • 500 replies
  • April 8, 2022

Hey @Userstyles!

If you’re looking for a transaction identifier on iOS, you can reference the `transactionIdentifier` property of the StoreTransaction returned after a purchase: https://github.com/RevenueCat/purchases-ios/blob/main/Sources/Purchasing/StoreKitAbstractions/StoreTransaction.swift#L110

Purchases.shared.purchase(package: package) { transaction, info, error, userCancelled in
    if let transaction = transaction {
        print(transaction.transactionIdentifier)
    }
}

 


Forum|alt.badge.img+5
  • Author
  • New Member
  • 1 reply
  • April 12, 2022

The `transaction.transactionIdentifier` I am getting is 2000000030897391. It is numeric only. I am looking for an alphanumeric string. Like I am getting in 

purchaseResultData.customerInfo.allPurchases.first?.value["id"]

 


ryan
RevenueCat Staff
Forum|alt.badge.img+9
  • RevenueCat Staff
  • 391 replies
  • April 13, 2022

Hey @Userstyles!

 

Thanks for the screenshot! That ID field is a UUID generated by RevenueCat for non-subscription purchases as a way to identify multiple purchases of the same product ID - this will only be set for non-subscription purchases.

 

The “PurchaseToken” is an Android specific field that’s most similar to the raw receipt from Apple actually, but if you deconstruct the Apple receipt than the transaction identifier that @cody mentioned could be used as an identifier.

 

What is it that you’re trying to accomplish? Most devs that are storing the Android PurchaseToken on their server are using it for a very specific purpose and there isn’t a perfect equivalent on iOS.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings