cordova-plugin-netcontroll-integration 1.0.7 → 1.0.10

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/README.md CHANGED
@@ -1,9 +1,5 @@
1
- Version 0.0.2 - Adição de Keywords, ajustes na configuração do plugin (plugin.xml e package.json) e adição de conteúdo ao README.
2
- Version 0.0.3 - Versão da bibloteca E1 atualizada para 1.0.16 (corte extra no imprimeXMLNFCE removido), atualização de imports e adição de comentários.
1
+ Versao 1.0.9
3
2
 
4
- É necessário instalar o plugin que permite a compilação de projetos/plugins que referenciem tanto as librarys do Android Support e AndroidX, que é o caso da versão mais atual da lib "E1":
5
- #cordova-plugin-androidx-adapter
6
-
7
- clobbers:
8
- cordova.plugins.elgin.minipdv
3
+ Funções internas de integração XMenu / NetControll
9
4
 
5
+ - Finalização completa de integração Elgin Terminal M10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cordova-plugin-netcontroll-integration",
3
- "version": "1.0.7",
3
+ "version": "1.0.10",
4
4
  "description": "Plugin cordova de integracao para uso interno (NetControll/ XMenu)",
5
5
  "cordova": {
6
6
  "id": "cordova-plugin-netcontroll-integration",
package/plugin.xml CHANGED
@@ -1,5 +1,5 @@
1
1
  <?xml version='1.0' encoding='utf-8'?>
2
- <plugin id="cordova-plugin-netcontroll-integration" version="1.0.6"
2
+ <plugin id="cordova-plugin-netcontroll-integration" version="1.0.10"
3
3
  xmlns="http://apache.org/cordova/ns/plugins/1.0"
4
4
  xmlns:android="http://schemas.android.com/apk/res/android">
5
5
 
@@ -9,6 +9,8 @@ import org.json.JSONArray;
9
9
  import org.json.JSONException;
10
10
  import org.json.JSONObject;
11
11
 
12
+ // import androidx.annotation.NonNull;
13
+ import androidx.annotation.NonNull;
12
14
  import android.app.Activity;
13
15
  import android.graphics.Bitmap;
14
16
  import android.content.Context;
@@ -27,35 +29,58 @@ import javax.security.auth.callback.Callback;
27
29
 
28
30
  import java.util.List;
29
31
 
30
- //Cielo Package
31
- import cielo.orders.domain.Credentials;
32
+ //Json Serialize
33
+ import com.google.gson.Gson;
34
+ import com.google.gson.GsonBuilder;
35
+
32
36
 
37
+ //Cielo Package Sdk
38
+
39
+ import cielo.orders.domain.CancellationRequest;
40
+ import cielo.orders.domain.Credentials;
33
41
  import cielo.orders.domain.Item;
34
- import cielo.orders.domain.CheckoutRequest;
35
42
  import cielo.orders.domain.Order;
36
43
  import cielo.orders.domain.product.PrimaryProduct;
37
44
  import cielo.orders.domain.product.SecondaryProduct;
45
+ import cielo.orders.domain.CheckoutRequest;
38
46
  import cielo.orders.domain.ResultOrders;
47
+ import cielo.orders.domain.PrinterAttributes;
39
48
 
40
49
  import cielo.sdk.order.OrderManager;
50
+ import cielo.sdk.order.cancellation.CancellationListener;
41
51
  import cielo.sdk.order.ServiceBindListener;
52
+ import cielo.sdk.order.payment.Payment;
42
53
  import cielo.sdk.order.payment.PaymentCode;
43
54
  import cielo.sdk.order.payment.PaymentListener;
44
55
  import cielo.sdk.order.payment.PaymentError;
45
-
46
-
47
-
56
+ import cielo.sdk.order.PrinterListener;
57
+ import cielo.sdk.printer.PrinterManager;
48
58
 
49
59
 
50
60
  /**
51
61
  * This class echoes a string called from JavaScript.
52
62
  */
53
63
  public class CieloLioLocal {
54
- //Cielo
64
+
65
+ //Cielo Package Sdk
55
66
  public OrderManager orderManager;
67
+
68
+
69
+
70
+ //Cielo Variables
71
+ Credentials _credentials ;
56
72
  public boolean orderManagerServiceBinded = false;
73
+ public Order order;
74
+ public Payment payment;
57
75
 
58
76
 
77
+ //Cielo Printer
78
+ private PrinterManager printerManager;
79
+ private PrinterListener printerListener;
80
+ private HashMap<String, Integer> alignCenter = new HashMap<>();
81
+ private HashMap<String, Integer> alignLeft = new HashMap<>();
82
+ private HashMap<String, Integer> alignRight = new HashMap<>();
83
+
59
84
  //Cordova/Java Params
60
85
  private Activity mActivity;
61
86
  private Context mContext;
@@ -74,123 +99,408 @@ public class CieloLioLocal {
74
99
  mContext = cordova.getActivity().getApplicationContext();
75
100
  }
76
101
 
77
- public String Teste() {
78
- return "Result - CieloLioLocalClass: ok";
102
+ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
103
+
104
+ if (action.equals("ConfigureSdk")) {
105
+ JSONObject params = args.getJSONObject(0);
106
+ try {
107
+ this.configSDK(params.getString("clientId"),params.getString("accessToken"), callbackContext);
108
+ return true;
109
+ } catch (Exception error1) {
110
+ callbackContext.error("Result - Cielo - LioLocal - ConfigureSdk: " + "Error Detail: " + error1);
111
+ }
112
+ return false;
113
+ }
114
+ else if (action.equals("CreateDraftOrder")) {
115
+ JSONObject params = args.getJSONObject(0);
116
+ try {
117
+ boolean result = this.createDraftOrder(params.getString("orderReference"), callbackContext);
118
+ return result;
119
+ } catch (Exception error1) {
120
+ callbackContext.error("Result - Cielo - LioLocal CreateDraftOrder: " + "Error Detail: " + error1);
121
+ }
122
+ return false;
123
+ }
124
+ else if (action.equals("AddOrderItem")) {
125
+ JSONObject params = args.getJSONObject(0);
126
+ try {
127
+ boolean result = this.addOrderItem(
128
+ params.getString("sku"),
129
+ params.getString("name"),
130
+ params.getInt("unitPrice"),
131
+ params.getInt("quantity"),
132
+ params.getString("unityOfMeasure"),
133
+ callbackContext
134
+ );
135
+ return result;
136
+ } catch (Exception error1) {
137
+ callbackContext.error("Result - Cielo - LioLocal AddOrderItem: " + "Error Detail: " + error1);
138
+ }
139
+ return false;
140
+ }
141
+ else if (action.equals("MakePayment")) {
142
+ JSONObject params = args.getJSONObject(0);
143
+ try {
144
+ boolean result = this.makePayment(
145
+ params.getString("orderReference"),
146
+ params.getString("orderId"),
147
+ params.getInt("amount"),
148
+ params.getString("ec"),
149
+ params.getInt("installments"),
150
+ params.getString("email"),
151
+ params.getString("paymentCode"),
152
+ callbackContext
153
+ );
154
+ return result;
155
+ } catch (Exception error1) {
156
+ callbackContext.error("Result - Cielo - LioLocal MakePayment: " + "Error Detail: " + error1);
157
+ }
158
+ return false;
159
+ }
160
+ else if (action.equals("ListOrders")) {
161
+ JSONObject params = args.getJSONObject(0);
162
+ try {
163
+ boolean result = this.listOrders(params.getInt("pageSize"), params.getInt("page"), callbackContext);
164
+ return result;
165
+ } catch (Exception error1) {
166
+ callbackContext.error("Result - Cielo - LioLocal ListOrders: " + "Error Detail: " + error1);
167
+ }
168
+ }
169
+ else if (action.equals("CancelPayment")) {
170
+ JSONObject paramsObj = args.getJSONObject(0);
171
+ try {
172
+ boolean result = this.cancelPayment(paramsObj, callbackContext);
173
+ return result;
174
+ } catch (Exception error1) {
175
+ callbackContext.error("Result - Cielo - LioLocal ListOrders: " + "Error Detail: " + error1);
176
+ }
177
+ }
178
+ else if (action.equals("PrintSimpleText")) {
179
+ JSONObject paramsObj = args.getJSONObject(0);
180
+ try {
181
+ boolean result = this.print_SimpleText(paramsObj, callbackContext);
182
+ return result;
183
+ } catch (Exception error1) {
184
+ callbackContext.error("Result - Cielo - LioLocal PrintSimpleText: " + "Error Detail: " + error1);
185
+ }
186
+ }
187
+
188
+ return false;
189
+ }
190
+
191
+
192
+ // Cielo Functions Helpers
193
+ private cielo.sdk.order.payment.PaymentCode GetPaymentCodeFromName(String paymentCodeName) {
194
+ cielo.sdk.order.payment.PaymentCode paymentCode = null;
195
+ switch (paymentCodeName) {
196
+ case "DEBITO_AVISTA":
197
+ paymentCode = PaymentCode.DEBITO_AVISTA;
198
+ break;
199
+ case "DEBITO_PREDATADO":
200
+ paymentCode = PaymentCode.DEBITO_PREDATADO;
201
+ break;
202
+ case "CREDITO_AVISTA":
203
+ paymentCode = PaymentCode.CREDITO_AVISTA;
204
+ break;
205
+ case "CREDITO_PARCELADO_LOJA":
206
+ paymentCode = PaymentCode.CREDITO_PARCELADO_LOJA;
207
+ break;
208
+ case "CREDITO_PARCELADO_ADM":
209
+ paymentCode = PaymentCode.CREDITO_PARCELADO_ADM;
210
+ break;
211
+ case "CREDITO_PARCELADO_BNCO":
212
+ paymentCode = PaymentCode.CREDITO_PARCELADO_BNCO;
213
+ break;
214
+ case "CARTAO_LOJA_AVISTA":
215
+ paymentCode = PaymentCode.CARTAO_LOJA_AVISTA;
216
+ break;
217
+ case "CARTAO_LOJA_PARCELADO_LOJA":
218
+ paymentCode = PaymentCode.CARTAO_LOJA_PARCELADO_LOJA;
219
+ break;
220
+ case "CARTAO_LOJA_PARCELADO":
221
+ paymentCode = PaymentCode.CARTAO_LOJA_PARCELADO;
222
+ break;
223
+ case "PRE_AUTORIZACAO":
224
+ paymentCode = PaymentCode.PRE_AUTORIZACAO;
225
+ break;
226
+ case "VOUCHER_ALIMENTACAO":
227
+ paymentCode = PaymentCode.VOUCHER_ALIMENTACAO;
228
+ break;
229
+ case "VOUCHER_REFEICAO":
230
+ paymentCode = PaymentCode.VOUCHER_REFEICAO;
231
+ break;
232
+ case "VISAVALE_REFEICAO":
233
+ paymentCode = PaymentCode.VISAVALE_REFEICAO;
234
+ break;
235
+ case "VISAVALE_ALIMENTACAO":
236
+ paymentCode = PaymentCode.VISAVALE_ALIMENTACAO;
237
+ break;
238
+ default:
239
+ break;
240
+ }
241
+ return paymentCode;
79
242
  }
80
243
 
81
- public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
82
244
 
83
- if (action.equals("Teste")) {
84
- int arg1 = args.getInt(0);
85
- if (arg1 == 0) {
86
- Credentials credentials = new Credentials("M2vcq2fr0oWKbKd5bvpDoGZvHXQ8IneDLBJEulDjxNA59MOA2D/ EMOfYfErX7Y537JZgJvlgG0r805v5jYTxCgNiPtxm500bBUSxh", "NMgpwK4N5dcLCWnOr2kYbDIFcQdLPEn5M2ObKUTULEOdhxzFZu");
87
- orderManager = new OrderManager(credentials, mContext);
88
- if (credentials == null) {
89
- callbackContext.success("Result - CieloLioLocalClass: Erro Credencial " + action);
90
- return false;
91
- } else {
92
- callbackContext.success("Result - CieloLioLocalClass: Tem Credencial " + action + " Token: " + credentials.getAccessToken().toString());
93
- return true;
94
-
95
- }
96
-
97
-
98
- // callbackContext.success("Result - CieloLioLocalClass: ok " + action);
99
- // return false;
100
- }
101
- else {
102
- callbackContext.success("Result - CieloLioLocalClass: noOk " + action);
103
- return false;
245
+ // Cielo Functions
246
+ protected void configSDK(String clientId, String accessToken, CallbackContext callbackContext) {
247
+ this._credentials = new Credentials(clientId, accessToken);
248
+ this.orderManager = new OrderManager(this._credentials, this.mContext);
249
+ this.orderManager.bind(this.mContext, new ServiceBindListener() {
250
+
251
+ @Override
252
+ public void onServiceBoundError(Throwable throwable) {
253
+ orderManagerServiceBinded = false;
254
+ callbackContext.error(String.format("configSDK: onServiceBoundError: Erro fazendo bind do serviço de ordem -> %s",
255
+ throwable.getMessage()));
256
+ }
257
+
258
+ @Override
259
+ public void onServiceBound() {
260
+ orderManagerServiceBinded = true;
261
+ callbackContext.success("configSDK: onServiceBound: Success");
262
+ // orderManager.createDraftOrder("REFERENCIA DA ORDEM");
263
+ // Toast.makeText(mContext,String.format("configSDK: onServiceBound"), Toast.LENGTH_LONG).show();
264
+ }
265
+
266
+ @Override
267
+ public void onServiceUnbound() {
268
+ orderManagerServiceBinded = false;
269
+ callbackContext.success("configSDK: onServiceUnbound: Success");
270
+ // Toast.makeText(mContext,String.format("configSDK: onServiceUnbound"), Toast.LENGTH_LONG).show();
271
+ }
272
+ });
273
+ }
274
+
275
+ protected boolean createDraftOrder(String orderReference, CallbackContext callbackContext) {
276
+ if (!orderManagerServiceBinded) {
277
+ callbackContext.error("createDraftOrder: onServiceBoundError: No binded order manager");
278
+ return false;
279
+ }
280
+ order = orderManager.createDraftOrder(orderReference);
281
+ if (order != null) {
282
+ callbackContext.success(this.parseObjToJsonSrtring(order));
283
+ return true;
284
+ }
285
+ return false;
286
+ }
287
+
288
+ protected boolean addOrderItem(String sku,
289
+ String name,
290
+ int unitPrice,
291
+ int quantity,
292
+ String unityOfMeasure,
293
+ CallbackContext callbackContext) {
294
+ if (!orderManagerServiceBinded) {
295
+ callbackContext.error("createDraftOrder: onServiceBoundError: No binded order manager");
296
+ return false;
297
+ }
298
+ order.addItem(sku, name, unitPrice, quantity, unityOfMeasure);
299
+ callbackContext.success(this.parseObjToJsonSrtring(order));
300
+ return true;
301
+ }
302
+
303
+ protected boolean makePayment(String orderReference,
304
+ String orderId,
305
+ long amount,
306
+ String ec,
307
+ int installments,
308
+ String email,
309
+ String paymentCodeStr,
310
+ CallbackContext callbackContext) {
311
+ if (!orderManagerServiceBinded) {
312
+ callbackContext.error("makePayment error: No binded order manager");
313
+ return false;
314
+ }
315
+ if (order == null) {
316
+ callbackContext.error("makePayment error: No order found");
317
+ return false;
318
+ } else {
319
+ if (!orderReference.equals(order.getReference())) {
320
+ callbackContext.error("makePayment error: The order reference is not the same as the current order (Reference: " + orderReference + ") - (Current order Reference: " + order.getReference() + ")");
321
+ return false;
322
+ }
323
+ }
324
+ cielo.sdk.order.payment.PaymentCode paymentCode = GetPaymentCodeFromName(paymentCodeStr);
325
+ if (paymentCode == null) {
326
+ callbackContext.error("makePayment error: Invalid paymentCode (" + paymentCodeStr + ")");
327
+ return false;
328
+ }
329
+ orderManager.placeOrder(order);
330
+ try
331
+ {
332
+ CheckoutRequest.Builder requestBuilder = new CheckoutRequest.Builder()
333
+ .orderId(orderId)
334
+ // .orderId(order.getId())
335
+ .amount(amount)
336
+ .paymentCode(paymentCode)
337
+ .installments(installments);
338
+
339
+ if (!ec.equals(""))
340
+ requestBuilder.ec(ec);
341
+ if (!email.equals(""))
342
+ requestBuilder.email(email);
343
+
344
+ CheckoutRequest request = requestBuilder.build();
345
+ orderManager.checkoutOrder(request, new PaymentListener() {
346
+ @Override
347
+ public void onStart() {
104
348
  }
349
+
350
+ @Override
351
+ public void onPayment(Order paidOrder) {
352
+ order = paidOrder;
353
+ order.markAsPaid();
354
+ orderManager.updateOrder(order);
355
+ callbackContext.success(parseObjToJsonSrtring(order));
356
+ resetState();
357
+ }
358
+
359
+ @Override
360
+ public void onCancel() {
361
+ callbackContext.error("{Result - Cielo - LioLocal MakePayment: checkoutOrder - onCancel");
362
+ resetState();
363
+ }
364
+
365
+ @Override
366
+ public void onError(@NonNull PaymentError paymentError) {
367
+ callbackContext.error("Result - Cielo - LioLocal MakePayment: checkoutOrder - onError");
368
+ resetState();
369
+ }
370
+
371
+ });
372
+ } catch (Exception error1) {
373
+ callbackContext.error("makePayment " + "- Error Detail: " + error1);
374
+ throw error1;
105
375
  }
106
- else if (action.equals("ListarPagamentos")) {
107
- try {
108
- Credentials credentials = new Credentials("M2vcq2fr0oWKbKd5bvpDoGZvHXQ8IneDLBJEulDjxNA59MOA2D/ EMOfYfErX7Y537JZgJvlgG0r805v5jYTxCgNiPtxm500bBUSxh", "NMgpwK4N5dcLCWnOr2kYbDIFcQdLPEn5M2ObKUTULEOdhxzFZu");
109
- orderManager = new OrderManager(credentials, mContext);
376
+ return true;
377
+ }
110
378
 
111
- orderManager.bind(mContext, new ServiceBindListener() {
379
+ protected boolean listOrders(int pageSize, int page, CallbackContext callbackContext) {
380
+ try {
381
+ ResultOrders resultOrders = orderManager.retrieveOrders(pageSize, page);
382
+ if (resultOrders != null) {
383
+ String resultOrdersStr = parseObjToJsonSrtring(resultOrders);
384
+ callbackContext.success(resultOrdersStr);
385
+ } else {
386
+ callbackContext.success("null");
387
+ }
388
+ return true;
389
+ } catch (Exception error1) {
390
+ callbackContext.error("Result - Cielo - LioLocal - listOrders: " + "Error Detail: " + error1);
391
+ }
392
+ return false;
393
+ }
394
+
395
+ protected boolean cancelPayment(JSONObject orderObj, CallbackContext callbackContext) {
396
+ try {
397
+ String jsonStr = orderObj.toString();
398
+ Gson gson = new Gson();
399
+ Order cancelOrder = gson.fromJson(jsonStr, Order.class);
400
+
401
+ List<Payment> paymentList = cancelOrder.getPayments();
402
+ payment = paymentList.get(0);
403
+
404
+
405
+ if (cancelOrder != null && cancelOrder.getPayments().size() > 0) {
406
+ CancellationRequest request = new CancellationRequest.Builder()
407
+ .orderId(cancelOrder.getId())
408
+ .authCode(payment.getAuthCode())
409
+ .cieloCode(payment.getCieloCode())
410
+ .value(payment.getAmount())
411
+ //.ec("0000000000000003")
412
+ .build();
413
+
414
+ orderManager.cancelOrder(request, new CancellationListener() {
112
415
 
113
416
  @Override
114
- public void onServiceBoundError(Throwable throwable) {
115
- orderManagerServiceBinded = false;
116
-
117
- callbackContext.success("Result - ListarPagamentos: " + "Error Detail: " + throwable.getMessage());
118
- // Toast.makeText(getApplicationContext(),
119
- // String.format("Erro fazendo bind do serviço de ordem -> %s",
120
- // throwable.getMessage()), Toast.LENGTH_LONG).show();
121
- // return false;
417
+ public void onSuccess(Order cancelledOrder) {
418
+ cancelledOrder.cancel();
419
+ orderManager.updateOrder(cancelledOrder);
420
+ order = cancelledOrder;
421
+ callbackContext.success(parseObjToJsonSrtring(order));
122
422
  }
123
423
 
124
424
  @Override
125
- public void onServiceBound() {
126
- orderManagerServiceBinded = true;
127
- orderManager.createDraftOrder("REFERENCIA DA ORDEM");
128
- // callbackContext.success("Result - ListarPagamentos: " + "REFERENCIA DA ORDEM => listOrders");
129
-
130
- ResultOrders resultOrders = orderManager.retrieveOrders(200, 0);
131
- final List<Order> orderList = resultOrders.getResults();
132
- String ordersList = "";
133
- for (Order or : orderList) {
134
- if (!or.getItems().isEmpty()) {
135
- ordersList += or.getReference() + " - Price: " + or.getPrice() + "\n";
136
- }
137
- // Log.i("Order: ", or.getNumber() + " - " + or.getPrice());
138
- }
139
- if (ordersList != "") {
140
- // txtEmptyValue.setText(ordersList);
141
- callbackContext.success("Result - ListarPagamentos: " + "REFERENCIA DA ORDEM => listOrders \n" + ordersList);
142
- }
143
- // callbackContext.success("Service Bound");
144
- // listOrders();
145
- // return true;
425
+ public void onCancel() {
426
+ callbackContext.success("cancelPayment - onCancel");
146
427
  }
147
428
 
148
429
  @Override
149
- public void onServiceUnbound() {
150
- orderManagerServiceBinded = false;
430
+ public void onError(PaymentError paymentError) {
431
+ callbackContext.success("cancelPayment - onError");
151
432
  }
152
433
  });
153
- return true;
154
- } catch (Exception error1) {
155
- // alertarMensagem(resutText, error1);
156
- callbackContext.success("Result - ListarPagamentos: " + "Error Detail: " + error1);
434
+ }
435
+ return true;
436
+ } catch (Exception error1) {
437
+ callbackContext.error("Result - Cielo - LioLocal - cancelPayment: " + "Error Detail: " + error1);
438
+ }
439
+ return false;
440
+ }
441
+
442
+ protected boolean print_initialize() {
443
+ setStyles();
444
+
445
+ printerManager = new PrinterManager(this.mContext);
446
+ printerListener = new PrinterListener() {
447
+ @Override
448
+ public void onWithoutPaper() {
449
+ //Log.d("PrintSampleActivity", "printer without paper");
450
+ }
451
+
452
+ @Override
453
+ public void onPrintSuccess() {
454
+ //Log.d("PrintSampleActivity", "print success!");
157
455
  }
158
- // callbackContext.success("Result - ListarPagamentos: Ok " + action);
159
- // return true;
456
+
457
+ @Override
458
+ public void onError(Throwable throwable) {
459
+ //Log.d("PrintSampleActivity",String.format("printer error -> %s", throwable.getMessage()));
460
+ }
461
+ };
462
+ return true;
463
+ }
464
+
465
+ protected boolean print_SimpleText(JSONObject orderObj, CallbackContext callbackContext) {
466
+ try {
467
+ print_initialize();
468
+ PrinterManager printerManager = new PrinterManager(this.mContext);
469
+ String textToPrint = "Texto simples a ser impresso.\n Com múltiplas linhas";
470
+
471
+ printerManager.printText(textToPrint, alignLeft, printerListener);
472
+ callbackContext.success("Result - Cielo - LioLocal - print_SimpleText: setStyles OK");
473
+ return true;
474
+ } catch (Exception error1) {
475
+ callbackContext.error("Result - Cielo - LioLocal - print_SimpleText: " + "Error Detail: " + error1);
160
476
  }
161
477
  return false;
162
478
  }
163
479
 
480
+ private void setStyles() {
481
+ alignLeft.put(PrinterAttributes.KEY_ALIGN, PrinterAttributes.VAL_ALIGN_LEFT);
482
+ alignLeft.put(PrinterAttributes.KEY_TYPEFACE, 0);
483
+ alignLeft.put(PrinterAttributes.KEY_TEXT_SIZE, 30);
164
484
 
485
+ alignCenter.put(PrinterAttributes.KEY_ALIGN, PrinterAttributes.VAL_ALIGN_CENTER);
486
+ alignCenter.put(PrinterAttributes.KEY_TYPEFACE, 1);
487
+ alignCenter.put(PrinterAttributes.KEY_TEXT_SIZE, 20);
165
488
 
489
+ alignRight.put(PrinterAttributes.KEY_ALIGN, PrinterAttributes.VAL_ALIGN_RIGHT);
490
+ alignRight.put(PrinterAttributes.KEY_TYPEFACE, 2);
491
+ alignRight.put(PrinterAttributes.KEY_TEXT_SIZE, 10);
492
+ }
166
493
 
167
- // Cielo Functions
168
- protected void configSDKListarPagamentos() {
169
- Credentials credentials = new Credentials("M2vcq2fr0oWKbKd5bvpDoGZvHXQ8IneDLBJEulDjxNA59MOA2D/ EMOfYfErX7Y537JZgJvlgG0r805v5jYTxCgNiPtxm500bBUSxh", "NMgpwK4N5dcLCWnOr2kYbDIFcQdLPEn5M2ObKUTULEOdhxzFZu");
170
- // orderManager = new OrderManager(credentials, this);
171
- // orderManager.bind(this, new ServiceBindListener() {
172
-
173
- // @Override
174
- // public void onServiceBoundError(Throwable throwable) {
175
- // orderManagerServiceBinded = false;
176
-
177
- // Toast.makeText(getApplicationContext(),
178
- // String.format("Erro fazendo bind do serviço de ordem -> %s",
179
- // throwable.getMessage()), Toast.LENGTH_LONG).show();
180
- // }
181
-
182
- // @Override
183
- // public void onServiceBound() {
184
- // orderManagerServiceBinded = true;
185
- // orderManager.createDraftOrder("REFERENCIA DA ORDEM");
186
- // listOrders();
187
- // }
188
-
189
- // @Override
190
- // public void onServiceUnbound() {
191
- // orderManagerServiceBinded = false;
192
- // }
193
- // });
494
+
495
+ // Cielo Global
496
+ protected String parseObjToJsonSrtring(Object obj) {
497
+ Gson gson = new Gson();
498
+ String result = gson.toJson(obj);
499
+ return result;
500
+ }
501
+
502
+ protected void resetState() {
503
+ order = null;
194
504
  }
195
505
 
196
506
  }
@@ -60,20 +60,7 @@ public class ElginM10Terminal {
60
60
  }
61
61
 
62
62
  public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
63
-
64
- if (action.equals("Teste")) {
65
- int arg1 = args.getInt(0);
66
- if (arg1 == 0) {
67
- callbackContext.success("Result - ElginClass: ok " + action);
68
- return false;
69
- }
70
- else {
71
- callbackContext.success("Result - ElginClass: noOk " + action);
72
- return false;
73
- }
74
- }
75
-
76
- else if(action.equals("AbreConexaoImpressora")){
63
+ if(action.equals("AbreConexaoImpressora")){
77
64
  try{
78
65
  JSONObject params = args.getJSONObject(0);
79
66
 
@@ -88,45 +75,48 @@ public class ElginM10Terminal {
88
75
  }catch (Exception e){
89
76
  callbackContext.error("AbreConexaoImpressora error: " + e.toString());
90
77
  }
78
+ return true;
91
79
  }
92
80
 
93
- // else if(action.equals("FechaConexaoImpressora")){
94
- // try{
95
- // int result = Termica.FechaConexaoImpressora();
96
-
97
- // callbackContext.success(result);
98
- // } catch (Exception e){
99
- // callbackContext.error("FechaConexaoImpressora error: " + e.toString());
100
- // }
101
- // }
81
+ else if(action.equals("FechaConexaoImpressora")){
82
+ try{
83
+ int result = Termica.FechaConexaoImpressora();
84
+ callbackContext.success(result);
85
+ } catch (Exception e){
86
+ callbackContext.error("FechaConexaoImpressora error: " + e.toString());
87
+ }
88
+ return true;
89
+ }
102
90
 
103
- // else if(action.equals("AvancaPapel")){
104
- // try{
105
- // JSONObject params = args.getJSONObject(0);
91
+ else if(action.equals("AvancaPapel")){
92
+ try{
93
+ JSONObject params = args.getJSONObject(0);
106
94
 
107
- // int linhas = params.getInt("linhas");
95
+ int linhas = params.getInt("linhas");
108
96
 
109
- // int result = Termica.AvancaPapel(linhas);
97
+ int result = Termica.AvancaPapel(linhas);
110
98
 
111
- // callbackContext.success(result);
112
- // }catch (Exception e){
113
- // callbackContext.error("AvancaPapel error: " + e.toString());
114
- // }
115
- // }
99
+ callbackContext.success(result);
100
+ }catch (Exception e){
101
+ callbackContext.error("AvancaPapel error: " + e.toString());
102
+ }
103
+ return true;
104
+ }
116
105
 
117
- // else if(action.equals("Corte")){
118
- // try{
119
- // JSONObject params = args.getJSONObject(0);
106
+ else if(action.equals("Corte")){
107
+ try{
108
+ JSONObject params = args.getJSONObject(0);
120
109
 
121
- // int avanco = params.getInt("avanco");
110
+ int avanco = params.getInt("avanco");
122
111
 
123
- // int result = Termica.Corte(avanco);
112
+ int result = Termica.Corte(avanco);
124
113
 
125
- // callbackContext.success(result);
126
- // }catch (Exception e){
127
- // callbackContext.error("Corte error: " + e.toString());
128
- // }
129
- // }
114
+ callbackContext.success(result);
115
+ }catch (Exception e){
116
+ callbackContext.error("Corte error: " + e.toString());
117
+ }
118
+ return true;
119
+ }
130
120
 
131
121
  else if(action.equals("ImpressaoTexto")){
132
122
  try{
@@ -146,137 +136,138 @@ public class ElginM10Terminal {
146
136
  return true;
147
137
  }
148
138
 
149
- // else if(action.equals("ImpressaoCodigoBarras")){
150
- // try{
151
- // JSONObject params = args.getJSONObject(0);
139
+ else if(action.equals("ImpressaoCodigoBarras")){
140
+ try{
141
+ JSONObject params = args.getJSONObject(0);
152
142
 
153
- // int tipo = params.getInt("tipo");
154
- // String dados = params.getString("dados");
155
- // int altura = params.getInt("altura");
156
- // int largura = params.getInt("largura");
157
- // int HRI = params.getInt("HRI");
143
+ int tipo = params.getInt("tipo");
144
+ String dados = params.getString("dados");
145
+ int altura = params.getInt("altura");
146
+ int largura = params.getInt("largura");
147
+ int HRI = params.getInt("HRI");
158
148
 
159
- // int result = Termica.ImpressaoCodigoBarras(tipo, dados, altura, largura, HRI);
149
+ int result = Termica.ImpressaoCodigoBarras(tipo, dados, altura, largura, HRI);
160
150
 
161
- // callbackContext.success(result);
162
- // }catch (Exception e){
163
- // callbackContext.error("ImpressaoCodigoBarras error: " + e.toString());
164
- // }
165
- // return true;
166
- // }
151
+ callbackContext.success(result);
152
+ }catch (Exception e){
153
+ callbackContext.error("ImpressaoCodigoBarras error: " + e.toString());
154
+ }
155
+ return true;
156
+ }
167
157
 
168
- // else if (action.equals("DefinePosicao")){
169
- // try{
170
- // JSONObject params = args.getJSONObject(0);
158
+ else if (action.equals("DefinePosicao")){
159
+ try{
160
+ JSONObject params = args.getJSONObject(0);
171
161
 
172
- // int posicao = params.getInt("posicao");
162
+ int posicao = params.getInt("posicao");
173
163
 
174
- // int result = Termica.DefinePosicao(posicao);
164
+ int result = Termica.DefinePosicao(posicao);
175
165
 
176
- // callbackContext.success(result);
177
- // }catch (Exception e){
178
- // callbackContext.error("DefinePosicao error: " + e.toString());
179
- // }
180
- // return true;
181
- // }
166
+ callbackContext.success(result);
167
+ }catch (Exception e){
168
+ callbackContext.error("DefinePosicao error: " + e.toString());
169
+ }
170
+ return true;
171
+ }
182
172
 
183
- // else if(action.equals("ImpressaoQRCode")){
184
- // try{
185
- // JSONObject params = args.getJSONObject(0);
173
+ else if(action.equals("ImpressaoQRCode")){
174
+ try{
175
+ JSONObject params = args.getJSONObject(0);
186
176
 
187
- // String dados = params.getString("dados");
188
- // int tamanho = params.getInt("tamanho");
189
- // int nivelCorrecao = params.getInt("nivelCorrecao");
177
+ String dados = params.getString("dados");
178
+ int tamanho = params.getInt("tamanho");
179
+ int nivelCorrecao = params.getInt("nivelCorrecao");
190
180
 
191
- // int result = Termica.ImpressaoQRCode(dados, tamanho, nivelCorrecao);
181
+ int result = Termica.ImpressaoQRCode(dados, tamanho, nivelCorrecao);
192
182
 
193
- // callbackContext.success(result) ;
194
- // }catch (Exception e){
195
- // callbackContext.error("ImpressaoQRCode error: " + e.toString());
196
- // }
197
- // return true;
198
- // }
183
+ callbackContext.success(result) ;
184
+ }catch (Exception e){
185
+ callbackContext.error("ImpressaoQRCode error: " + e.toString());
186
+ }
187
+ return true;
188
+ }
199
189
 
200
- // else if(action.equals("ImprimeXMLNFCe")){
201
- // try{
202
- // JSONObject params = args.getJSONObject(0);
190
+ else if(action.equals("ImprimeXMLNFCe")){
191
+ try{
192
+ JSONObject params = args.getJSONObject(0);
203
193
 
204
- // String dados = params.getString("dados");
205
- // int indexcsc = params.getInt("indexcsc");
206
- // String csc = params.getString("csc");
207
- // int param = params.getInt("param");
194
+ String dados = params.getString("dados");
195
+ int indexcsc = params.getInt("indexcsc");
196
+ String csc = params.getString("csc");
197
+ int param = params.getInt("param");
208
198
 
209
- // int result = Termica.ImprimeXMLNFCe(dados, indexcsc, csc, param);
199
+ int result = Termica.ImprimeXMLNFCe(dados, indexcsc, csc, param);
210
200
 
211
- // callbackContext.success(result);
212
- // }catch (Exception e){
213
- // callbackContext.error("ImprimeXMLNFCe error: " + e.toString());
214
- // }
215
- // return true;
216
- // }
201
+ callbackContext.success(result);
202
+ }catch (Exception e){
203
+ callbackContext.error("ImprimeXMLNFCe error: " + e.toString());
204
+ }
205
+ return true;
206
+ }
217
207
 
218
- // else if(action.equals("ImprimeXMLSAT")){
219
- // try{
220
- // JSONObject params = args.getJSONObject(0);
208
+ else if(action.equals("ImprimeXMLSAT")){
209
+ try{
210
+ JSONObject params = args.getJSONObject(0);
221
211
 
222
- // String dados = params.getString("dados");
223
- // int param = params.getInt("param");
212
+ String dados = params.getString("dados");
213
+ int param = params.getInt("param");
224
214
 
225
- // int result = Termica.ImprimeXMLSAT(dados, param);
215
+ int result = Termica.ImprimeXMLSAT(dados, param);
226
216
 
227
- // callbackContext.success(result);
217
+ callbackContext.success(result);
228
218
 
229
- // }catch (Exception e){
230
- // callbackContext.error("ImprimeXMLSAT error: " + e.toString());
231
- // }
232
- // return true;
233
- // }
219
+ }catch (Exception e){
220
+ callbackContext.error("ImprimeXMLSAT error: " + e.toString());
221
+ }
222
+ return true;
223
+ }
234
224
 
235
- // else if(action.equals("AbreGavetaElgin")){
236
- // try{
237
- // int result = Termica.AbreGavetaElgin();
225
+ else if(action.equals("AbreGavetaElgin")){
226
+ try{
227
+ int result = Termica.AbreGavetaElgin();
238
228
 
239
- // callbackContext.success(result);
240
- // } catch (Exception e){
241
- // callbackContext.error("AbreGavetaElgin error: " + e.toString());
242
- // }
243
- // }
229
+ callbackContext.success(result);
230
+ } catch (Exception e){
231
+ callbackContext.error("AbreGavetaElgin error: " + e.toString());
232
+ }
233
+ return true;
234
+ }
244
235
 
245
- // else if(action.equals("StatusImpressora")){
246
- // try{
247
- // JSONObject params = args.getJSONObject(0);
236
+ else if(action.equals("StatusImpressora")){
237
+ try{
238
+ JSONObject params = args.getJSONObject(0);
248
239
 
249
- // int param = params.getInt("param");
240
+ int param = params.getInt("param");
250
241
 
251
- // int result = Termica.StatusImpressora(param);
242
+ int result = Termica.StatusImpressora(param);
252
243
 
253
- // callbackContext.success(result);
254
- // }catch (Exception e){
255
- // callbackContext.error("StatusImpressora error: " + e.toString());
256
- // }
257
- // return true;
258
- // }
244
+ callbackContext.success(result);
245
+ }catch (Exception e){
246
+ callbackContext.error("StatusImpressora error: " + e.toString());
247
+ }
248
+ return true;
249
+ }
259
250
 
260
- // else if(action.equals("ImprimeImagem")){
261
- // try{
262
- // JSONObject params = args.getJSONObject(0);
251
+ // else if(action.equals("ImprimeImagem")){
252
+ // try{
253
+ // JSONObject params = args.getJSONObject(0);
263
254
 
264
- // if(params.getBoolean("cutPaper")) this.cutPaper = true;
265
- // else this.cutPaper = false;
255
+ // if(params.getBoolean("cutPaper")) this.cutPaper = true;
256
+ // else this.cutPaper = false;
266
257
 
267
- // Intent intent = new Intent((Intent.ACTION_PICK));
268
- // intent.setType("image/*");
258
+ // Intent intent = new Intent((Intent.ACTION_PICK));
259
+ // intent.setType("image/*");
269
260
 
270
- // this.selecionarImagemCallbackContext = callbackContext;
261
+ // // this.selecionarImagemCallbackContext = callbackContext;
271
262
 
272
- // this.cordova.setActivityResultCallback(this);
273
- // this.cordova.getActivity().startActivityForResult(intent, REQ_CODE_SELECAOIMAGEM);
263
+ // // this.cordova.setActivityResultCallback(this);
264
+ // // this.cordova.getActivity().startActivityForResult(intent, REQ_CODE_SELECAOIMAGEM);
274
265
 
275
- // }catch (Exception e){
276
- // callbackContext.error("ImprimirImagem error: " + e.toString());
277
- // }
278
- // return true;
279
- // }
266
+ // }catch (Exception e){
267
+ // callbackContext.error("ImprimirImagem error: " + e.toString());
268
+ // }
269
+ // return true;
270
+ // }
280
271
  return false;
281
272
  }
282
273
  }
package/src/build.gradle CHANGED
@@ -25,4 +25,6 @@ dependencies {
25
25
  //Em alguns frameworks (como o Ionic), pode ser necessário a definição de alguns atributos de cor utilizado por algumas das libs já incluidas, para evitar qualquer inconsistência nesse sentido
26
26
  //adicionamos a implementação desses atributos em específicos, assim não será necessário que o plugin depende de alguma dependência como app-compat ou similares.
27
27
  implementation 'com.android.support:design:28.0.0'
28
+
29
+ implementation 'com.google.code.gson:gson:2.8.9'
28
30
  }
@@ -6,8 +6,55 @@ exports.Teste = function (params, success, error) {
6
6
  exec(success, error, 'NetControllCordovaPluginsIntegration', 'Cielo.LioLocal.Teste', [params]);
7
7
  }
8
8
 
9
- exports.ListarPagamentos = function (params, success, error) {
10
- exec(success, error, 'NetControllCordovaPluginsIntegration', 'Cielo.LioLocal.ListarPagamentos', [params]);
9
+ exports.ConfigureSdk = function (params, success, error) {
10
+ exec(success, error, 'NetControllCordovaPluginsIntegration', 'Cielo.LioLocal.ConfigureSdk', [params]);
11
11
  }
12
12
 
13
13
 
14
+
15
+
16
+ exports.CreateDraftOrder = function (params, success, error) {
17
+ exec(success, error, 'NetControllCordovaPluginsIntegration', 'Cielo.LioLocal.CreateDraftOrder', [params]);
18
+ }
19
+
20
+ exports.AddOrderItem = function (params, success, error) {
21
+ exec(success, error, 'NetControllCordovaPluginsIntegration', 'Cielo.LioLocal.AddOrderItem', [params]);
22
+ }
23
+
24
+ exports.MakePayment = function (params, success, error) {
25
+ exec(success, error, 'NetControllCordovaPluginsIntegration', 'Cielo.LioLocal.MakePayment', [params]);
26
+ }
27
+
28
+
29
+
30
+ exports.ListOrders = function (params, success, error) {
31
+ exec(success, error, 'NetControllCordovaPluginsIntegration', 'Cielo.LioLocal.ListOrders', [params]);
32
+ }
33
+
34
+
35
+ exports.CancelPayment = function (param, success, error) {
36
+ exec(success, error, 'NetControllCordovaPluginsIntegration', 'Cielo.LioLocal.CancelPayment', [param]);
37
+ }
38
+
39
+ exports.PrintSimpleText = function (params, success, error) {
40
+ exec(success, error, 'NetControllCordovaPluginsIntegration', 'Cielo.LioLocal.PrintSimpleText', [params]);
41
+ }
42
+
43
+ // exports.PlaceOrder = function (params, success, error) {
44
+ // exec(success, error, 'NetControllCordovaPluginsIntegration', 'Cielo.LioLocal.PlaceOrder', [params]);
45
+ // }
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
@@ -2,10 +2,6 @@ var exec = require('cordova/exec');
2
2
 
3
3
  //Printer Functions
4
4
 
5
- exports.Teste = function (params, success, error) {
6
- exec(success, error, 'NetControllCordovaPluginsIntegration', 'Elgin.M10Terminal.Teste', [params]);
7
- }
8
-
9
5
  exports.AbreConexaoImpressora = function (params, success, error) {
10
6
  exec(success, error, 'NetControllCordovaPluginsIntegration', 'Elgin.M10Terminal.AbreConexaoImpressora', [params]);
11
7
  }
@@ -55,10 +51,10 @@ exports.StatusImpressora = function (params, success, error) {
55
51
  }
56
52
 
57
53
 
58
- //CUSTOM METHOD
59
- exports.imprimeImagem = function (params, success, error) {
60
- exec(success, error, 'NetControllCordovaPluginsIntegration', 'Elgin.M10Terminal.ImprimeImagem', [params]);
61
- }
54
+ // //CUSTOM METHOD
55
+ // exports.imprimeImagem = function (params, success, error) {
56
+ // exec(success, error, 'NetControllCordovaPluginsIntegration', 'Elgin.M10Terminal.ImprimeImagem', [params]);
57
+ // }
62
58
 
63
59
 
64
60