@pqthanh/pay-code-gen
Version:
A package to generate pay codes for fast money transfer (excluding QR code generation).
2 lines (1 loc) • 2.12 kB
JavaScript
function h(n){let r=65535;for(let e=0;e<n.length;e++){r^=n[e]<<8;for(let s=0;s<8;s++)r&32768?r=r<<1^69665:r<<=1,r&=65535}return r}function c(n){return n.normalize("NFD").replace(/[\u0300-\u036f]/g,"")}function p(n){return String(n).padStart(2,"0")}var u=class{payload=new Map;validate(){}value(){return this.validate(),this.build(this.payload)}set(t,r){t=Array.isArray(t)?t:[t];let e=this.payload;for(let s=0;s<t.length-1;s++){let i=t[s];e.has(i)||e.set(i,new Map);let o=e.get(i);o instanceof Map||(o=new Map,e.set(i,o)),e=o}return e.set(t[t.length-1],r),this}remove(...t){t.forEach(this.payload.delete,this.payload)}build(t){return Array.isArray(t)||t instanceof Map?Array.from(t).sort(([r],[e])=>r<e?-1:r>e?1:0).reduce((r,[e,s])=>{let i=this.build(s);return i?r+p(e)+p(i.length)+i:r},""):t.toString()}};var x=1,A=2,b=3,E=4,y=5,S=6,L=7,M=8,B=9;var a=class extends u{guid="A000000727";constructor(){super(),this.set(0,"01").static().currency().country()}toString(){let t=this.value()+"6304",r=new TextEncoder().encode(t);return t+h(r).toString(16).toUpperCase()}static(){return this.set(1,"11")}dynamic(){return this.set(1,"12")}acquirer(t){return this.set([38,0],this.guid),this.set([38,1,0],t),this}cosumer(t){return this.set([38,0],this.guid),this.set([38,1,1],t),this}cosumerType(t="A"){return this.set([38,0],this.guid),this.set([38,2],"QRIBFTT"+t),this}category(t){return this.set(52,t.toString())}currency(t=704){return this.set(53,t.toString())}amount(t){return this.set(54,t.toString())}tip(){return this.set(55,"01").remove(56,57)}fixedFee(t){return this.set(56,t.toString()).remove(54,57)}percentFee(t){return this.set(57,t.toString()).remove(54,56)}country(t="VN"){return this.set(58,t)}bankName(t){return this.set(59,t)}city(t){return this.set(60,t)}portal(t){return this.set(61,t)}additional(t,r){return this.set([62,t],c(r))}content(t){return this.set([62,8],c(t))}validate(){}};export{B as ADDITIONAL_CONSUMER_DATA_REQUEST,x as BILL_NUMBER,S as CUSTOMER_LABEL,E as LOYALTY_NUMBER,A as MOBILE_NUMBER,M as PURPOSE_OF_TRANSACTION,y as REFERENCE_LABEL,b as STORE_LABEL,L as TERMINAL_LABEL,a as default};