3.2.3
0.58.6
iOS
When the user cancels a transaction, RNIap.buyProduct returns null instead of raising an exception with error.code E_USER_CANCELLED.
When the user cancels a transaction, RNIap.buyProduct returns null
Real device
This is the code:
async buyItem(sku) {
try {
const purchase = await RNIap.buyProduct(sku)
if (!purchase) {
// This should not happen
return
}
// Omitted code
} catch (err) {
if (err.code && err.code === 'E_USER_CANCELLED') {
// Not being called
}
}
}
@kennym I've seen related issue earlier and we need to fix this. Currently, cancelling send @null array in ios. I hope you can give us a PR.
You can (and probably should) use the new listener pattern to listen to errors. An error with responseCode 1 on android and "2" on iOS means the user cancelled. Note that iOS will give you the code as a string while Android enters it as an integer.
@solidfox I think it should be handled in plugin as @hyochan suggested. The plugin shall send the same error code for both Android and iOS in the updated listener pattern too.
I see currently Listner is sending error: responseCode, debugMessage. We can add additional error keys generated by rejectPromiseWithBillingError() or standardErrorCode.
I will try sending PR this weekend. If anyone can do it early, please do it 馃槃
The flow and TypeScript type of responseCode is number, but it's string on iOS 馃し鈥嶁檪
Closed via #616
Most helpful comment
@solidfox I think it should be handled in plugin as @hyochan suggested. The plugin shall send the same error code for both Android and iOS in the updated listener pattern too.
I see currently Listner is sending error:
responseCode, debugMessage. We can add additional error keys generated byrejectPromiseWithBillingError()orstandardErrorCode.I will try sending PR this weekend. If anyone can do it early, please do it 馃槃