dooboolab-community / react-native-iap

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

Try/catch error description does not matched with the error code (instead it returns E_UNKNOWN) #1179

Closed gurol closed 3 years ago

gurol commented 3 years ago

Version of react-native-iap

4.6.3

Version of react-native

0.63.3

Platforms you faced the error (IOS or Android or both?)

iOS

Expected behavior

getAvailablePurchases() should return E_NETWORK_ERROR instead of E_UNKNOWN

Actual behavior

The try/catching getAvailablePurchases() triggers the catch exception with correct (localized) description but incorrect (actually indistinguishable) error code. The description (in Turkish) is correct: "Uluslararası Dolaşım şu anda kapalı" (Cellular Network is off right now)

Tested environment (Emulator? Real Device?)

Real Device

Steps to reproduce the behavior

The issue was already reported by @acostalima with a clear explaination but it was closed the stale bot

819

He told that Android implementation (DoobooUtils.java) has an expected behavior listed here

The descriptions in react-native-iap (index.ts) are

  1. E_UNKNOWN
  2. E_SERVICE_ERROR
  3. E_USER_CANCELLED
  4. E_USER_ERROR
  5. E_USER_ERROR
  6. E_ITEM_UNAVAILABLE
  7. E_REMOTE_ERROR
  8. E_NETWORK_ERROR
  9. E_SERVICE_ERROR
  10. E_RECEIPT_FAILED
  11. E_RECEIPT_FINISHED_FAILED

Store Kit Error Codes:

  1. unknown: Error code indicating that an unknown or unexpected error occurred.
  2. clientInvalid: Error code indicating that the client is not allowed to perform the attempted action.
  3. paymentCancelled: Error code indicating that the user canceled a payment request.
  4. paymentInvalid: Error code indicating that one of the payment parameters was not recognized by the App Store.
  5. paymentNotAllowed: Error code indicating that the user is not allowed to authorize payments.
  6. storeProductNotAvailable: Error code indicating that the requested product is not available in the store.
  7. cloudServicePermissionDenied: Error code indicating that the user has not allowed access to Cloud service information.
  8. cloudServiceNetworkConnectionFailed: Error code indicating that the device could not connect to the network.
  9. cloudServiceRevoked: Error code indicating that the user has revoked permission to use this cloud service.
  10. privacyAcknowledgementRequired: Error code indicating that the user has not yet acknowledged Apple’s privacy policy for Apple Music.
  11. unauthorizedRequestData: Error code indicating that the app is attempting to use a property for which it does not have the required entitlement.
  12. invalidOfferIdentifier: Error code indicating that the offer identifier cannot be found or is not active.
  13. invalidOfferPrice: Error code indicating that the price you specified in App Store Connect is no longer valid.
  14. invalidSignature: Error code indicating that the signature in a payment discount is not valid.
  15. missingOfferParams: Error code indicating that parameters are missing in a payment discount.

In the reported case cloudServiceNetworkConnectionFailed returns E_UNKNOWN (index 0) instead of E_NETWORK_ERROR (index 8)

I could not spot a possible bug in RNIapIos.m file, possibly here:

(void)request:(SKRequest *)request didFailWithError:(NSError *)error{
    if([request isKindOfClass:[SKReceiptRefreshRequest class]]) {
        if (receiptBlock != nil) {
            NSError *standardError = [[NSError alloc]initWithDomain:error.domain code:9 userInfo:error.userInfo];
            receiptBlock(nil, standardError);
            receiptBlock = nil;
            return;
        }
    }
    else {
        NSString* key = RCTKeyForInstance(productsRequest);
        dispatch_sync(myQueue, ^{
            [self rejectPromisesForKey:key code:[self standardErrorCode:(int)error.code]
                               message:error.localizedDescription error:error];
        });
    }
}
hyochan commented 3 years ago

Looks like a legacy issue. Will look into this.

stale[bot] commented 3 years ago

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as "For Discussion" or "Good first issue" and I will leave it open. Thank you for your contributions.

stale[bot] commented 3 years ago

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.