Skip to content

Instantly share code, notes, and snippets.

@totuworld
Last active March 24, 2016 01:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save totuworld/8687dc2c59d26ca97ae9 to your computer and use it in GitHub Desktop.
Save totuworld/8687dc2c59d26ca97ae9 to your computer and use it in GitHub Desktop.
apple iap validation
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