我的后端有一些代码,可用来尝试通过库 node-iap 验证苹果的购买收据。
我已经收到所有收据进行验证,但是我在尝试一些非常简单的事情:
尝试使代码返回到 iap.verifyPayment 方法之外,以便继续执行Subscribe方法中的代码并返回成功。它只是挂在handleAppleSub中而不会返回。
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;
});
});