hyochan / react-native-iap

In App Purchase module for React Native!
https://react-native-iap.hyo.dev
MIT License
2.87k stars 648 forks source link

Restore purchase does not work using- RNIap.getAvailablePurchases() #2858

Open saracasticshailz opened 1 month ago

saracasticshailz commented 1 month ago
  1. IAP purchase is going smooth.
  2. When user tries to restore the purchase in re-login
  3. The IAP given below error.

Code snippet

`RNIap.getAvailablePurchases() .then(async availablePurchases => { if ( availablePurchases?.length === 0 || availablePurchases === undefined || availablePurchases === null ) { setIsLoading(false); Alert.alert('Notification', 'Product not available to restore'); return; } const sortedAvailablePurchases = availablePurchases.sort( (a, b) => b.transactionDate - a.transactionDate, );

        if (itemSkus.includes(sortedAvailablePurchases?.[0]?.productId)) {
          let data = '';
          if (Platform.OS === 'ios') {
            data = {
              subscription: itemId,
              inAppSubscription: sortedAvailablePurchases?.[i],
            };
          } else {
            data = {
              subscription: itemId,
              inAppSubscription: sortedAvailablePurchases?.[i],
            };
          }
          const request = {
            data,
            onSuccess: () => {
              dispatch(getUserProfile());
              setTimeout(() => {
                setIsLoading(false);
                Alert.alert('Notification', 'Restored Successfully');
              }, 1000);
            },
            onFail: e => {
              if (e.message) {
                setIsLoading(false);
                alert('Error ' + e.message);
              }
            },
          };
          if (userProfile?.inAppSubscriptionStatus === 'Active') {
            Alert.alert('Notification', 'You already have an active plan');
            setIsLoading(false);
          } else {
            dispatch(upgradeSubscription(request));
          }
        } else if (i === sortedAvailablePurchases?.length - 1) {
          setIsLoading(false);
          Alert.alert('Notification', 'Product not available to restore');
        }
      })
      .catch(err => {
        setIsLoading(false);
        console.log(' RNIap Init', err);
      });`

      Error

      `{"code":"E_UNKNOWN","message":"An unknown error occurred","domain":"SKErrorDomain","userInfo":{"NSUnderlyingError":{"code":"5002","message":"underlying error","domain":"ASDServerErrorDomain","userInfo":{"NSLocalizedFailureReason":"An unknown error has occurred"},"nativeStackIOS":["0 Holy Reads            0x00000001055dc484 RCTJSErrorFromCodeMessageAndNSError + 112","1 Holy Reads            0x00000001055dc73c RCTJSErrorFromCodeMessageAndNSError + 808","2 Holy Reads            0x0000000105580ffc __41-[RCTModuleMethod processMethodSignature]_block_invoke_2.73 + 152","3 Holy Reads            0x00000001052a2e8c $sSo8NSStringCSgACSo7NSErrorCSgIeyByyy_SSSgAGs5Error_pSgIegggg_TR + 380","4 Holy Reads            0x000000010529f9ec $sSSSgAAs5Error_pSgIegggg_A2aCytIegnnnr_TR + 56","5 Holy Reads            0x000000010529f96c $sSSSgAAs5Error_pSgytIegnnnr_A2aCIegggg_TR + 152","6 Holy Reads            0x00000001052a4598 $s5RNIap0A3IosC14rejectPromises6forKey4code7message5errorySS_SSSgAIs5Error_pSgtF + 912","7 Holy Reads            0x00000001052acd8c $s5RNIap0A3IosC12paymentQueue_43restoreCompletedTransactionsFailedWithErrorySo09SKPaymentD0C_s0J0_ptFyyXEfU_ + 416","8 Holy Reads            0x0000000105088870 $sIg_Ieg_TR + 20","9 Holy Reads            0x00000001050888c8 $sIeg_IyB_TR + 24","10 libdispatch.dylib         0x00000001999ae0d0 B8C15E69-D076-317D-9296-1279500738FC + 16592","11 libdispatch.dylib         0x00000001999bd750 B8C15E69-D076-317D-9296-1279500738FC + 79696","12 Holy Reads            0x00000001052acb20 $s5RNIap0A3IosC12paymentQueue_43restoreCompletedTransactionsFailedWithErrorySo09SKPaymentD0C_s0J0_ptF + 320","13 Holy Reads            0x00000001052ace00 $s5RNIap0A3IosC12paymentQueue_43restoreCompletedTransactionsFailedWithErrorySo09SKPaymentD0C_s0J0_ptFTo + 68","14 libdispatch.dylib         0x00000001999ac370 B8C15E69-D076-317D-9296-1279500738FC + 9072","15 libdispatch.dylib         0x00000001999ae0d0 B8C15E69-D076-317D-9296-1279500738FC + 16592","16 libdispatch.dylib         0x00000001999bc9e0 B8C15E69-D076-317D-9296-1279500738FC + 76256","17 libdispatch.dylib         0x00000001999bc5fc _dispatch_main_queue_callback_4CF + 44","18 CoreFoundation          0x0000000191d07f64 47427277-EE15-3C17-AD68-6886B0380B5E + 356196","19 CoreFoundation          0x0000000191d05188 47427277-EE15-3C17-AD68-6886B0380B5E + 344456","20 CoreFoundation          0x0000000191d045b8 CFRunLoopRunSpecific + 572","21 GraphicsServices         0x00000001dd79a1c4 GSEventRunModal + 164","22 UIKitCore             0x000000019485a5f0 5BD027B1-0EC9-35FD-B9F0-6288A525693A + 4056560","23 UIKitCore             0x000000019490910c UIApplicationMain + 340","24 Holy Reads            0x0000000104fd83bc main + 96","25 dyld               0x00000001b74d7d34 77C1EED2-2ED7-396A-BA34-E770120D81D4 + 212276"]},"NSLocalizedDescription":"An unknown error occurred"},"nativeStackIOS":["0 Holy Reads            0x00000001055dc484 RCTJSErrorFromCodeMessageAndNSError + 112","1 Holy Reads            0x0000000105580ffc __41-[RCTModuleMethod processMethodSignature]_block_invoke_2.73 + 152","2 Holy Reads            0x00000001052a2e8c $sSo8NSStringCSgACSo7NSErrorCSgIeyByyy_SSSgAGs5Error_pSgIegggg_TR + 380","3 Holy Reads            0x000000010529f9ec $sSSSgAAs5Error_pSgIegggg_A2aCytIegnnnr_TR + 56","4 Holy Reads            0x000000010529f96c $sSSSgAAs5Error_pSgytIegnnnr_A2aCIegggg_TR + 152","5 Holy Reads            0x00000001052a4598 $s5RNIap0A3IosC14rejectPromises6forKey4code7message5errorySS_SSSgAIs5Error_pSgtF + 912","6 Holy Reads            0x00000001052acd8c $s5RNIap0A3IosC12paymentQueue_43restoreCompletedTransactionsFailedWithErrorySo09SKPaymentD0C_s0J0_ptFyyXEfU_ + 416","7 Holy Reads            0x0000000105088870 $sIg_Ieg_TR + 20","8 Holy Reads            0x00000001050888c8 $sIeg_IyB_TR + 24","9 libdispatch.dylib         0x00000001999ae0d0 B8C15E69-D076-317D-9296-1279500738FC + 16592","10 libdispatch.dylib         0x00000001999bd750 B8C15E69-D076-317D-9296-1279500738FC + 79696","11 Holy Reads            0x00000001052acb20 $s5RNIap0A3IosC12paymentQueue_43restoreCompletedTransactionsFailedWithErrorySo09SKPaymentD0C_s0J0_ptF + 320","12 Holy Reads            0x00000001052ace00 $s5RNIap0A3IosC12paymentQueue_43restoreCompletedTransactionsFailedWithErrorySo09SKPaymentD0C_s0J0_ptFTo + 68","13 libdispatch.dylib         0x00000001999ac370 B8C15E69-D076-317D-9296-1279500738FC + 9072","14 libdispatch.dylib         0x00000001999ae0d0 B8C15E69-D076-317D-9296-1279500738FC + 16592","15 libdispatch.dylib         0x00000001999bc9e0 B8C15E69-D076-317D-9296-1279500738FC + 76256","16 libdispatch.dylib         0x00000001999bc5fc _dispatch_main_queue_callback_4CF + 44","17 CoreFoundation          0x0000000191d07f64 47427277-EE15-3C17-AD68-6886B0380B5E + 356196","18 CoreFoundation          0x0000000191d05188 47427277-EE15-3C17-AD68-6886B0380B5E + 344456","19 CoreFoundation          0x0000000191d045b8 CFRunLoopRunSpecific + 572","20 GraphicsServices         0x00000001dd79a1c4 GSEventRunModal + 164","21 UIKitCore             0x000000019485a5f0 5BD027B1-0EC9-35FD-B9F0-6288A525693A + 4056560","22 UIKitCore             0x000000019490910c UIApplicationMain + 340","23 Holy Reads            0x0000000104fd83bc main + 96","24 dyld               0x00000001b74d7d34 77C1EED2-2ED7-396A-BA34-E770120D81D4 + 212276"]}

`

DevLasa commented 5 hours ago

I also blocked due to this issue. Please resolve this ASAP