Skip to content
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

Merged
merged 2 commits into from
Jan 23, 2020

Conversation

faboyds
Copy link
Contributor

@faboyds faboyds commented Oct 29, 2019

Created an alternative method for verifyPayment that uses promises instead of callbacks.

Should fix #68

@ronkorving
Copy link
Collaborator

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.

@faboyds
Copy link
Contributor Author

faboyds commented Nov 1, 2019

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.

@superandrew213
Copy link
Contributor

@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 => {})

@justinpage
Copy link
Contributor

justinpage commented Nov 12, 2019

@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
@faboyds
Copy link
Contributor Author

faboyds commented Nov 19, 2019

@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! 😄

@artur-ma
Copy link

artur-ma commented Jan 21, 2020

Can u merge it please? @ronkorving

@ronkorving ronkorving merged commit 4ac0e22 into Wizcorp:master Jan 23, 2020
@ronkorving
Copy link
Collaborator

Done, cheers 👍

@SeanDunford
Copy link

Could we get this released on npm?

Relevant issue here #81

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create verifyPayment function that returns a Promise, instead of using callbacks
6 participants