Question

How to get the purchaseToken in iOS

  • 3 April 2022
  • 3 replies
  • 289 views

Badge +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?


3 replies

Userlevel 6
Badge +8

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)
}
}

 

Badge +5

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"]

 

Userlevel 5
Badge +9

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.

Reply