@danidoble/webserial 4.4.0-beta.5 → 4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/pinpax.cjs +3 -3
- package/dist/pinpax.js +117 -75
- package/dist/types/serial/pinpax.d.ts +8 -6
- package/dist/types/serial/pinpax.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/pinpax.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
2
|
-
`,this.#t(),
|
|
3
|
-
`);await this.appendToQueue(this.stringArrayToUint8Array(
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./kernel-9JeWIxgz.cjs"),s=require("./relay-E3NCcSjS.cjs");class p extends c.Kernel{__pinpax__={server:"DEV",businessId:null,encryptionKey:null,apiKey:null,asyncResponses:{voucher:null,sale:null},waiting:{voucher:!1,sale:!1,sale_init:"idle",sale_login:"idle"}};constructor({filters:i=null,config_port:e={baudRate:115200,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"},no_device:t=1,device_listen_on_channel:a=1,socket:n=!1}={filters:null,config_port:{baudRate:115200,dataBits:8,stopBits:1,parity:"none",bufferSize:32768,flowControl:"none"},no_device:1,device_listen_on_channel:1,socket:!1}){if(super({filters:i,config_port:e,no_device:t,device_listen_on_channel:a,socket:n}),this.__internal__.device.type="pinpax",c.Devices.getCustom(this.typeDevice,t))throw new Error(`Device ${this.typeDevice} ${t} already exists`);this.__internal__.time.response_connection=4e3,this.__internal__.time.response_general=3e3,this.__internal__.serial.delay_first_connection=1e3,this.__internal__.serial.response.replacer="",this.__internal__.serial.response.limiter=`\r
|
|
2
|
+
`,this.#t(),c.Devices.add(this),this.getResponseAsString()}#t(){const i=["buttons-status","init-app","connectMessage","voucher","info","keep-alive","reset-app","get-config","payment","error","refund","login"];for(const e of i)this.serialRegisterAvailableListener(e)}set businessId(i){this.__pinpax__.businessId=i}get businessId(){return this.__pinpax__.businessId}set encryptionKey(i){this.__pinpax__.encryptionKey=i}get encryptionKey(){return this.__pinpax__.encryptionKey}set apiKey(i){this.__pinpax__.apiKey=i}get apiKey(){return this.__pinpax__.apiKey}set server(i){this.__pinpax__.server=i}get server(){return this.__pinpax__.server}serialMessage(i){let e=null;try{e=JSON.parse(i),e.request||(e.request=this.lastAction),e.name||(e.name=this.lastAction)}catch(t){console.error("Error parsing response",t,i),this.dispatch("serial:message",i);return}switch(e.response){case"INIT":this.dispatch("init",{name:"INIT",request:this.lastAction,status:"ok"}),this.__pinpax__.waiting.sale_init==="waiting"&&(this.__pinpax__.waiting.sale_init="received");break;case"INITAPP":this.dispatch("init-app",{name:"INITAPP",request:this.lastAction,status:"started"}),this.__pinpax__.waiting.sale_init==="waiting"?this.__pinpax__.waiting.sale_init="received":this.#n().then(()=>{});break;case"CONNECT":this.dispatch("connectMessage",{name:"CONNECT",request:this.lastAction,status:"connected"}),this.#r().then(()=>{});break;case"LOGIN":e.name||(e.name="LOGIN"),this.__pinpax__.waiting.sale_login==="waiting"&&(this.__pinpax__.waiting.sale_login="received"),this.dispatch("login",e);break;case"LASTVOUCHER":e.name||(e.name="LASTVOUCHER"),this.dispatch("voucher",e),this.__pinpax__.waiting.voucher&&(this.__pinpax__.asyncResponses.voucher=e,this.__pinpax__.waiting.voucher=!1);break;case"DEVICEINFO":e.name||(e.name="DEVICEINFO"),this.dispatch("info",e);break;case"KEEPALIVE":this.dispatch("keep-alive",{name:"KEEPALIVE",request:this.lastAction,status:"alive"});break;case"RESETAPP":this.dispatch("reset-app",{name:"RESETAPP",request:this.lastAction,status:"accepted"});break;case"GETCONFIG":e.name||(e.name="GETCONFIG"),this.dispatch("get-config",e);break;case"HIDEBUTTONS":this.dispatch("buttons-status",{name:"HIDEBUTTONS",request:this.lastAction,hidden:!0});break;case"SHOWBUTTONS":this.dispatch("buttons-status",{name:"SHOWBUTTONS",request:this.lastAction,hidden:!1});break;case"PAYMENT_PROCESS":e.name||(e.name="PAYMENT_PROCESS"),this.dispatch("payment",{name:"PAYMENT_PROCESS",request:this.lastAction,status:"starting",amount:e.amount,reference:e.referecence});break;case"INSERT_CARD":this.dispatch("payment",{name:"INSERT_CARD",request:this.lastAction,status:"insert card"});break;case"CARD_DATA":e.name||(e.name="CARD_DATA"),this.dispatch("payment",{name:"CARD_DATA",request:this.lastAction,status:"card data",amount:e.amount,cardHolderName:e.cardHolderName,ccMark:e.ccMark,ccType:e.ccType,currency:e.currency,maskedPan:e.maskedPan,readingType:e.readingType});break;case"MERCHANT":e.name||(e.name="MERCHANT"),this.dispatch("payment",{request:this.lastAction,status:"merchant",afiliation:e.afiliation,alias:e.alias,amountCashBackCommission:e.amountCashBackCommission,currency:e.currency,description:e.description,hasCashBack:e.hasCashBack,limitCashBackAmount:e.limitCashBackAmount,merchant:e.merchant,months:e.months,name:e.name});break;case"TRANSACTION_RESULT":e.name||(e.name="TRANSACTION_RESULT"),this.#o({status:"result",approved:e.approved,acquirer:e.acquirer,address:e.address,amount:e.amount,amountCashback:e.amountCashback,appIDLabel:e.appIDLabel,appId:e.appId,arqc:e.arqc,auth:e.auth,ccBin:e.ccBin,ccExpirationDate:e.ccExpirationDate,ccName:e.ccName,ccNumber:e.ccNumber,ccType:e.ccType,comissionCashback:e.comissionCashback,currency:e.currency,date:e.date,errorCode:e.errorCode,errorDescription:e.errorDescription,folio:e.folio,id:e.id,merchantName:e.merchantName,msiLabel:e.msiLabel,operation:e.operation,pin:e.pin,qps:e.qps,reference:e.reference,response:e.response,source:e.source,sourceLabel:e.sourceLabel,time:e.time});break;case"ERROR":e.name||(e.name="ERROR"),this.__pinpax__.waiting.sale&&(this.__pinpax__.asyncResponses.sale={status:"error",approved:!1,response:e}),this.dispatch("error",{name:"ERROR",request:this.lastAction,status:"error",response:e}),this.dispatch("payment",{name:"ERROR",request:this.lastAction,status:"error",response:e});break;case"REFUND":this.dispatch("refund",{name:"ERROR",request:this.lastAction,status:"refund",response:e});break}this.dispatch("serial:message",e)}serialSetConnectionConstant(){return s.s.connection()}softReload(){super.softReload(),this.__pinpax__.waiting.sale=!1,this.__pinpax__.waiting.voucher=!1,this.__pinpax__.asyncResponses.sale=null,this.__pinpax__.asyncResponses.voucher=null}async sendCustomCode(i={}){if(typeof i!="object")throw new Error("Invalid object");if(i.constructor!==Object)throw new Error("Invalid object");if(Object.keys(i).length===0)throw new Error("Empty object");if(i.action===void 0||i.action===null)throw new Error("Invalid object add action");const e=JSON.stringify(i),t=this.parseStringToBytes(e,`\r
|
|
3
|
+
`);await this.appendToQueue(this.stringArrayToUint8Array(t),"custom")}async connectMessage(){await this.appendToQueue(s.s.connect(),"connect:message")}async#e(){if(this.isDisconnected)throw new Error("Device is disconnected");return this.queue.length===0?!0:new Promise(i=>{const e=setInterval(()=>{this.queue.length===0&&(clearInterval(e),i(!0))},500)})}async#i({type:i="production"}={}){const e=s.s.readQR({type:i});return await this.appendToQueue(e,"read-qr")}async#s(){await this.appendToQueue(s.s.forceHide(),"force-hide")}async#a(){await this.appendToQueue(s.s.forceShow(),"force-show")}async#n(){await this.connectMessage()}async#r(){await this.hideButtons()}#o(i){this.dispatch("payment",i),this.__pinpax__.waiting.sale&&(this.__pinpax__.asyncResponses.sale=i)}cancelSaleRequestInProcess(){this.__pinpax__.waiting.sale&&(this.__pinpax__.asyncResponses.sale={status:"error",approved:!1,response:{}})}async#c(){return new Promise((i,e)=>{const t=setTimeout(()=>{this.__pinpax__.waiting.sale_login==="waiting"&&(this.__pinpax__.waiting.sale_login="timeout",e(new Error("Login timeout")))},1e4),a=setInterval(()=>{this.__pinpax__.waiting.sale_login==="received"&&(clearTimeout(t),clearInterval(a),i(!0))},100)})}async#p(){return new Promise((i,e)=>{const t=setTimeout(()=>{this.__pinpax__.waiting.sale_init==="waiting"&&(this.__pinpax__.waiting.sale_init="timeout",e(new Error("Init timeout")))},1e4),a=setInterval(()=>{this.__pinpax__.waiting.sale_init==="received"&&(clearTimeout(t),clearInterval(a),i(!0))},100)})}async makeSale({amount:i=0,reference:e=null}={amount:0,reference:null}){if(this.isDisconnected)throw new Error("Device is disconnected");if(this.__pinpax__.waiting.sale)throw new Error("Already waiting for sale response");const t=s.s.makeSale({amount:i,reference:e});this.__pinpax__.waiting.sale=!0,this.__pinpax__.asyncResponses.sale=null,this.queue.length>0&&await this.#e();let a=!1;try{this.__pinpax__.waiting.sale_login="waiting",await this.login(),await this.#c(),this.__pinpax__.waiting.sale_login="idle",this.__pinpax__.waiting.sale_init="waiting",await this.init(),await this.#p(),this.__pinpax__.waiting.sale_init="idle"}catch(n){a=!0,this.__pinpax__.waiting.sale_login="idle",this.__pinpax__.waiting.sale_init="idle",this.__pinpax__.waiting.sale=!1,this.dispatch("error",{name:"ERROR",request:this.lastAction,status:"error",response:"Error during login/init before sale",error:n})}return a?!1:(await this.appendToQueue(t,"make-sale"),new Promise(n=>{const r=setInterval(()=>{if(this.__pinpax__.asyncResponses.sale){const o=this.__pinpax__.asyncResponses.sale;this.__pinpax__.asyncResponses.sale=null,this.__pinpax__.waiting.sale=!1,clearInterval(r),n(o.approved)}},100)}))}async getVoucher({folio:i=null}={}){if(this.isDisconnected)throw new Error("Device is disconnected");if(this.__pinpax__.waiting.voucher)throw new Error("Already waiting for voucher");if(!i)throw new Error("Folio is required");this.__pinpax__.waiting.voucher=!0,this.__pinpax__.asyncResponses.voucher=null;const e=s.s.getVoucher({folio:i});return this.queue.length>0&&await this.#e(),await this.appendToQueue(e,"get-voucher"),new Promise((t,a)=>{const n=setTimeout(()=>{this.__pinpax__.waiting.voucher=!1,a("Timeout")},1e4),r=setInterval(()=>{if(this.__pinpax__.asyncResponses.voucher){const o=this.__pinpax__.asyncResponses.voucher;this.__pinpax__.asyncResponses.voucher=null,this.__pinpax__.waiting.voucher=!1,clearInterval(r),clearTimeout(n),t(o.voucher)}},100)})}async info(){await this.appendToQueue(s.s.info(),"info")}async keepAlive(){await this.appendToQueue(s.s.keepAlive(),"keep-alive")}async restartApp(){await this.appendToQueue(s.s.restartApp(),"reset-app")}async getConfig(){return await this.appendToQueue(s.s.getConfig(),"get-config")}async hideButtons(){return await this.appendToQueue(s.s.hideButtons(),"hide-buttons"),await this.#s()}async showButtons(){return await this.appendToQueue(s.s.showButtons(),"show-buttons"),await this.#a()}async demo(){return console.warn("RUNNING DEMO APP, BE CAREFUL"),await this.appendToQueue(s.s.demo(),"demo")}async refund({amount:i=0,folio:e=null,auth:t=null}={}){return await this.appendToQueue(s.s.refund({amount:i,folio:e,auth:t}),"refund")}async readProductionQR(){return await this.#i({type:"production"})}async readQualityAssuranceQR(){return this.#i({type:"QA"})}async exit(){return await this.appendToQueue(s.s.exit(),"exit-app")}async init(){await this.appendToQueue(s.s.init(),"init-app")}async login(){if(!this.apiKey||!this.businessId||!this.encryptionKey||!this.server)throw new Error("Invalid data to login check apiKey, businessId, encryptionKey, server");const i=JSON.stringify({action:"LOGIN_MIT",server:this.__pinpax__.server,business_id:this.__pinpax__.businessId,encryption_key:this.__pinpax__.encryptionKey,api_key:this.__pinpax__.apiKey}),e=this.parseStringToBytes(i,`\r
|
|
4
4
|
`);await this.appendToQueue(e,"login")}}exports.PinPax=p;
|
package/dist/pinpax.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { K as p, D as
|
|
2
|
-
import { s
|
|
1
|
+
import { K as p, D as c } from "./kernel-BnWXOCde.js";
|
|
2
|
+
import { s } from "./relay-DP8PLsDP.js";
|
|
3
3
|
class l extends p {
|
|
4
4
|
__pinpax__ = {
|
|
5
5
|
server: "DEV",
|
|
@@ -12,11 +12,13 @@ class l extends p {
|
|
|
12
12
|
},
|
|
13
13
|
waiting: {
|
|
14
14
|
voucher: !1,
|
|
15
|
-
sale: !1
|
|
15
|
+
sale: !1,
|
|
16
|
+
sale_init: "idle",
|
|
17
|
+
sale_login: "idle"
|
|
16
18
|
}
|
|
17
19
|
};
|
|
18
20
|
constructor({
|
|
19
|
-
filters:
|
|
21
|
+
filters: i = null,
|
|
20
22
|
config_port: e = {
|
|
21
23
|
baudRate: 115200,
|
|
22
24
|
dataBits: 8,
|
|
@@ -25,8 +27,8 @@ class l extends p {
|
|
|
25
27
|
bufferSize: 32768,
|
|
26
28
|
flowControl: "none"
|
|
27
29
|
},
|
|
28
|
-
no_device:
|
|
29
|
-
device_listen_on_channel:
|
|
30
|
+
no_device: t = 1,
|
|
31
|
+
device_listen_on_channel: a = 1,
|
|
30
32
|
socket: n = !1
|
|
31
33
|
} = {
|
|
32
34
|
filters: null,
|
|
@@ -42,13 +44,13 @@ class l extends p {
|
|
|
42
44
|
device_listen_on_channel: 1,
|
|
43
45
|
socket: !1
|
|
44
46
|
}) {
|
|
45
|
-
if (super({ filters:
|
|
46
|
-
throw new Error(`Device ${this.typeDevice} ${
|
|
47
|
+
if (super({ filters: i, config_port: e, no_device: t, device_listen_on_channel: a, socket: n }), this.__internal__.device.type = "pinpax", c.getCustom(this.typeDevice, t))
|
|
48
|
+
throw new Error(`Device ${this.typeDevice} ${t} already exists`);
|
|
47
49
|
this.__internal__.time.response_connection = 4e3, this.__internal__.time.response_general = 3e3, this.__internal__.serial.delay_first_connection = 1e3, this.__internal__.serial.response.replacer = "", this.__internal__.serial.response.limiter = `\r
|
|
48
|
-
`, this.#t(),
|
|
50
|
+
`, this.#t(), c.add(this), this.getResponseAsString();
|
|
49
51
|
}
|
|
50
52
|
#t() {
|
|
51
|
-
const
|
|
53
|
+
const i = [
|
|
52
54
|
"buttons-status",
|
|
53
55
|
"init-app",
|
|
54
56
|
"connectMessage",
|
|
@@ -62,44 +64,47 @@ class l extends p {
|
|
|
62
64
|
"refund",
|
|
63
65
|
"login"
|
|
64
66
|
];
|
|
65
|
-
for (const e of
|
|
67
|
+
for (const e of i)
|
|
66
68
|
this.serialRegisterAvailableListener(e);
|
|
67
69
|
}
|
|
68
|
-
set businessId(
|
|
69
|
-
this.__pinpax__.businessId =
|
|
70
|
+
set businessId(i) {
|
|
71
|
+
this.__pinpax__.businessId = i;
|
|
70
72
|
}
|
|
71
73
|
get businessId() {
|
|
72
74
|
return this.__pinpax__.businessId;
|
|
73
75
|
}
|
|
74
|
-
set encryptionKey(
|
|
75
|
-
this.__pinpax__.encryptionKey =
|
|
76
|
+
set encryptionKey(i) {
|
|
77
|
+
this.__pinpax__.encryptionKey = i;
|
|
76
78
|
}
|
|
77
79
|
get encryptionKey() {
|
|
78
80
|
return this.__pinpax__.encryptionKey;
|
|
79
81
|
}
|
|
80
|
-
set apiKey(
|
|
81
|
-
this.__pinpax__.apiKey =
|
|
82
|
+
set apiKey(i) {
|
|
83
|
+
this.__pinpax__.apiKey = i;
|
|
82
84
|
}
|
|
83
85
|
get apiKey() {
|
|
84
86
|
return this.__pinpax__.apiKey;
|
|
85
87
|
}
|
|
86
|
-
set server(
|
|
87
|
-
this.__pinpax__.server =
|
|
88
|
+
set server(i) {
|
|
89
|
+
this.__pinpax__.server = i;
|
|
88
90
|
}
|
|
89
91
|
get server() {
|
|
90
92
|
return this.__pinpax__.server;
|
|
91
93
|
}
|
|
92
|
-
serialMessage(
|
|
94
|
+
serialMessage(i) {
|
|
93
95
|
let e = null;
|
|
94
96
|
try {
|
|
95
|
-
e = JSON.parse(
|
|
96
|
-
} catch (
|
|
97
|
-
console.error("Error parsing response",
|
|
97
|
+
e = JSON.parse(i), e.request || (e.request = this.lastAction), e.name || (e.name = this.lastAction);
|
|
98
|
+
} catch (t) {
|
|
99
|
+
console.error("Error parsing response", t, i), this.dispatch("serial:message", i);
|
|
98
100
|
return;
|
|
99
101
|
}
|
|
100
102
|
switch (e.response) {
|
|
103
|
+
case "INIT":
|
|
104
|
+
this.dispatch("init", { name: "INIT", request: this.lastAction, status: "ok" }), this.__pinpax__.waiting.sale_init === "waiting" && (this.__pinpax__.waiting.sale_init = "received");
|
|
105
|
+
break;
|
|
101
106
|
case "INITAPP":
|
|
102
|
-
this.dispatch("init-app", { name: "INITAPP", request: this.lastAction, status: "started" }), this.#n().then(() => {
|
|
107
|
+
this.dispatch("init-app", { name: "INITAPP", request: this.lastAction, status: "started" }), this.__pinpax__.waiting.sale_init === "waiting" ? this.__pinpax__.waiting.sale_init = "received" : this.#n().then(() => {
|
|
103
108
|
});
|
|
104
109
|
break;
|
|
105
110
|
case "CONNECT":
|
|
@@ -107,7 +112,7 @@ class l extends p {
|
|
|
107
112
|
});
|
|
108
113
|
break;
|
|
109
114
|
case "LOGIN":
|
|
110
|
-
e.name || (e.name = "LOGIN"), this.dispatch("login", e);
|
|
115
|
+
e.name || (e.name = "LOGIN"), this.__pinpax__.waiting.sale_login === "waiting" && (this.__pinpax__.waiting.sale_login = "received"), this.dispatch("login", e);
|
|
111
116
|
break;
|
|
112
117
|
case "LASTVOUCHER":
|
|
113
118
|
e.name || (e.name = "LASTVOUCHER"), this.dispatch("voucher", e), this.__pinpax__.waiting.voucher && (this.__pinpax__.asyncResponses.voucher = e, this.__pinpax__.waiting.voucher = !1);
|
|
@@ -222,40 +227,40 @@ class l extends p {
|
|
|
222
227
|
this.dispatch("serial:message", e);
|
|
223
228
|
}
|
|
224
229
|
serialSetConnectionConstant() {
|
|
225
|
-
return
|
|
230
|
+
return s.connection();
|
|
226
231
|
}
|
|
227
232
|
softReload() {
|
|
228
233
|
super.softReload(), this.__pinpax__.waiting.sale = !1, this.__pinpax__.waiting.voucher = !1, this.__pinpax__.asyncResponses.sale = null, this.__pinpax__.asyncResponses.voucher = null;
|
|
229
234
|
}
|
|
230
|
-
async sendCustomCode(
|
|
231
|
-
if (typeof
|
|
232
|
-
if (
|
|
233
|
-
if (Object.keys(
|
|
234
|
-
if (
|
|
235
|
-
const e = JSON.stringify(
|
|
235
|
+
async sendCustomCode(i = {}) {
|
|
236
|
+
if (typeof i != "object") throw new Error("Invalid object");
|
|
237
|
+
if (i.constructor !== Object) throw new Error("Invalid object");
|
|
238
|
+
if (Object.keys(i).length === 0) throw new Error("Empty object");
|
|
239
|
+
if (i.action === void 0 || i.action === null) throw new Error("Invalid object add action");
|
|
240
|
+
const e = JSON.stringify(i), t = this.parseStringToBytes(e, `\r
|
|
236
241
|
`);
|
|
237
|
-
await this.appendToQueue(this.stringArrayToUint8Array(
|
|
242
|
+
await this.appendToQueue(this.stringArrayToUint8Array(t), "custom");
|
|
238
243
|
}
|
|
239
244
|
async connectMessage() {
|
|
240
|
-
await this.appendToQueue(
|
|
245
|
+
await this.appendToQueue(s.connect(), "connect:message");
|
|
241
246
|
}
|
|
242
247
|
async #e() {
|
|
243
248
|
if (this.isDisconnected) throw new Error("Device is disconnected");
|
|
244
|
-
return this.queue.length === 0 ? !0 : new Promise((
|
|
249
|
+
return this.queue.length === 0 ? !0 : new Promise((i) => {
|
|
245
250
|
const e = setInterval(() => {
|
|
246
|
-
this.queue.length === 0 && (clearInterval(e),
|
|
251
|
+
this.queue.length === 0 && (clearInterval(e), i(!0));
|
|
247
252
|
}, 500);
|
|
248
253
|
});
|
|
249
254
|
}
|
|
250
|
-
async #
|
|
251
|
-
const e =
|
|
255
|
+
async #i({ type: i = "production" } = {}) {
|
|
256
|
+
const e = s.readQR({ type: i });
|
|
252
257
|
return await this.appendToQueue(e, "read-qr");
|
|
253
258
|
}
|
|
254
|
-
async #
|
|
255
|
-
await this.appendToQueue(
|
|
259
|
+
async #s() {
|
|
260
|
+
await this.appendToQueue(s.forceHide(), "force-hide");
|
|
256
261
|
}
|
|
257
|
-
async #
|
|
258
|
-
await this.appendToQueue(
|
|
262
|
+
async #a() {
|
|
263
|
+
await this.appendToQueue(s.forceShow(), "force-show");
|
|
259
264
|
}
|
|
260
265
|
async #n() {
|
|
261
266
|
await this.connectMessage();
|
|
@@ -263,8 +268,8 @@ class l extends p {
|
|
|
263
268
|
async #r() {
|
|
264
269
|
await this.hideButtons();
|
|
265
270
|
}
|
|
266
|
-
#o(
|
|
267
|
-
this.dispatch("payment",
|
|
271
|
+
#o(i) {
|
|
272
|
+
this.dispatch("payment", i), this.__pinpax__.waiting.sale && (this.__pinpax__.asyncResponses.sale = i);
|
|
268
273
|
}
|
|
269
274
|
cancelSaleRequestInProcess() {
|
|
270
275
|
this.__pinpax__.waiting.sale && (this.__pinpax__.asyncResponses.sale = {
|
|
@@ -273,89 +278,126 @@ class l extends p {
|
|
|
273
278
|
response: {}
|
|
274
279
|
});
|
|
275
280
|
}
|
|
276
|
-
async
|
|
281
|
+
async #c() {
|
|
282
|
+
return new Promise((i, e) => {
|
|
283
|
+
const t = setTimeout(() => {
|
|
284
|
+
this.__pinpax__.waiting.sale_login === "waiting" && (this.__pinpax__.waiting.sale_login = "timeout", e(new Error("Login timeout")));
|
|
285
|
+
}, 1e4), a = setInterval(() => {
|
|
286
|
+
this.__pinpax__.waiting.sale_login === "received" && (clearTimeout(t), clearInterval(a), i(!0));
|
|
287
|
+
}, 100);
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
async #p() {
|
|
291
|
+
return new Promise((i, e) => {
|
|
292
|
+
const t = setTimeout(() => {
|
|
293
|
+
this.__pinpax__.waiting.sale_init === "waiting" && (this.__pinpax__.waiting.sale_init = "timeout", e(new Error("Init timeout")));
|
|
294
|
+
}, 1e4), a = setInterval(() => {
|
|
295
|
+
this.__pinpax__.waiting.sale_init === "received" && (clearTimeout(t), clearInterval(a), i(!0));
|
|
296
|
+
}, 100);
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
async makeSale({
|
|
300
|
+
amount: i = 0,
|
|
301
|
+
reference: e = null
|
|
302
|
+
} = {
|
|
303
|
+
amount: 0,
|
|
304
|
+
reference: null
|
|
305
|
+
}) {
|
|
277
306
|
if (this.isDisconnected) throw new Error("Device is disconnected");
|
|
278
307
|
if (this.__pinpax__.waiting.sale) throw new Error("Already waiting for sale response");
|
|
279
|
-
const
|
|
280
|
-
|
|
281
|
-
|
|
308
|
+
const t = s.makeSale({ amount: i, reference: e });
|
|
309
|
+
this.__pinpax__.waiting.sale = !0, this.__pinpax__.asyncResponses.sale = null, this.queue.length > 0 && await this.#e();
|
|
310
|
+
let a = !1;
|
|
311
|
+
try {
|
|
312
|
+
this.__pinpax__.waiting.sale_login = "waiting", await this.login(), await this.#c(), this.__pinpax__.waiting.sale_login = "idle", this.__pinpax__.waiting.sale_init = "waiting", await this.init(), await this.#p(), this.__pinpax__.waiting.sale_init = "idle";
|
|
313
|
+
} catch (n) {
|
|
314
|
+
a = !0, this.__pinpax__.waiting.sale_login = "idle", this.__pinpax__.waiting.sale_init = "idle", this.__pinpax__.waiting.sale = !1, this.dispatch("error", {
|
|
315
|
+
name: "ERROR",
|
|
316
|
+
request: this.lastAction,
|
|
317
|
+
status: "error",
|
|
318
|
+
response: "Error during login/init before sale",
|
|
319
|
+
error: n
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
return a ? !1 : (await this.appendToQueue(t, "make-sale"), new Promise((n) => {
|
|
323
|
+
const r = setInterval(() => {
|
|
282
324
|
if (this.__pinpax__.asyncResponses.sale) {
|
|
283
|
-
const
|
|
284
|
-
this.__pinpax__.asyncResponses.sale = null, this.__pinpax__.waiting.sale = !1, clearInterval(
|
|
325
|
+
const o = this.__pinpax__.asyncResponses.sale;
|
|
326
|
+
this.__pinpax__.asyncResponses.sale = null, this.__pinpax__.waiting.sale = !1, clearInterval(r), n(o.approved);
|
|
285
327
|
}
|
|
286
328
|
}, 100);
|
|
287
|
-
});
|
|
329
|
+
}));
|
|
288
330
|
}
|
|
289
|
-
async getVoucher({ folio:
|
|
331
|
+
async getVoucher({ folio: i = null } = {}) {
|
|
290
332
|
if (this.isDisconnected) throw new Error("Device is disconnected");
|
|
291
333
|
if (this.__pinpax__.waiting.voucher) throw new Error("Already waiting for voucher");
|
|
292
|
-
if (!
|
|
334
|
+
if (!i) throw new Error("Folio is required");
|
|
293
335
|
this.__pinpax__.waiting.voucher = !0, this.__pinpax__.asyncResponses.voucher = null;
|
|
294
|
-
const e =
|
|
295
|
-
return this.queue.length > 0 && await this.#e(), await this.appendToQueue(e, "get-voucher"), new Promise((
|
|
336
|
+
const e = s.getVoucher({ folio: i });
|
|
337
|
+
return this.queue.length > 0 && await this.#e(), await this.appendToQueue(e, "get-voucher"), new Promise((t, a) => {
|
|
296
338
|
const n = setTimeout(() => {
|
|
297
|
-
this.__pinpax__.waiting.voucher = !1,
|
|
339
|
+
this.__pinpax__.waiting.voucher = !1, a("Timeout");
|
|
298
340
|
}, 1e4), r = setInterval(() => {
|
|
299
341
|
if (this.__pinpax__.asyncResponses.voucher) {
|
|
300
|
-
const
|
|
301
|
-
this.__pinpax__.asyncResponses.voucher = null, this.__pinpax__.waiting.voucher = !1, clearInterval(r), clearTimeout(n),
|
|
342
|
+
const o = this.__pinpax__.asyncResponses.voucher;
|
|
343
|
+
this.__pinpax__.asyncResponses.voucher = null, this.__pinpax__.waiting.voucher = !1, clearInterval(r), clearTimeout(n), t(o.voucher);
|
|
302
344
|
}
|
|
303
345
|
}, 100);
|
|
304
346
|
});
|
|
305
347
|
}
|
|
306
348
|
async info() {
|
|
307
|
-
await this.appendToQueue(
|
|
349
|
+
await this.appendToQueue(s.info(), "info");
|
|
308
350
|
}
|
|
309
351
|
async keepAlive() {
|
|
310
|
-
await this.appendToQueue(
|
|
352
|
+
await this.appendToQueue(s.keepAlive(), "keep-alive");
|
|
311
353
|
}
|
|
312
354
|
async restartApp() {
|
|
313
|
-
await this.appendToQueue(
|
|
355
|
+
await this.appendToQueue(s.restartApp(), "reset-app");
|
|
314
356
|
}
|
|
315
357
|
async getConfig() {
|
|
316
|
-
return await this.appendToQueue(
|
|
358
|
+
return await this.appendToQueue(s.getConfig(), "get-config");
|
|
317
359
|
}
|
|
318
360
|
async hideButtons() {
|
|
319
|
-
return await this.appendToQueue(
|
|
361
|
+
return await this.appendToQueue(s.hideButtons(), "hide-buttons"), await this.#s();
|
|
320
362
|
}
|
|
321
363
|
async showButtons() {
|
|
322
|
-
return await this.appendToQueue(
|
|
364
|
+
return await this.appendToQueue(s.showButtons(), "show-buttons"), await this.#a();
|
|
323
365
|
}
|
|
324
366
|
async demo() {
|
|
325
|
-
return console.warn("RUNNING DEMO APP, BE CAREFUL"), await this.appendToQueue(
|
|
367
|
+
return console.warn("RUNNING DEMO APP, BE CAREFUL"), await this.appendToQueue(s.demo(), "demo");
|
|
326
368
|
}
|
|
327
|
-
async refund({ amount:
|
|
369
|
+
async refund({ amount: i = 0, folio: e = null, auth: t = null } = {}) {
|
|
328
370
|
return await this.appendToQueue(
|
|
329
|
-
|
|
330
|
-
amount:
|
|
371
|
+
s.refund({
|
|
372
|
+
amount: i,
|
|
331
373
|
folio: e,
|
|
332
|
-
auth:
|
|
374
|
+
auth: t
|
|
333
375
|
}),
|
|
334
376
|
"refund"
|
|
335
377
|
);
|
|
336
378
|
}
|
|
337
379
|
async readProductionQR() {
|
|
338
|
-
return await this.#
|
|
380
|
+
return await this.#i({ type: "production" });
|
|
339
381
|
}
|
|
340
382
|
async readQualityAssuranceQR() {
|
|
341
|
-
return this.#
|
|
383
|
+
return this.#i({ type: "QA" });
|
|
342
384
|
}
|
|
343
385
|
async exit() {
|
|
344
|
-
return await this.appendToQueue(
|
|
386
|
+
return await this.appendToQueue(s.exit(), "exit-app");
|
|
345
387
|
}
|
|
346
388
|
async init() {
|
|
347
|
-
await this.appendToQueue(
|
|
389
|
+
await this.appendToQueue(s.init(), "init-app");
|
|
348
390
|
}
|
|
349
391
|
async login() {
|
|
350
392
|
if (!this.apiKey || !this.businessId || !this.encryptionKey || !this.server)
|
|
351
393
|
throw new Error("Invalid data to login check apiKey, businessId, encryptionKey, server");
|
|
352
|
-
const
|
|
394
|
+
const i = JSON.stringify({
|
|
353
395
|
action: "LOGIN_MIT",
|
|
354
396
|
server: this.__pinpax__.server,
|
|
355
397
|
business_id: this.__pinpax__.businessId,
|
|
356
398
|
encryption_key: this.__pinpax__.encryptionKey,
|
|
357
399
|
api_key: this.__pinpax__.apiKey
|
|
358
|
-
}), e = this.parseStringToBytes(
|
|
400
|
+
}), e = this.parseStringToBytes(i, `\r
|
|
359
401
|
`);
|
|
360
402
|
await this.appendToQueue(e, "login");
|
|
361
403
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ConstructorParams, Kernel } from './kernel';
|
|
2
2
|
interface PinPaxInternal {
|
|
3
|
-
server: 'DEV' | 'PROD' | '
|
|
3
|
+
server: 'DEV' | 'PROD' | 'QA';
|
|
4
4
|
businessId: string | null;
|
|
5
5
|
encryptionKey: string | null;
|
|
6
6
|
apiKey: string | null;
|
|
@@ -11,6 +11,8 @@ interface PinPaxInternal {
|
|
|
11
11
|
waiting: {
|
|
12
12
|
voucher: boolean;
|
|
13
13
|
sale: boolean;
|
|
14
|
+
sale_init: 'idle' | 'waiting' | 'received' | 'timeout';
|
|
15
|
+
sale_login: 'idle' | 'waiting' | 'received' | 'timeout';
|
|
14
16
|
};
|
|
15
17
|
}
|
|
16
18
|
export declare class PinPax extends Kernel {
|
|
@@ -23,17 +25,17 @@ export declare class PinPax extends Kernel {
|
|
|
23
25
|
get encryptionKey(): string | null;
|
|
24
26
|
set apiKey(apiKey: string | null);
|
|
25
27
|
get apiKey(): string | null;
|
|
26
|
-
set server(server: "DEV" | "PROD" | "
|
|
27
|
-
get server(): "DEV" | "PROD" | "
|
|
28
|
+
set server(server: "DEV" | "PROD" | "QA");
|
|
29
|
+
get server(): "DEV" | "PROD" | "QA";
|
|
28
30
|
serialMessage(codex: string[] | Uint8Array<ArrayBufferLike> | string | ArrayBuffer): void;
|
|
29
31
|
serialSetConnectionConstant(): Uint8Array<ArrayBufferLike>;
|
|
30
32
|
softReload(): void;
|
|
31
33
|
sendCustomCode(code?: any): Promise<void>;
|
|
32
34
|
connectMessage(): Promise<void>;
|
|
33
35
|
cancelSaleRequestInProcess(): void;
|
|
34
|
-
makeSale({ amount, reference }?: {
|
|
35
|
-
amount
|
|
36
|
-
reference?:
|
|
36
|
+
makeSale({ amount, reference, }?: {
|
|
37
|
+
amount: number;
|
|
38
|
+
reference?: string | null;
|
|
37
39
|
}): Promise<unknown>;
|
|
38
40
|
getVoucher({ folio }?: {
|
|
39
41
|
folio?: null | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pinpax.d.ts","sourceRoot":"","sources":["../../../lib/serial/pinpax.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAIrD,UAAU,cAAc;IACtB,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,
|
|
1
|
+
{"version":3,"file":"pinpax.d.ts","sourceRoot":"","sources":["../../../lib/serial/pinpax.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAIrD,UAAU,cAAc;IACtB,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,IAAI,CAAC;IAC9B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,cAAc,EAAE;QACd,OAAO,EAAE,GAAG,GAAG,IAAI,CAAC;QACpB,IAAI,EAAE,GAAG,GAAG,IAAI,CAAC;KAClB,CAAC;IACF,OAAO,EAAE;QACP,OAAO,EAAE,OAAO,CAAC;QACjB,IAAI,EAAE,OAAO,CAAC;QACd,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,UAAU,GAAG,SAAS,CAAC;QACvD,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,UAAU,GAAG,SAAS,CAAC;KACzD,CAAC;CACH;AAED,qBAAa,MAAO,SAAQ,MAAM;;IAChC,UAAU,EAAE,cAAc,CAgBxB;gBAEA,EACE,OAAc,EACd,WAOC,EACD,SAAa,EACb,wBAA4B,EAC5B,MAAc,GACf,GAAE,iBAaF;IAoCH,IAAI,UAAU,CAAC,UAAU,eAAA,EAExB;IACD,IAAI,UAAU,kBAEb;IAED,IAAI,aAAa,CAAC,aAAa,eAAA,EAE9B;IACD,IAAI,aAAa,kBAEhB;IAED,IAAI,MAAM,CAAC,MAAM,eAAA,EAEhB;IACD,IAAI,MAAM,kBAET;IAED,IAAI,MAAM,CAAC,MAAM,uBAAA,EAEhB;IACD,IAAI,MAAM,0BAET;IAEQ,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,eAAe,CAAC,GAAG,MAAM,GAAG,WAAW;IA+LlF,2BAA2B;IAIpC,UAAU;IAQK,cAAc,CAAC,IAAI,GAAE,GAAQ;IAWtC,cAAc;IA8CpB,0BAA0B;IAgDpB,QAAQ,CACZ,EACE,MAAU,EACV,SAAgB,GACjB,GAAE;QACD,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;KAI3B;IAsDG,UAAU,CAAC,EAAE,KAAY,EAAE;;KAAK;IAkChC,IAAI;IAIJ,SAAS;IAIT,UAAU;IAIV,SAAS;IAIT,WAAW;IAKX,WAAW;IAKX,IAAI;IAKJ,MAAM,CAAC,EAAE,MAAU,EAAE,KAAY,EAAE,IAAW,EAAE;;;;KAAK;IAWrD,gBAAgB;IAIhB,sBAAsB;IAItB,IAAI;IAIJ,IAAI;IAIJ,KAAK;CAcZ"}
|