0

I'm trying to provide a Google subscription service using the react-native-iap API.

I'm trying to enter data into the developerPayload value to split the service.

const result = await requestSubscription(
      sku,
      false,
      offerToken,
      developerPayload,
    );

ChatGPT told me to use it as above. However, there is no function in their API that takes the arguments as listed.

How can I use it?

API version :12.10.2

Thank you for read my question :)

Mamochi
  • 85
  • 8

1 Answers1

1

You should handle the Android and iOS separately on your own business logic.

You can simply check the Platform.OS === 'android' and then use the IAP.requestSubscription depends on this and write two different methods for these.

Here is a basic example for you:

Android Example:


export async const purchaseAndroidSubscription(sku: string, offerToken: string){
 await IAP.requestSubscription({
      sku,
      subscriptionOffers: [
        {
          sku,
          offerToken,
        },
      ],
 });
}

iOS one:

export async const purchaseAppleSubscription(sku: IOSSku){
    await IAP.clearTransactionIOS();
    await IAP.requestSubscription({ sku });
}

You should customize/change as your need.

Also, I strongly suggest you to read the whole documentation and check the IAPExample before doing these stuff. Only ChatGPT will not enough for this :)

FreakyCoder
  • 840
  • 11
  • 24
  • Thanks for the answer! But the code you wrote doesn't have a `developerPayload`, does that mean I can't use it? – Mamochi Apr 06 '23 at 10:21
  • 1
    `requestSubscription` does not have a developerPayload. You can use `finishTransaction` for `developerPayloadAndroid`. It does not have a this for iOS, only for Android. You should check `react-native-iap`'s documentation for best-practices and how to use it properly – FreakyCoder Apr 06 '23 at 10:53
  • Thanks for the answer, I'll look for the documentation. – Mamochi Apr 07 '23 at 00:18