dooboolab-community / react-native-iap

In App Purchase module for React Native!
https://react-native-iap.dooboolab.com
MIT License
2.78k stars 634 forks source link

transactionReceipt is empty string when testing in app purchase on iOS. #2526

Closed benminor closed 11 months ago

benminor commented 1 year ago

Description

I am trying to test my in app purchase. After successfully purchasing the subscription in the app, via TestFlight and signed into Sandbox account, I try and access the purchase.transactionReceipt value to send to my backend for verification but it is an empty string.

Expected Behavior

It's expected to not be an empty string so that I can verify the transaction in my backend.

Screenshots Screen Shot 2023-08-24 at 4 39 31 PM

Environment:

Is this because I am testing via TestFlight so the transaction technically doesn't go through, thus there's no receipt?

baesumin commented 11 months ago

+1

khrulev commented 11 months ago

Do you use a StoreKit2 or Hybrid Mode?

benminor commented 11 months ago

@khrulev You need to use StoreKit2, not anything else. Closing this issue :)

daimonkor commented 10 months ago

@baesumin Hello, the same, I use setup({storekitMode: 'STOREKIT2_MODE'}); and "transactionReceipt":"" with help sandbox account. Please help, version "12.10.8".

khrulev commented 10 months ago

@baesumin Hello, the same, I use setup({storekitMode: 'STOREKIT2_MODE'}); and "transactionReceipt":"" with help sandbox account. Please help, version "12.10.8".

When you use STOREKIT2_MODE you should not use any Receipt(including transactionReciept), you should ONLY process JWS transactions by verifying them using the Apple services and then invoke your own business logic and when you complete your own code you need just invoke FinishTransaction() to say Apple that you did all your job. The main difference between STOREKIT2 and SK1 is migration from receipt to transactions approach.

daimonkor commented 10 months ago

@khrulev hm, I found validate code const appleReceiptResponse = await validateReceiptIos({ receiptBody: { 'receipt-data': receipt, password: ITUNES_SHARED_SECRET, }, isTest: isTestEnvironment, }); Is it valid?

khrulev commented 10 months ago

@khrulev hm, I found validate code const appleReceiptResponse = await validateReceiptIos({ receiptBody: { 'receipt-data': receipt, password: ITUNES_SHARED_SECRET, }, isTest: isTestEnvironment, }); Is it valid?

It should work in SK1 mode. With these comments:

And I recommend using STORE_KIT2_MODE, where you can get PurchaseHistory() and get the latest transaction. Work with transactions, not receipts. I guess if you implement a receipts approach you can not get approved by App store because of guidelines.