Question

React Native: Purchases.purchaseDiscountedPackage not working as expected.

  • 18 July 2023
  • 3 replies
  • 447 views

Badge

Hello,

I’m receiving the following error

RNPurchases.purchasePackage was called with 4 arguments but expects 5 arguments. If you haven’t changed this method yourself, this usually means that your versions of the native code and JavaScript code are out of sync. Updating both should make this error go away.

when calling

Purchases.purchaseDiscountedPackage(package, paymentDiscount)

with the following SDK versions:

  • react-native-purchases 6.3.0
  • PurchasesHybridCommon 5.3.0
  • RevenueCat 4.24.1

When I append null as an argument in the purchases.js file as part of the method’s definition, similar to the regular purchasePackage method...

RNPurchases.purchasePackage(aPackage.identifier, aPackage.offeringIdentifier, null, discount.timestamp.toString(), null)

...the error goes away, but I get a rejection with the following content instead:

{
"code": "2",
"message": "There was a problem with the App Store.",
"domain": "RevenueCat.ErrorCode",
"userInfo": {
"readableErrorCode": "STORE_PROBLEM",
"readable_error_code": "STORE_PROBLEM",
"source_file": "RevenueCat/SKError+Extensions.swift:64",
"NSLocalizedDescription": "There was a problem with the App Store.",
"source_function": "asPurchasesError",
"NSUnderlyingError": {
"code": "0",
"message": "underlying error",
"domain": "SKErrorDomain",
"userInfo": {
"NSUnderlyingError": {
"code": "500",
"message": "underlying error",
"domain": "ASDErrorDomain",
"userInfo": {
"NSUnderlyingError": {
"code": "301",
"message": "underlying error",
"domain": "AMSErrorDomain",
"userInfo": {
"NSLocalizedDescription": "Invalid Status Code",
"AMSStatusCode": 500,
"AMSURL": "https://sandbox.itunes.apple.com/WebObjects/MZBuy.woa/wa/inAppBuy?REDACTED",
"NSLocalizedFailureReason": "The response has an invalid status code"
},
"nativeStackIOS": [
"0 MYAPPNAME 0x0000000100f7ef74 RCTJSErrorFromCodeMessageAndNSError + 112",
"1 MYAPPNAME 0x0000000100f7f22c RCTJSErrorFromCodeMessageAndNSError + 808",
"2 MYAPPNAME 0x0000000100f7f22c RCTJSErrorFromCodeMessageAndNSError + 808",
"3 MYAPPNAME 0x0000000100f7f22c RCTJSErrorFromCodeMessageAndNSError + 808",
"4 MYAPPNAME 0x0000000100f1d060 __41-[RCTModuleMethod processMethodSignature]_block_invoke_2.73 + 152",
"5 MYAPPNAME 0x0000000100d20100 -[RNPurchases rejectPromiseWithBlock:error:] + 224",
"6 MYAPPNAME 0x0000000100d202cc __60-[RNPurchases getResponseCompletionBlockWithResolve:reject:]_block_invoke + 104",
"7 MYAPPNAME 0x0000000100c86ef8 $sSo12NSDictionaryCSg21PurchasesHybridCommon14ErrorContainerCSgIeyByy_SDySSypGSgAGIeggg_TR + 164",
"8 MYAPPNAME 0x0000000100c88738 $s21PurchasesHybridCommon0C13FunctionalityC8purchase7package18offeringIdentifier23signedDiscountTimestamp10completionySS_S2SSgySDySSypGSg_AA14ErrorContainerCSgtctFZy10RevenueCat16StoreTransactionCSg_AO12CustomerInfoCSgs0M0_pSgSbtYbcfU_ + 292",
"9 MYAPPNAME 0x0000000100c880bc $s10RevenueCat16StoreTransactionCSgAA12CustomerInfoCSgs5Error_pSgSbIeghgggy_AdGSo7NSErrorCSgSbIeghgggy_TR + 140",
"10 MYAPPNAME 0x0000000100c8814c $s10RevenueCat16StoreTransactionCSgAA12CustomerInfoCSgSo7NSErrorCSgSbIeghgggy_AdgJ10ObjectiveC8ObjCBoolVIeyBhyyyy_TR + 120",
"11 MYAPPNAME 0x00000001013518f0 $s10RevenueCat16StoreTransactionCSgAA12CustomerInfoCSgSo7NSErrorCSg10ObjectiveC8ObjCBoolVIeyBhyyyy_AdgJSbIeghgggy_TR + 68",
"12 MYAPPNAME 0x00000001013f7180 $s10RevenueCat21PurchasesOrchestratorC8purchase10sk1Product7payment7package7wrapper10completionySo9SKProductC_So16SKMutablePaymentCAA7PackageCSgAA16StoreKit1WrapperCyAA0P11TransactionCSg_AA12CustomerInfoCSgSo7NSErrorCSgSbtYbScMYcctFyAU_AXA_SbtYbScMYccfU0_ + 664",
"13 MYAPPNAME 0x00000001013fdd40 $s10RevenueCat16StoreTransactionCSgAA12CustomerInfoCSgSo7NSErrorCSgSbIeghgggy_AdgJSbytIeghnnnnr_TR + 40",
"14 MYAPPNAME 0x0000000101401490 $s10RevenueCat16StoreTransactionCSgAA12CustomerInfoCSgSo7NSErrorCSgSbytIeghnnnnr_AdgJSbIeghgggy_TR + 144",
"15 MYAPPNAME 0x00000001013fdd40 $s10RevenueCat16StoreTransactionCSgAA12CustomerInfoCSgSo7NSErrorCSgSbIeghgggy_AdgJSbytIeghnnnnr_TR + 40",
"16 MYAPPNAME 0x0000000101401490 $s10RevenueCat16StoreTransactionCSgAA12CustomerInfoCSgSo7NSErrorCSgSbytIeghnnnnr_AdgJSbIeghgggy_TR + 144",
"17 MYAPPNAME 0x00000001013ff7b8 $s10RevenueCat21PurchasesOrchestratorC23handleFailedTransaction33_B8F471F86775DD0D24EF3C9BB319BEBBLLyySo09SKPaymentG0CFyyYbScMYccfU1_ + 144",
"18 MYAPPNAME 0x000000010137f3d0 $s10RevenueCat19OperationDispatcherC19dispatchOnMainActoryyyyYbScMYccFZyyYaYbScMYccfU_TY0_ + 88",
"19 MYAPPNAME 0x000000010137f5c5 $s10RevenueCat19OperationDispatcherC19dispatchOnMainActoryyyyYbScMYccFZyyYaYbScMYccfU_TATQ0_ + 1",
"20 MYAPPNAME 0x00000001013f024d $sIeghH_ytIeghHr_TRTQ0_ + 1",
"21 MYAPPNAME 0x000000010137f6fd $sIeghH_ytIeghHr_TRTATQ0_ + 1",
"22 MYAPPNAME 0x0000000101207d9d $sxIeghHr_xs5Error_pIegHrzo_s8SendableRzs5NeverORs_r0_lTRTQ0_ + 1",
"23 MYAPPNAME 0x0000000101207eed $sxIeghHr_xs5Error_pIegHrzo_s8SendableRzs5NeverORs_r0_lTRTATQ0_ + 1",
"24 libswift_Concurrency.dylib 0x00000001dd439dd9 265F5F8D-C650-318E-B5B8-1A6A0532D653 + 298457"
]
}
}
},
"NSLocalizedDescription": "An unknown error occurred"
}
}
},
"userCancelled": false
}

