-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Created verifyPayment alternative function to return Promise #69
Conversation
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;
} |
… of either Callback-based or Promise-based implementation styles
I followed this implementation. Please check if the code is now meeting the requirements. |
Can u merge it please? @ronkorving |
Done, cheers 👍 |
Could we get this released on npm? Relevant issue here #81 |
Created an alternative method for verifyPayment that uses promises instead of callbacks.
Should fix #68