var cmcic = require('cmcic');
var tpe = new cmcic.tpe({
CMCIC_TPE: 'tpeid',
CMCIC_CODESOCIETE: 'societykey',
CMCIC_CLE: '1234567890abcdef',
CMCIC_BANK: 'CIC',
CMCIC_LNG: 'FR',
CMCIC_CURRENCY: 'EUR',
CMCIC_URL_RETOUR: '/url/return',
CMCIC_URLOK: '/url/ok',
CMCIC_URLKO: '/url/ko'
});
var t = {
email: 'exemple@exemple.fr',
amount: 300,
reference: 'qwerty'
};
var trans = new cmcic.transaction(tpe, t);
// if you use expressjs
res.send(trans.form('paimentid', true));
On your return url (still with expressjs)
var ret = tpe.checkTransactionReturn((req.method == 'POST')? req.body : req.query);
if (!ret.isSealValidated) {
console.log('MAC seal is invalid')
return res.send(tpe.RETURN_NOTOK);
}
if (ret.status) {
console.error('Payment is ok');
res.send(tpe.RETURN_OK);
} else {
console.error('Payment is fail : ', ret.motifrefus );
res.send(tpe.RETURN_OK);
}
For handle different kind of payment with the same TPE, you can use the 'texte-libre' field ! You can use 'texte-libre' field like an object, it ll be stringified/parsed for you.
- tabulation (4 width)
- JsHint
https://github.com/PierrickP/cmcic/issues?labels=new-feature&page=1&state=open
Under MIT license, feel free to contribuate with fork and PR !