I have some code on my back end that I am using to try and verify apple purchase receipts with the library node-iap.
I've got all the receipt to verify but I am struggling with something really simple:
Trying to get the code to return out of the iap.verifyPayment method to carry on with the code execution in the subscribe method and return a success. It just hangs within handleAppleSub and doesn't return.
export const subscribe = (req, res, next) => {
return User.findOne({
where: {
ID: req.params.ID
}
})
.then(
user =>
user
? req.body.OS == "android"
? handleAndroidSub(user, req.body.receipt)
: handleAppleSub(user, req.body.receipt)
: notFound(res)
)
.then(success(res))
.catch(next);
};
const handleAppleSub = (user, receipt) => {
var platform = "apple";
var payment = {
receipt: receipt.transactionReceipt,
productId: receipt.productId,
packageName: "com.app.test",
secret: appleSecret,
excludeOldTransactions: true
};
return iap.verifyPayment(platform, payment, function(error, response) {
user.dataValues.SubAppleReceipt = receipt.transactionReceipt;
return User.update(user.dataValues, {
where: { ID: user.dataValues.ID }
}).then(user => {
return user;
});
});