Closed faboyds closed 4 years ago
This removes the callback-style API from the library. In other words, while your new function works, the old one is gone (overwritten).
I would love Promise support, so I think you're on the right track here, but we need a solid solution that we can apply to all APIs, while still supporting callback-style. I think it's possible. Please reconsider a solution.
Ok, I understand and I agree with you. I will take a deeper look into this when I have more time, and I'll try to deliver a more complete solution.
@faboyds have a look how I did it here: https://github.com/superandrew213/react-native-in-app-utils/blob/listen-for-purchase-event/index.js
You end up with a single method that you can call like this if you want to use callbacks:
method(arg1, arg2, (error, res) => {})
or like this if you want to use Promises:
method(arg1, arg2).then(res => {}).catch(error => {})
@faboyds An alternative way you could handle this issue is through bluebird promisfy all:
http://bluebirdjs.com/docs/api/promise.promisifyall.html
Simply wrap the existing package:
const iap: any = Bluebird.promisifyAll(require("iap"));
And then you can do something like:
// Verify payment from iap service
let responseFromApple = await iap.verifyPaymentAsync(
"apple", subscriptionWithSharedSecret
)
.catch(e => {
logger.error(
"Receipt.validateApplePurchase: failed to validate apple " +
"receipt",
{ message: e.message, subscription }
);
return Err("ValidationError", e.message);
});
if (isError(responseFromApple)) {
return responseFromApple;
}
@faboyds have a look how I did it here: https://github.com/superandrew213/react-native-in-app-utils/blob/listen-for-purchase-event/index.js
You end up with a single method that you can call like this if you want to use callbacks:
method(arg1, arg2, (error, res) => {})
or like this if you want to use Promises:
method(arg1, arg2).then(res => {}).catch(error => {})
I followed this implementation. Please check if the code is now meeting the requirements. And thank you for your suggestions! 😄
Can u merge it please? @ronkorving
Done, cheers 👍
Could we get this released on npm?
Relevant issue here https://github.com/Wizcorp/node-iap/issues/81
Created an alternative method for verifyPayment that uses promises instead of callbacks.
Should fix #68