I’m unsure what to do at this point and would appreciate any kind of help.
I’m testing in the sandbox environment.

Thanks in advance,
Birger


3 replies

Userlevel 4
Badge +6

Hey @birger ,

 

When calling this method, you should need to pass in only the following:

  • product: PurchasesStoreProduct
  • discount: PurchasesPromotionalOffer

When you pass those in only, is an error displayed other than the 4 arguments complaint? 

 

More information on how this method is implemented can be found here: https://github.com/RevenueCat/react-native-purchases/blob/1a7cb0af83b91ca7c4921d6516979ff2d3560331/src/purchases.ts#L495

 

This error you are receiving is forwarded from Apple/Google/Amazon and indicates there was a problem connecting to the App Store, Play Store, or Amazon Appstore.

The problems that will trigger this on iOS:

The problems that will trigger this on Android:

 

I will also share this with someone on the SDK team to get some more eyes on what could be going wrong here! 

 

Badge

Hey Michael,

Thank you for your response. You are actually referring to purchaseDiscountedProduct instead of purchaseDiscountedPackage. I was able to resolve the store issue on my end and with the previously mentioned fix that already found its way into the main branch the issue should be resolved though. So now I’m looking forward to a new React Native SDK release.

Thanks again,
Birger

Userlevel 4
Badge +6

Hey Birger, 

 

Glad to hear that is solved, let us know if you have any other questions! 

 

Reply