apple / app-store-server-library-node

MIT License
162 stars 31 forks source link

How to verify purchase with data from in_app_purchase_ios flutter package? #106

Closed nmtuan2001 closed 6 months ago

nmtuan2001 commented 6 months ago

Hi. I'm integrating in-app payment using in_app_purchase package. I have managed to verify purchases for Android, and just started to work on iOS. Using this package, I will obtain a string serverVerificationData. How do I verify purchases on iOS with this value? Is this value the appReceipt mentioned in the guide?

alexanderjordanbaker commented 6 months ago

We would recommend using StoreKit 2 client side, which would give you a signed JWS you can pass directly to the server. I'm not familiar with whether that library is using Original StoreKit or StoreKit 2 or what that field represents.

Apidcloud commented 4 months ago

Apologies for reopening the thread but I'm facing the same issue.

the serverVerificationData is something like this: MIIUZwYJ<.......more>9rxE3Q==

and it's something that seems to work with the receipt utility extractTransactionIdFromAppReceipt, so im assuming the flutter package is using the original store kit.

My question now is: what is the correct way of validating the purchase? In my mind it would be something like searching if the receipt coming from the app was already paid or not, but I'm a bit confused with the example in README in this repo for Receipt usage.

It loops over the transaction history, but when can consider it valid and effectively purchased? And the opposite: when can we consider it invalid?

Thanks!