Last active
March 24, 2016 01:22
-
-
Save totuworld/8687dc2c59d26ca97ae9 to your computer and use it in GitHub Desktop.
apple iap validation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const iap = require('in-app-purchase'); | |
iap.config({applePassword:""}); | |
iap.setup(function (err) { | |
if (err) { | |
return console.error('something went wrong...'); | |
} | |
else { | |
console.log('iap init done'); | |
} | |
}); | |
/* POST validation ios */ | |
router.post('/appleiap/receipt/validation', function(req, res, next) { | |
let parseRawRecipt = JSON.parse(req.body.RawReceipt); | |
if(req.body.RawReceipt === null | |
|| req.body.RawReceipt === undefined) { | |
res.send({result:false}); | |
return; | |
} | |
if(parseRawRecipt['transaction-receipt'] === undefined) { | |
res.send( | |
{result:false, | |
error:'receipt invalid transaction receipt'}); | |
} | |
iap.validate( | |
iap.APPLE, | |
parseRawRecipt['transaction-receipt'], | |
function (err, appleRes) { | |
//에러 발생시 에러 전달 | |
if (err) { | |
res.send({result:false, error:`${err}`}); | |
return; | |
} | |
//검증되었는지 확인 | |
if (iap.isValidated(appleRes)) { | |
res.send({result:true}); | |
} | |
else { | |
res.send({result:false}); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment