-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedcBridge.js
1 lines (1 loc) · 4.3 KB
/
edcBridge.js
1
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.edcBridge=t():e.edcBridge=t()}(self,(()=>{return e={989:e=>{e.exports={"00":"APPROVE",54:"DECLINE EXPIRED CARD",55:"DECLINE EXPIRED PIN",P2:"READ CARD ERROR",P3:"USER PRESS CANCEL ON EDC",Z3:"EMV CARD DECLINE",CE:"CONNECTION ERROR / LINE BUSY TO CONNECTION TIMEOUT",PT:"EDC PROBLEM",S2:"FAILED TRANSACTION",S3:"TXN BLM DIPROSES MINTA SCAN QR",S4:"TXN EXPIRED"}},288:e=>{e.exports={BCA:{ecrVersion:[0,1],transAmount:[3,15],otherAmount:[15,27],PAN:[27,46],expiryDate:[46,50],rrn:[52,64],approvalCode:[64,70],date:[70,78],time:[78,84],merchantId:[84,99],terminalId:[99,107],offlineFlag:[107,108],cardHolderName:[108,134],panCashierFlag:[134,150],invoiceNumber:[150,156],batchNumber:[156,162],issuerId:[162,164],installmentFlag:[164,165],dccFlag:[165,166],redeemFlag:[166,167],informationAmount:[167,179],dccDecimalPlace:[179,180],dccCurrencyName:[180,183],dccExchangeRate:[183,191],couponFlag:[191,192],filler:[192,200]},MANDIRI:{terminalId:0,merchantId:1,cardType:2,PAN:3,entryMode:4,transTypeStr:5,batchNumber:6,traceNumber:7,date:8,time:9,referenceCode:10,approvalCode:11,transAmount:12}}},706:e=>{e.exports={BCA:{"01":"PURCHASE",17:"ECHO_TEST","08":"VOID"},MANDIRI:{10:"SALE",20:"VOID",";0":"ECHO_TEST"}}},437:(e,t,r)=>{const{calculateLRCBCA:n,setAmountBCA:a,formatCardNumberBCA:o,calculateCRCMandiri:c,setAmountMandiri:i,checkDataValidity:s}=r(555),d=r(288),l=r(706),C=r(989);e.exports={constructMessage:({msgLength:e="P",ecrVersion:t="",amount:r=1,cardNumber:s=" ",expireDate:d=" ",transType:l="01",cancelReason:C="00",invoiceNumber:p="000000",genericData:u=" ",authorizationIDResponse:A="000000"}={},m="BCA")=>{let I=null;if("BCA"==m){const c="000000000000",i=" ",m=" ",E="N",N="000",D="00",f=" ",R=" ",S=`${e}${t}${l}${r=a(r.toString())}${c}${s=o(s)}${d}${C}${p}${A}${i}${m}${E}${N}${D}${u=u.padEnd(12," ")}${f}${R}`;I=`${S}${n(S)}`}else{if(!(m="MANDIRI"))throw"Invalid issuer ID";{const e=`${t=""}${l="10"}${r=`${r=i(r.toString())}000000000000`}`;I=`${e}${c(e)}`}}return I},parseResponse:async(e,t,r="BCA")=>{let a,o=[];if(1===e.length){const t=parseInt(e[0]);switch(t){case 6:o._type="ACK";break;case 15:o._type="NAK";break;default:o._type="UND",o.respCode=t}return o}if(o._type="MSG",o.hashValue=e.slice(-1).toString(),"BCA"===r){if(a=n(e.slice(1,-1),!0),s(a,o.hashValue,t))return e=e.slice(3,-2),await(async(e,t,r)=>{const n=new TextDecoder,a=t.slice(1,3),o=n.decode(a).trim();if(!Object.keys(l.BCA).includes(o))return[];e.transType=l.BCA[o];const c=n.decode(t.slice(50,52)).trim();for(segmentProp in Object.keys(C).includes(c)?e.respCode=C[c]:e.respCode=`DECLINE ${c}`,d.BCA){const r=d.BCA[segmentProp];e[segmentProp]=n.decode(t.slice(r[0],r[1])).trim()}if(""!=e.date){const t=/^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/,[,r,n,a,o,c,i]=t.exec(`${e.date}${e.time}`);e.datetime=new Date(r,n,a,o,c,i).toISOString()}return await r.write((new TextEncoder).encode("")),e})(o,e,t)}else{if("MANDIRI"!==r)throw"Invalid issuer ID";if(a=c(e.slice(1,-1),!0),s(a,o.hashValue,t))return e=e.slice(2,-2),await(async(e,t,r)=>{const n=(new TextDecoder).decode(t.slice(0,2));if(!Object.keys(l.MANDIRI).includes(n))return[];e.transType=l.MANDIRI[n];const a=(new TextDecoder).decode(t.slice(4)).split("|");for(segmentProp in d.MANDIRI)e[segmentProp]=a[d.MANDIRI[segmentProp]];return""!=e.date&&(e.datetime=new Date(`${e.date} ${e.time}`).toISOString()),await r.write((new TextEncoder).encode("")),e})(o,e,t)}}}},555:e=>{e.exports={calculateLRCBCA:(e,t=!1)=>{t&&(e=(new TextDecoder).decode(e));let r=0;for(s of e)r^=s.charCodeAt();return t?r.toString():String.fromCharCode(parseInt(r.toString(16),16))},setAmountBCA:e=>(e=e.toString(),(e+="00").padStart(12,"0")),setAmountMandiri:e=>e.padStart(12,"0"),formatCardNumberBCA:e=>e.padEnd(19," "),calculateCRCMandiri:(e,t=!1)=>{t&&(e=(new TextDecoder).decode(e));let r=0;for(let t of e)r^=t.charCodeAt(0);return String.fromCharCode(parseInt(r.toString(16),16))},checkDataValidity:async(e,t,r)=>e===t||(await r.write((new TextEncoder).encode("")),!1)}}},t={},function r(n){var a=t[n];if(void 0!==a)return a.exports;var o=t[n]={exports:{}};return e[n](o,o.exports,r),o.exports}(437);var e,t}));