j3k0 / cordova-plugin-purchase

In-App Purchase for Cordova on iOS, Android and Windows
https://purchase.cordova.fovea.cc
1.29k stars 529 forks source link

How to get the appStoreReceipt #1527

Open reinos opened 2 months ago

reinos commented 2 months ago

There is already an ongoing discussion here (https://github.com/j3k0/cordova-plugin-purchase/issues/1495) with the same topic. However, that topic is more related to the custom verify service.

In order to have our payment provider be synced with Apple (we offer In App Purchases as well purchases via the website), we need to need the appStoreReceipt. However, it seems that this cannot be fetched?

Does anybody know a way for getting the appStoreReceipt value?

selcukbeyhan commented 2 months ago

Do you want to retrieve the user's receipt and store in your own system?

reinos commented 2 months ago

Yes I need the user's receipt, it is required for our payment provider that needs to store it. So I have to retrieve and send it to our payment provider (chargebee).

selcukbeyhan commented 2 months ago

Hi, if the payment via Apple is done, processed and documented with a receipt, I cannot think of a usecase what the other payment provider would do with Apple's receipt. Could there be a misunderstanding about the payment providers processes and requirements?

Otherwise, the API of Store object could be helpful to access to the receipts: https://github.com/j3k0/cordova-plugin-purchase/blob/v13/api/classes/CdvPurchase.Store.md

reinos commented 2 months ago

Chargee (our payment provider) is just syncing the data.

Small intro about this; we use chargebee to see if a subscription is active or not, or what plan the user is using. Based on that plan we give the user extra features or not.

Because the app was first only created for web, this approach is working fine. However, we also created a Mobile app, using capacitor, but it is rejected by apple because we don't use In App Purchases.

But by using In App Purchases it creates a second source of truth for our subscriptions. Fortunately Chargebee has a syncing method where it can sync those subscriptions from Apple to Chargebee. So we can still using Chargebee as our source of truth. However, new subscriptions are not created initially, so we have to push/create a new subscription manually via an Chargebee endpoint and that requires the AppStoreReceipt

# Create an In app subscription for Apple App Store
curl  https://{site}.chargebee.com/api/v2/in_app_subscriptions/cb-pjp7hcmrcbfmtjhle3smlwicu4/process_purchase_command \
     -u {site_api_key}:\
     -d receipt="Apple Based64 Encoded Receipt" \
     -d product[id]="app_store_plan_id" \
     -d product[price]="3399" \
     -d product[price_in_decimal]="33.99" \
     -d product[currency_code]="USD" 
     -d customer[id]="customer-123"

I will have a look at https://github.com/j3k0/cordova-plugin-purchase/blob/v13/api/classes/CdvPurchase.Store.md

Thanks!

selcukbeyhan commented 2 months ago

If I am not wrong, what you could do is: a) when there is a purchase performed on the mobile app, you could use a listener to listen the receipt updates and push to your backend where you also validate the receipt. Then you make a call to chargebee b) when there is a purchase performed on the mobile app, you could use a listener to listen the receipt updates and push to chargebee directly. I dont know whether they have receipt validation functionality. Otherwise, you could face issues with fake receipts.

I still have difficulty to understand the receipt lifecycle on the app (when it is issued, what does it contain and how it is validated)