UNPKG

@pqthanh/pay-code-gen

Version:

A package to generate pay codes for fast money transfer (excluding QR code generation).

2 lines (1 loc) 2.76 kB
"use strict";var p=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var f=(n,t)=>{for(var r in t)p(n,r,{get:t[r],enumerable:!0})},x=(n,t,r,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of g(t))!l.call(n,s)&&s!==r&&p(n,s,{get:()=>t[s],enumerable:!(e=d(t,s))||e.enumerable});return n};var A=n=>x(p({},"__esModule",{value:!0}),n);var b={};f(b,{ADDITIONAL_CONSUMER_DATA_REQUEST:()=>I,BILL_NUMBER:()=>_,CUSTOMER_LABEL:()=>O,LOYALTY_NUMBER:()=>N,MOBILE_NUMBER:()=>R,PURPOSE_OF_TRANSACTION:()=>U,REFERENCE_LABEL:()=>C,STORE_LABEL:()=>T,TERMINAL_LABEL:()=>v,default:()=>c});module.exports=A(b);function m(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 a(n){return n.normalize("NFD").replace(/[\u0300-\u036f]/g,"")}function h(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+h(e)+h(i.length)+i:r},""):t.toString()}};var _=1,R=2,T=3,N=4,C=5,O=6,v=7,U=8,I=9;var c=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+m(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],a(r))}content(t){return this.set([62,8],a(t))}validate(){}};0&&(module.exports={ADDITIONAL_CONSUMER_DATA_REQUEST,BILL_NUMBER,CUSTOMER_LABEL,LOYALTY_NUMBER,MOBILE_NUMBER,PURPOSE_OF_TRANSACTION,REFERENCE_LABEL,STORE_LABEL,TERMINAL_LABEL});