mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-08-01 19:50:37 +00:00
improve error reporting for iOS IAP
This commit is contained in:
parent
6467dd8fc0
commit
39adff0e2c
2 changed files with 25 additions and 7 deletions
|
|
@ -209,8 +209,15 @@ describe 'In-App Purchases', ->
|
||||||
|
|
||||||
it 'does not call res.json', ->
|
it 'does not call res.json', ->
|
||||||
inApp.iosVerify(req, res, next)
|
inApp.iosVerify(req, res, next)
|
||||||
|
expectedResObj = {
|
||||||
expect(res.json).to.not.be.called
|
ok: false
|
||||||
|
data: {
|
||||||
|
code: 6778001
|
||||||
|
message: 'Invalid receipt'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(res.json).to.be.calledOnce
|
||||||
|
expect(res.json).to.be.calledWith(expectedResObj)
|
||||||
|
|
||||||
it 'does not calls payments.buyGems function', ->
|
it 'does not calls payments.buyGems function', ->
|
||||||
inApp.iosVerify(req, res, next)
|
inApp.iosVerify(req, res, next)
|
||||||
|
|
@ -231,7 +238,7 @@ describe 'In-App Purchases', ->
|
||||||
ok: false
|
ok: false
|
||||||
data: {
|
data: {
|
||||||
code: 6778001
|
code: 6778001
|
||||||
message: 'Incorrect receipt'
|
message: 'Incorrect receipt content'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -259,7 +266,7 @@ describe 'In-App Purchases', ->
|
||||||
ok: false
|
ok: false
|
||||||
data: {
|
data: {
|
||||||
code: 6778001
|
code: 6778001
|
||||||
message: 'Incorrect receipt'
|
message: 'Incorrect receipt content'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,7 @@ exports.iosVerify = function(req, res, next) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// iap is ready
|
//iap is ready
|
||||||
iap.validate(iap.APPLE, iapBody.transaction.receipt, function (err, appleRes) {
|
iap.validate(iap.APPLE, iapBody.transaction.receipt, function (err, appleRes) {
|
||||||
if (err) {
|
if (err) {
|
||||||
var resObj = {
|
var resObj = {
|
||||||
|
|
@ -102,6 +102,7 @@ exports.iosVerify = function(req, res, next) {
|
||||||
var purchaseDataList = iap.getPurchaseData(appleRes);
|
var purchaseDataList = iap.getPurchaseData(appleRes);
|
||||||
if (purchaseDataList.length > 0) {
|
if (purchaseDataList.length > 0) {
|
||||||
if (purchaseDataList[0].productId === "com.habitrpg.ios.Habitica.20gems") {
|
if (purchaseDataList[0].productId === "com.habitrpg.ios.Habitica.20gems") {
|
||||||
|
//Correct receipt
|
||||||
payments.buyGems({user:user, paymentMethod:'IAP AppleStore'});
|
payments.buyGems({user:user, paymentMethod:'IAP AppleStore'});
|
||||||
var resObj = {
|
var resObj = {
|
||||||
ok: true,
|
ok: true,
|
||||||
|
|
@ -111,16 +112,26 @@ exports.iosVerify = function(req, res, next) {
|
||||||
return res.json(resObj);
|
return res.json(resObj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//wrong receipt content
|
||||||
var resObj = {
|
var resObj = {
|
||||||
ok: false,
|
ok: false,
|
||||||
data: {
|
data: {
|
||||||
code: INVALID_PAYLOAD,
|
code: INVALID_PAYLOAD,
|
||||||
message: "Incorrect receipt"
|
message: "Incorrect receipt content"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return res.json(resObj);
|
return res.json(resObj);
|
||||||
}
|
}
|
||||||
|
//invalid receipt
|
||||||
|
var resObj = {
|
||||||
|
ok: false,
|
||||||
|
data: {
|
||||||
|
code: INVALID_PAYLOAD,
|
||||||
|
message: "Invalid receipt"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return res.json(resObj);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue