cordova-plugin-netcontroll-integration 1.0.9 → 1.0.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cordova-plugin-netcontroll-integration",
3
- "version": "1.0.9",
3
+ "version": "1.0.12",
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.9"
2
+ <plugin id="cordova-plugin-netcontroll-integration" version="1.0.12"
3
3
  xmlns="http://apache.org/cordova/ns/plugins/1.0"
4
4
  xmlns:android="http://schemas.android.com/apk/res/android">
5
5
 
@@ -19,6 +19,7 @@ import android.widget.Toast;
19
19
  import android.net.Uri;
20
20
  import android.content.Intent;
21
21
  import android.provider.MediaStore;
22
+ import android.os.Build;
22
23
 
23
24
  import static android.app.Activity.RESULT_OK;
24
25
 
@@ -38,12 +39,15 @@ import com.google.gson.GsonBuilder;
38
39
 
39
40
  import cielo.orders.domain.CancellationRequest;
40
41
  import cielo.orders.domain.Credentials;
42
+ import cielo.orders.domain.DeviceModel;
41
43
  import cielo.orders.domain.Item;
42
44
  import cielo.orders.domain.Order;
43
45
  import cielo.orders.domain.product.PrimaryProduct;
44
46
  import cielo.orders.domain.product.SecondaryProduct;
45
47
  import cielo.orders.domain.CheckoutRequest;
46
48
  import cielo.orders.domain.ResultOrders;
49
+ import cielo.orders.domain.PrinterAttributes;
50
+ import cielo.orders.domain.Settings;
47
51
 
48
52
  import cielo.sdk.order.OrderManager;
49
53
  import cielo.sdk.order.cancellation.CancellationListener;
@@ -52,6 +56,9 @@ import cielo.sdk.order.payment.Payment;
52
56
  import cielo.sdk.order.payment.PaymentCode;
53
57
  import cielo.sdk.order.payment.PaymentListener;
54
58
  import cielo.sdk.order.payment.PaymentError;
59
+ import cielo.sdk.order.PrinterListener;
60
+ import cielo.sdk.printer.PrinterManager;
61
+ import cielo.sdk.info.InfoManager;
55
62
 
56
63
 
57
64
  /**
@@ -61,7 +68,7 @@ public class CieloLioLocal {
61
68
 
62
69
  //Cielo Package Sdk
63
70
  public OrderManager orderManager;
64
-
71
+ public InfoManager infoManager;
65
72
 
66
73
 
67
74
  //Cielo Variables
@@ -71,6 +78,12 @@ public class CieloLioLocal {
71
78
  public Payment payment;
72
79
 
73
80
 
81
+ //Cielo Printer
82
+ private PrinterManager printerManager;
83
+ private PrinterListener printerListener;
84
+ private HashMap<String, Integer> alignCenter = new HashMap<>();
85
+ private HashMap<String, Integer> alignLeft = new HashMap<>();
86
+ private HashMap<String, Integer> alignRight = new HashMap<>();
74
87
 
75
88
  //Cordova/Java Params
76
89
  private Activity mActivity;
@@ -87,70 +100,64 @@ public class CieloLioLocal {
87
100
  public void initialize(CordovaInterface cordova, CordovaWebView webView) {
88
101
  this.webView = webView;
89
102
  mActivity = cordova.getActivity();
90
- mContext = cordova.getActivity().getApplicationContext();
91
- }
92
-
93
- public String Teste() {
94
- return "Result - CieloLioLocalClass: ok";
103
+ // mContext = cordova.getActivity().getApplicationContext();
104
+ mContext = this.webView.getContext();
95
105
  }
96
106
 
97
107
  public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
98
-
99
- if (action.equals("Teste")) {
100
- int arg1 = args.getInt(0);
101
- if (arg1 == 0) {
102
- Credentials credentials = new Credentials("M2vcq2fr0oWKbKd5bvpDoGZvHXQ8IneDLBJEulDjxNA59MOA2D/ EMOfYfErX7Y537JZgJvlgG0r805v5jYTxCgNiPtxm500bBUSxh", "NMgpwK4N5dcLCWnOr2kYbDIFcQdLPEn5M2ObKUTULEOdhxzFZu");
103
- orderManager = new OrderManager(credentials, mContext);
104
- if (credentials == null) {
105
- callbackContext.success("Result - CieloLioLocalClass: Erro Credencial " + action);
106
- return false;
107
- } else {
108
- callbackContext.success("Result - CieloLioLocalClass: Tem Credencial " + action + " Token: " + credentials.getAccessToken().toString());
109
- return true;
110
- }
111
- }
112
- else {
113
- callbackContext.success("Result - CieloLioLocalClass: noOk " + action);
114
- return false;
115
- }
116
- }
117
- else if (action.equals("ConfigureSdk")) {
108
+ if (action.equals("ConfigureSdk")) {
118
109
  JSONObject params = args.getJSONObject(0);
119
110
  try {
120
- this.configSDK(params.getString("clientId"),params.getString("accessToken"));
121
- if (this.orderManager == null) {
122
- callbackContext.error("Result - Cielo - LioLocal - ConfigureSdk: orderManager is null");
123
- return false;
124
- } else {
125
- callbackContext.success("Result - Cielo - LioLocal - ConfigureSdk: orderManager ok");
126
- return true;
127
- }
111
+ this.configSDK(params.getString("clientId"),params.getString("accessToken"), callbackContext);
112
+ return true;
128
113
  } catch (Exception error1) {
129
114
  callbackContext.error("Result - Cielo - LioLocal - ConfigureSdk: " + "Error Detail: " + error1);
130
115
  }
131
116
  return false;
132
117
  }
133
- else if (action.equals("PlaceOrder")) {
134
- JSONObject params = args.getJSONObject(0);
118
+ if (action.equals("OrderManagerBind")) {
135
119
  try {
136
- this.placeOrder(params.getString("productName"));
137
- // callbackContext.success("Result - Cielo - LioLocal PlaceOrder: ok ");
138
- if (order != null) {
139
- callbackContext.success("Result - Cielo - LioLocal PlaceOrder - order: ok (" + order.getReference() + ")");
140
- } else {
141
- callbackContext.success("Result - Cielo - LioLocal PlaceOrder - order is null: Error ");
142
- return false;
143
- }
120
+ this.orderManagerBind(callbackContext);
144
121
  return true;
145
122
  } catch (Exception error1) {
146
- callbackContext.error("Result - Cielo - LioLocal PlaceOrder: " + "Error Detail: " + error1);
123
+ callbackContext.error("Result - Cielo - LioLocal - OrderManagerBind: " + "Error Detail: " + error1);
124
+ }
125
+ return false;
126
+ }
127
+
128
+
129
+ else if (action.equals("CreateDraftOrder")) {
130
+ JSONObject params = args.getJSONObject(0);
131
+ try {
132
+ boolean result = this.createDraftOrder(params.getString("orderReference"), callbackContext);
133
+ return result;
134
+ } catch (Exception error1) {
135
+ callbackContext.error("Result - Cielo - LioLocal CreateDraftOrder: " + "Error Detail: " + error1);
136
+ }
137
+ return false;
138
+ }
139
+ else if (action.equals("AddOrderItem")) {
140
+ JSONObject params = args.getJSONObject(0);
141
+ try {
142
+ boolean result = this.addOrderItem(
143
+ params.getString("sku"),
144
+ params.getString("name"),
145
+ params.getInt("unitPrice"),
146
+ params.getInt("quantity"),
147
+ params.getString("unityOfMeasure"),
148
+ callbackContext
149
+ );
150
+ return result;
151
+ } catch (Exception error1) {
152
+ callbackContext.error("Result - Cielo - LioLocal AddOrderItem: " + "Error Detail: " + error1);
147
153
  }
148
154
  return false;
149
155
  }
150
156
  else if (action.equals("MakePayment")) {
151
157
  JSONObject params = args.getJSONObject(0);
152
158
  try {
153
- this.makePayment(
159
+ boolean result = this.makePayment(
160
+ params.getString("orderReference"),
154
161
  params.getString("orderId"),
155
162
  params.getInt("amount"),
156
163
  params.getString("ec"),
@@ -159,55 +166,115 @@ public class CieloLioLocal {
159
166
  params.getString("paymentCode"),
160
167
  callbackContext
161
168
  );
162
- return true;
169
+ return result;
163
170
  } catch (Exception error1) {
164
171
  callbackContext.error("Result - Cielo - LioLocal MakePayment: " + "Error Detail: " + error1);
165
172
  }
166
173
  return false;
167
174
  }
168
- else if (action.equals("ListOrders")) {
175
+ else if (action.equals("OrderManagerUnbind")) {
169
176
  try {
170
- this.listOrders(callbackContext);
177
+ orderManager.unbind();
178
+ orderManagerServiceBinded = false;
179
+ callbackContext.success("Unbind: Success");
171
180
  return true;
181
+ } catch (Exception error1) {
182
+ callbackContext.error("Result - Cielo - LioLocal Unbind: " + "Error Detail: " + error1);
183
+ }
184
+ return false;
185
+ }
186
+
187
+
188
+
189
+
190
+
191
+ else if (action.equals("ListOrders")) {
192
+ JSONObject params = args.getJSONObject(0);
193
+ try {
194
+ boolean result = this.listOrders(params.getInt("pageSize"), params.getInt("page"), callbackContext);
195
+ return result;
172
196
  } catch (Exception error1) {
173
197
  callbackContext.error("Result - Cielo - LioLocal ListOrders: " + "Error Detail: " + error1);
174
198
  }
175
199
  }
200
+
176
201
  else if (action.equals("CancelPayment")) {
177
202
  JSONObject paramsObj = args.getJSONObject(0);
178
203
  try {
179
- // JSONObject jobj = args.getJSONObject(0);
180
- // JSONObject jobj = new JSONObject(json);
204
+ boolean result = this.cancelPayment(paramsObj, callbackContext);
205
+ return result;
206
+ } catch (Exception error1) {
207
+ callbackContext.error("Result - Cielo - LioLocal ListOrders: " + "Error Detail: " + error1);
208
+ }
209
+ }
181
210
 
182
211
 
183
- // // JSONObject params = args.getJSONObject(0);
184
- // // Order cancelOrder =
185
- // // var testes = args.getJSONObject(0);
186
- // // JSONObject data = args.getJSONObject(0);
187
- // // JSONObject data = args.getJSONObject();
188
- this.cancelPayment(paramsObj, callbackContext);
189
- // callbackContext.success(paramsObj);
212
+ else if (action.equals("TerminalInformation")) {
213
+ try {
214
+ boolean result = this.terminalInformation(callbackContext);
215
+ return result;
216
+ } catch (Exception error1) {
217
+ callbackContext.error("Result - Cielo - LioLocal ListOrders: " + "Error Detail: " + error1);
218
+ }
219
+ }
190
220
 
191
221
 
192
- return true;
222
+ else if (action.equals("PrintSimpleText")) {
223
+ JSONObject params = args.getJSONObject(0);
224
+ try {
225
+ boolean result = this.print_SimpleText(
226
+ params.getString("textToPrint"),
227
+ params.getInt("textAlign"),
228
+ params.getInt("textSize"),
229
+ params.getInt("textTypeFace"),
230
+ 0,
231
+ 0,
232
+ 0,
233
+ 0,
234
+ 0,
235
+ 0,
236
+ //params.getInt("textMarginLeft"),
237
+ //params.getInt("textMarginRight"),
238
+ //params.getInt("textMarginTop"),
239
+ //params.getInt("textMarginBotton"),
240
+ //params.getInt("textLineSpace"),
241
+ //params.getInt("textWeight"),
242
+ callbackContext);
243
+ return result;
193
244
  } catch (Exception error1) {
194
- callbackContext.error("Result - Cielo - LioLocal ListOrders: " + "Error Detail: " + error1);
245
+ callbackContext.error("Result - Cielo - LioLocal PrintSimpleText: " + "Error Detail: " + error1);
195
246
  }
247
+ }
196
248
 
249
+ else if (action.equals("PrintQrCode")) {
250
+ JSONObject params = args.getJSONObject(0);
251
+ try {
252
+ boolean result = this.print_QrCode(
253
+ params.getString("textToPrint"),
254
+ params.getInt("textAlign"),
255
+ params.getInt("size"),
256
+ callbackContext);
257
+ return result;
258
+ } catch (Exception error1) {
259
+ callbackContext.error("Result - Cielo - LioLocal PrintQrCode: " + "Error Detail: " + error1);
260
+ }
261
+ }
197
262
 
198
- // JSONObject params = args.getJSONObject(0);
199
- // JSONObject params = args.getJSONObject(0);
200
- // try {
201
- // String idCancel = params.getString("id");
202
- // // Toast.makeText(mContext,String.format("configSDK: onServiceUnbound"), Toast.LENGTH_LONG).show();
203
-
204
- // this.cancelPayment(params.getString("id"), callbackContext);
205
- // callbackContext.success("Result - Cielo - LioLocal CancelPayment: ok");
206
- // return true;
207
- // } catch (Exception error1) {
208
- // callbackContext.error("Result - Cielo - LioLocal ListOrders: " + "Error Detail: " + error1);
209
- // }
263
+ else if (action.equals("PrintBarCode")) {
264
+ JSONObject params = args.getJSONObject(0);
265
+ try {
266
+ boolean result = this.print_BarCode(
267
+ params.getString("textToPrint"),
268
+ params.getInt("textAlign"),
269
+ params.getInt("barcodeWidth"),
270
+ params.getInt("barcodeHeight"),
271
+ callbackContext);
272
+ return result;
273
+ } catch (Exception error1) {
274
+ callbackContext.error("Result - Cielo - LioLocal PrintBarCode: " + "Error Detail: " + error1);
275
+ }
210
276
  }
277
+
211
278
  return false;
212
279
  }
213
280
 
@@ -266,23 +333,26 @@ public class CieloLioLocal {
266
333
 
267
334
 
268
335
  // Cielo Functions
269
- protected void configSDK(String clientId, String accessToken) {
336
+
337
+ protected void configSDK(String clientId, String accessToken, CallbackContext callbackContext) {
270
338
  this._credentials = new Credentials(clientId, accessToken);
271
339
  this.orderManager = new OrderManager(this._credentials, this.mContext);
272
- this.orderManager.bind(this.mContext, new ServiceBindListener() {
340
+ callbackContext.success("configSDK: ok");
341
+ }
273
342
 
343
+ protected void orderManagerBind(CallbackContext callbackContext) {
344
+ this.orderManager.bind(this.mContext, new ServiceBindListener() {
274
345
  @Override
275
346
  public void onServiceBoundError(Throwable throwable) {
276
347
  orderManagerServiceBinded = false;
277
-
278
- // Toast.makeText(mContext,
279
- // String.format("configSDK: onServiceBoundError: Erro fazendo bind do serviço de ordem -> %s",
280
- // throwable.getMessage()), Toast.LENGTH_LONG).show();
348
+ callbackContext.error(String.format("orderManagerBind: onServiceBoundError: Erro fazendo bind do serviço de ordem -> %s",
349
+ throwable.getMessage()));
281
350
  }
282
351
 
283
352
  @Override
284
353
  public void onServiceBound() {
285
354
  orderManagerServiceBinded = true;
355
+ callbackContext.success("orderManagerBind: onServiceBound: Success");
286
356
  // orderManager.createDraftOrder("REFERENCIA DA ORDEM");
287
357
  // Toast.makeText(mContext,String.format("configSDK: onServiceBound"), Toast.LENGTH_LONG).show();
288
358
  }
@@ -290,135 +360,156 @@ public class CieloLioLocal {
290
360
  @Override
291
361
  public void onServiceUnbound() {
292
362
  orderManagerServiceBinded = false;
363
+ callbackContext.success("orderManagerBind: onServiceUnbound: Success");
293
364
  // Toast.makeText(mContext,String.format("configSDK: onServiceUnbound"), Toast.LENGTH_LONG).show();
294
365
  }
295
366
  });
296
367
  }
297
368
 
298
- protected void placeOrder(String productName) {
369
+ protected boolean createDraftOrder(String orderReference, CallbackContext callbackContext) {
299
370
  if (!orderManagerServiceBinded) {
300
- // Toast.makeText(mContext, "Serviço de ordem ainda não recebeu retorno do método bind().\n"
301
- // + "Verifique sua internet e tente novamente", Toast.LENGTH_LONG).show();
302
- return;
371
+ callbackContext.error("createDraftOrder: onServiceBoundError: No binded order manager");
372
+ return false;
373
+ }
374
+ order = orderManager.createDraftOrder(orderReference);
375
+ if (order != null) {
376
+ callbackContext.success(this.parseObjToJsonSrtring(order));
377
+ return true;
303
378
  }
379
+ return false;
380
+ }
304
381
 
305
- // placeOrderButton.setEnabled(false);
306
- order = orderManager.createDraftOrder("REFERENCIA DA ORDEM");
307
- order.addItem("8989", "PROD LCS", 100, 3, "EACH");
308
- orderManager.updateOrder(order);
382
+ protected boolean addOrderItem(String sku,
383
+ String name,
384
+ int unitPrice,
385
+ int quantity,
386
+ String unityOfMeasure,
387
+ CallbackContext callbackContext) {
388
+ if (!orderManagerServiceBinded) {
389
+ callbackContext.error("createDraftOrder: onServiceBoundError: No binded order manager");
390
+ return false;
391
+ }
392
+ order.addItem(sku, name, unitPrice, quantity, unityOfMeasure);
393
+ callbackContext.success(this.parseObjToJsonSrtring(order));
394
+ return true;
309
395
  }
310
396
 
311
- protected void makePayment(String orderId,
312
- long amount,
313
- String ec,
314
- int installments,
315
- String email,
316
- String paymentCodeStr,
317
- CallbackContext callbackContext) {
397
+ protected boolean makePayment(String orderReference,
398
+ String orderId,
399
+ long amount,
400
+ String ec,
401
+ int installments,
402
+ String email,
403
+ String paymentCodeStr,
404
+ CallbackContext callbackContext) {
405
+ if (!orderManagerServiceBinded) {
406
+ callbackContext.error("makePayment error: No binded order manager");
407
+ return false;
408
+ }
409
+ if (order == null) {
410
+ callbackContext.error("makePayment error: No order found");
411
+ return false;
412
+ } else {
413
+ if (!orderReference.equals(order.getReference())) {
414
+ callbackContext.error("makePayment error: The order reference is not the same as the current order (Reference: " + orderReference + ") - (Current order Reference: " + order.getReference() + ")");
415
+ return false;
416
+ }
417
+ }
318
418
  cielo.sdk.order.payment.PaymentCode paymentCode = GetPaymentCodeFromName(paymentCodeStr);
319
419
  if (paymentCode == null) {
320
- callbackContext.error("Result - Cielo - LioLocal MakePayment: Invalid paymentCode (" + paymentCodeStr + ")");
321
- return;
420
+ callbackContext.error("makePayment error: Invalid paymentCode (" + paymentCodeStr + ")");
421
+ return false;
322
422
  }
423
+ orderManager.placeOrder(order);
424
+ try
425
+ {
426
+ CheckoutRequest.Builder requestBuilder = new CheckoutRequest.Builder()
427
+ .orderId(orderId)
428
+ // .orderId(order.getId())
429
+ .amount(amount)
430
+ .paymentCode(paymentCode)
431
+ .installments(installments);
432
+
433
+ if (!ec.equals(""))
434
+ requestBuilder.ec(ec);
435
+ if (!email.equals(""))
436
+ requestBuilder.email(email);
437
+
438
+ CheckoutRequest request = requestBuilder.build();
439
+ orderManager.checkoutOrder(request, new PaymentListener() {
440
+ @Override
441
+ public void onStart() {
442
+ }
323
443
 
444
+ @Override
445
+ public void onPayment(Order paidOrder) {
446
+ order = paidOrder;
447
+ order.markAsPaid();
448
+ orderManager.updateOrder(order);
449
+ callbackContext.success(parseObjToJsonSrtring(order));
450
+ resetState();
451
+ }
324
452
 
325
- if (order != null) {
326
- orderManager.placeOrder(order);
327
- try {
328
- CheckoutRequest.Builder requestBuilder = new CheckoutRequest.Builder()
329
- .orderId(order.getId())
330
- .amount(amount)
331
- .paymentCode(paymentCode)
332
- .installments(installments);
333
-
334
- if (!ec.equals(""))
335
- requestBuilder.ec(ec);
336
-
337
- if (!email.equals(""))
338
- requestBuilder.email(email);
453
+ @Override
454
+ public void onCancel() {
455
+ callbackContext.error("{Result - Cielo - LioLocal MakePayment: checkoutOrder - onCancel");
456
+ resetState();
457
+ }
339
458
 
340
- CheckoutRequest request = requestBuilder.build();
341
-
342
- orderManager.checkoutOrder(request, new PaymentListener() {
343
- @Override
344
- public void onStart() {
345
- // Toast.makeText(mContext,"Result - Cielo - LioLocal MakePayment: checkoutOrder - onStart", 0).show();
346
- // callbackContext.success("Result - Cielo - LioLocal MakePayment: checkoutOrder - onStart");
347
- // Log.d(TAG, "ON START");
348
- }
349
-
350
- @Override
351
- public void onPayment(Order paidOrder) {
352
- order = paidOrder;
353
- order.markAsPaid();
354
- orderManager.updateOrder(order);
355
- Gson gson = new Gson();
356
- callbackContext.success(gson.toJson(order));
357
- resetState();
358
- }
359
-
360
- @Override
361
- public void onCancel() {
362
- // Toast.makeText(mContext,String.format("Result - Cielo - LioLocal MakePayment: onCancel"), Toast.LENGTH_LONG).show();
363
- callbackContext.error("Result - Cielo - LioLocal MakePayment: checkoutOrder - onCancel");
364
- // Log.d(TAG, "ON CANCEL");
365
- resetState();
366
- }
367
-
368
- @Override
369
- public void onError(@NonNull PaymentError paymentError) {
370
- // Toast.makeText(mContext,String.format("Result - Cielo - LioLocal MakePayment: onError"), Toast.LENGTH_LONG).show();
371
- callbackContext.error("Result - Cielo - LioLocal MakePayment: checkoutOrder - onError");
372
- // Log.d(TAG, "ON ERROR");
373
- resetState();
374
- }
375
-
376
- });
377
-
378
- } catch (Exception error1) {
379
- callbackContext.error("makePayment " + "- Error Detail: " + error1);
380
- throw error1;
381
- }
459
+ @Override
460
+ public void onError(@NonNull PaymentError paymentError) {
461
+ callbackContext.error("Result - Cielo - LioLocal MakePayment: checkoutOrder - onError");
462
+ resetState();
463
+ }
464
+
465
+ });
466
+ } catch (Exception error1) {
467
+ callbackContext.error("makePayment " + "- Error Detail: " + error1);
468
+ throw error1;
469
+ }
470
+ return true;
471
+ }
382
472
 
383
473
 
384
- // if (!ec.equals(""))
385
- // requestBuilder.ec(ec);
386
474
 
387
- // if (!userEmail.equals(""))
388
- // requestBuilder.email(userEmail);
389
475
 
390
- // CheckoutRequest request = requestBuilder.build();
476
+ protected boolean listOrders(int pageSize, int page, CallbackContext callbackContext) {
477
+ if (!orderManagerServiceBinded) {
478
+ callbackContext.error("listOrders: onServiceBoundError: No binded order manager");
479
+ return false;
391
480
  }
392
- }
393
-
394
- protected void listOrders(CallbackContext callbackContext) {
395
481
  try {
396
- ResultOrders resultOrders = orderManager.retrieveOrders(200, 0);
482
+ ResultOrders resultOrders = orderManager.retrieveOrders(pageSize, page);
397
483
  if (resultOrders != null) {
398
- Gson gson = new Gson();
399
- callbackContext.success(gson.toJson(resultOrders));
484
+ String resultOrdersStr = parseObjToJsonSrtring(resultOrders);
485
+ callbackContext.success(resultOrdersStr);
400
486
  } else {
401
487
  callbackContext.success("null");
402
488
  }
489
+ return true;
403
490
  } catch (Exception error1) {
404
491
  callbackContext.error("Result - Cielo - LioLocal - listOrders: " + "Error Detail: " + error1);
405
492
  }
493
+ return false;
406
494
  }
407
495
 
408
- protected void cancelPayment(JSONObject orderObj, CallbackContext callbackContext) {
496
+ protected boolean cancelPayment(JSONObject orderObj, CallbackContext callbackContext) {
497
+ if (!orderManagerServiceBinded) {
498
+ callbackContext.error("cancelPayment: onServiceBoundError: No binded order manager");
499
+ return false;
500
+ }
409
501
  try {
410
502
  String jsonStr = orderObj.toString();
411
503
  Gson gson = new Gson();
412
- //Order objCliente = gson.fromJson(jsonStr, Order.class);
413
- order = gson.fromJson(jsonStr, Order.class);
504
+ Order cancelOrder = gson.fromJson(jsonStr, Order.class);
414
505
 
415
- List<Payment> paymentList = order.getPayments();
506
+ List<Payment> paymentList = cancelOrder.getPayments();
416
507
  payment = paymentList.get(0);
417
508
 
418
509
 
419
- if (order != null && order.getPayments().size() > 0) {
510
+ if (cancelOrder != null && cancelOrder.getPayments().size() > 0) {
420
511
  CancellationRequest request = new CancellationRequest.Builder()
421
- .orderId(order.getId())
512
+ .orderId(cancelOrder.getId())
422
513
  .authCode(payment.getAuthCode())
423
514
  .cieloCode(payment.getCieloCode())
424
515
  .value(payment.getAmount())
@@ -429,42 +520,242 @@ public class CieloLioLocal {
429
520
 
430
521
  @Override
431
522
  public void onSuccess(Order cancelledOrder) {
432
- // Log.d(TAG, "ON SUCCESS");
433
523
  cancelledOrder.cancel();
434
524
  orderManager.updateOrder(cancelledOrder);
435
- //
436
- Toast.makeText(mContext, "CANCELAMENTO SUCESSO", Toast.LENGTH_SHORT).show();
437
525
  order = cancelledOrder;
438
- // resetState();
439
526
  callbackContext.success(parseObjToJsonSrtring(order));
440
527
  }
441
528
 
442
529
  @Override
443
530
  public void onCancel() {
444
531
  callbackContext.success("cancelPayment - onCancel");
445
- // Log.d(TAG, "ON CANCEL");
446
- //
447
- // Toast.makeText(CancelPaymentActivity.this, "CANCELADO", Toast.LENGTH_SHORT).show();
448
- // resetUI();
449
532
  }
450
533
 
451
534
  @Override
452
535
  public void onError(PaymentError paymentError) {
453
536
  callbackContext.success("cancelPayment - onError");
454
- // Log.d(TAG, "ON ERROR");
455
- //
456
- // Toast.makeText(CancelPaymentActivity.this, "ERRO", Toast.LENGTH_SHORT).show();
457
- // resetUI();
458
537
  }
459
538
  });
460
-
461
- // callbackContext.success(jsonStr);
462
539
  }
540
+ return true;
463
541
  } catch (Exception error1) {
464
- callbackContext.error("Result - Cielo - LioLocal - listOrders: " + "Error Detail: " + error1);
542
+ callbackContext.error("Result - Cielo - LioLocal - cancelPayment: " + "Error Detail: " + error1);
543
+ }
544
+ return false;
545
+ }
546
+
547
+
548
+ protected boolean terminalInformation(CallbackContext callbackContext) {
549
+ try {
550
+ infoManager = new InfoManager();
551
+ Settings settings = infoManager.getSettings(this.mActivity);
552
+
553
+ String logicNumber = settings.getLogicNumber();
554
+ Float batteryLevel = infoManager.getBatteryLevel(this.mActivity);
555
+ DeviceModel deviceModel = infoManager.getDeviceModel();
556
+
557
+
558
+ JSONObject json = new JSONObject();
559
+ json.put("logicNumber", logicNumber);
560
+ json.put("batteryLevel", batteryLevel);
561
+ json.put("deviceModel", deviceModel);
562
+
563
+
564
+
565
+ json.put("serial", Build.SERIAL);
566
+ json.put("model", Build.MODEL);
567
+ json.put("id", Build.ID);
568
+ json.put("manufacture", Build.MANUFACTURER);
569
+ json.put("brand", Build.BRAND);
570
+ json.put("type", Build.TYPE);
571
+ json.put("user", Build.USER);
572
+ json.put("base", Build.VERSION_CODES.BASE);
573
+ json.put("device", Build.DEVICE);
574
+ json.put("incremental", Build.VERSION.INCREMENTAL);
575
+ json.put("sdk", Build.VERSION.SDK);
576
+ json.put("board", Build.BOARD);
577
+ json.put("brand", Build.BRAND);
578
+ json.put("host", Build.HOST);
579
+ json.put("fingerprint", Build.FINGERPRINT);
580
+ json.put("versionCode", Build.VERSION.RELEASE);
581
+ json.put("hardware", Build.HARDWARE);
582
+ callbackContext.success(json.toString());
583
+ return true;
584
+ } catch (Exception error1) {
585
+ callbackContext.error("Result - Cielo - LioLocal - terminalInformation: " + "Error Detail: " + error1);
586
+ }
587
+ return false;
588
+ }
589
+
590
+
591
+
592
+
593
+
594
+
595
+
596
+
597
+
598
+
599
+ protected boolean print_initialize() {
600
+ setStyles();
601
+ printerManager = new PrinterManager(this.mContext);
602
+ printerListener = new PrinterListener() {
603
+ @Override
604
+ public void onWithoutPaper() {
605
+ //Log.d("PrintSampleActivity", "printer without paper");
606
+ }
607
+
608
+ @Override
609
+ public void onPrintSuccess() {
610
+ //Log.d("PrintSampleActivity", "print success!");
611
+ }
612
+
613
+ @Override
614
+ public void onError(Throwable throwable) {
615
+ //Log.d("PrintSampleActivity",String.format("printer error -> %s", throwable.getMessage()));
616
+ }
617
+ };
618
+ return true;
619
+ }
620
+
621
+ protected boolean print_SimpleText(String textToPrint,
622
+ int textAlign,
623
+ int textSize,
624
+ int textTypeFace,
625
+
626
+ int textMarginLeft,
627
+ int textMarginRight,
628
+ int textMarginTop,
629
+ int textMarginBotton,
630
+
631
+ int textLineSpace,
632
+ int textWeight,
633
+
634
+ CallbackContext callbackContext) {
635
+ try {
636
+ print_initialize();
637
+ HashMap<String, Integer> printStyle = new HashMap<>();
638
+
639
+ // Alinhamento da impressão
640
+ switch (textAlign) {
641
+ case 1: // Left
642
+ printStyle.put(PrinterAttributes.KEY_ALIGN, PrinterAttributes.VAL_ALIGN_LEFT);
643
+ break;
644
+ case 2: // Center
645
+ printStyle.put(PrinterAttributes.KEY_ALIGN, PrinterAttributes.VAL_ALIGN_CENTER);
646
+ break;
647
+ case 3: // Right
648
+ printStyle.put(PrinterAttributes.KEY_ALIGN, PrinterAttributes.VAL_ALIGN_RIGHT);
649
+ break;
650
+ default:
651
+ printStyle.put(PrinterAttributes.KEY_ALIGN, PrinterAttributes.VAL_ALIGN_LEFT);
652
+ break;
653
+ }
654
+
655
+ // Tamanho do texto
656
+ printStyle.put(PrinterAttributes.KEY_TEXT_SIZE, textSize);
657
+
658
+ // Fonte do texto
659
+ printStyle.put(PrinterAttributes.KEY_TYPEFACE, textTypeFace);
660
+
661
+ // Margem
662
+ // printStyle.put(PrinterAttributes.KEY_MARGINLEFT, textMarginLeft);
663
+ // printStyle.put(PrinterAttributes.KEY_MARGINRIGHT, textMarginRight);
664
+ // printStyle.put(PrinterAttributes.KEY_MARGINTOP, textMarginTop);
665
+ // printStyle.put(PrinterAttributes.KEY_MARGINBOTTOM, textMarginBotton);
666
+
667
+ // LineSpace
668
+ // printStyle.put(PrinterAttributes.KEY_LINESPACE, textLineSpace);
669
+
670
+ // Varíavel utilizada quando se trbaalho com impressão de múltiplas colunas, para escolher o peso de cada coluna
671
+ // printStyle.put(PrinterAttributes.KEY_WEIGHT, textWeight);
672
+
673
+ printerManager.printText(textToPrint, printStyle, printerListener);
674
+ callbackContext.success("Result - Cielo - LioLocal - print_SimpleText: OK");
675
+ return true;
676
+ } catch (Exception error1) {
677
+ callbackContext.error("Result - Cielo - LioLocal - print_SimpleText: " + "Error Detail: " + error1);
465
678
  }
679
+ return false;
466
680
  }
467
681
 
682
+ protected boolean print_QrCode(String textToPrint,
683
+ int textAlign,
684
+ int size,
685
+ CallbackContext callbackContext) {
686
+ try {
687
+ print_initialize();
688
+
689
+ // Alinhamento da impressão
690
+ switch (textAlign) {
691
+ case 1: // Left
692
+ printerManager.printQrCode(textToPrint, PrinterAttributes.VAL_ALIGN_LEFT, size, printerListener);
693
+ break;
694
+ case 2: // Center
695
+ printerManager.printQrCode(textToPrint, PrinterAttributes.VAL_ALIGN_CENTER, size, printerListener);
696
+ break;
697
+ case 3: // Right
698
+ printerManager.printQrCode(textToPrint, PrinterAttributes.VAL_ALIGN_RIGHT, size, printerListener);
699
+ break;
700
+ default:
701
+ printerManager.printQrCode(textToPrint, PrinterAttributes.VAL_ALIGN_LEFT, size, printerListener);
702
+ break;
703
+ }
704
+ callbackContext.success("Result - Cielo - LioLocal - print_QrCode: OK");
705
+ return true;
706
+ } catch (Exception error1) {
707
+ callbackContext.error("Result - Cielo - LioLocal - print_QrCode: " + "Error Detail: " + error1);
708
+ }
709
+ return false;
710
+ }
711
+
712
+ protected boolean print_BarCode(String textToPrint,
713
+ int textAlign,
714
+ int barcodeWidth,
715
+ int barcodeHeight,
716
+ CallbackContext callbackContext) {
717
+ try {
718
+ print_initialize();
719
+
720
+ // Alinhamento da impressão
721
+ switch (textAlign) {
722
+ case 1: // Left
723
+ printerManager.printBarCode(textToPrint, PrinterAttributes.VAL_ALIGN_LEFT, barcodeWidth, barcodeHeight, false, printerListener);
724
+ break;
725
+ case 2: // Center
726
+ printerManager.printBarCode(textToPrint, PrinterAttributes.VAL_ALIGN_CENTER, barcodeWidth, barcodeHeight, false, printerListener);
727
+ break;
728
+ case 3: // Right
729
+ printerManager.printBarCode(textToPrint, PrinterAttributes.VAL_ALIGN_RIGHT, barcodeWidth, barcodeHeight, false, printerListener);
730
+ break;
731
+ default:
732
+ printerManager.printBarCode(textToPrint, PrinterAttributes.VAL_ALIGN_LEFT, barcodeWidth, barcodeHeight, false, printerListener);
733
+ break;
734
+ }
735
+ callbackContext.success("Result - Cielo - LioLocal - print_BarCode: OK");
736
+ return true;
737
+ } catch (Exception error1) {
738
+ callbackContext.error("Result - Cielo - LioLocal - print_BarCode: " + "Error Detail: " + error1);
739
+ }
740
+ return false;
741
+ }
742
+
743
+ private void setStyles() {
744
+ // alignLeft.put(PrinterAttributes.KEY_ALIGN, PrinterAttributes.VAL_ALIGN_LEFT);
745
+ // alignLeft.put(PrinterAttributes.KEY_TYPEFACE, 0);
746
+ // alignLeft.put(PrinterAttributes.KEY_TEXT_SIZE, 30);
747
+
748
+ // alignCenter.put(PrinterAttributes.KEY_ALIGN, PrinterAttributes.VAL_ALIGN_CENTER);
749
+ // alignCenter.put(PrinterAttributes.KEY_TYPEFACE, 1);
750
+ // alignCenter.put(PrinterAttributes.KEY_TEXT_SIZE, 20);
751
+
752
+ // alignRight.put(PrinterAttributes.KEY_ALIGN, PrinterAttributes.VAL_ALIGN_RIGHT);
753
+ // alignRight.put(PrinterAttributes.KEY_TYPEFACE, 2);
754
+ // alignRight.put(PrinterAttributes.KEY_TEXT_SIZE, 10);
755
+ }
756
+
757
+
758
+ // Cielo Global
468
759
  protected String parseObjToJsonSrtring(Object obj) {
469
760
  Gson gson = new Gson();
470
761
  String result = gson.toJson(obj);
@@ -473,8 +764,6 @@ public class CieloLioLocal {
473
764
 
474
765
  protected void resetState() {
475
766
  order = null;
476
- // configUi();
477
- // updatePaymentButton();
478
767
  }
479
768
 
480
769
  }
@@ -10,20 +10,72 @@ exports.ConfigureSdk = function (params, success, error) {
10
10
  exec(success, error, 'NetControllCordovaPluginsIntegration', 'Cielo.LioLocal.ConfigureSdk', [params]);
11
11
  }
12
12
 
13
- exports.PlaceOrder = function (params, success, error) {
14
- exec(success, error, 'NetControllCordovaPluginsIntegration', 'Cielo.LioLocal.PlaceOrder', [params]);
13
+ exports.OrderManagerBind = function (success, error) {
14
+ exec(success, error, 'NetControllCordovaPluginsIntegration', 'Cielo.LioLocal.OrderManagerBind');
15
+ }
16
+
17
+ exports.OrderManagerUnbind = function (success, error) {
18
+ exec(success, error, 'NetControllCordovaPluginsIntegration', 'Cielo.LioLocal.OrderManagerUnbind');
19
+ }
20
+
21
+
22
+
23
+
24
+ exports.CreateDraftOrder = function (params, success, error) {
25
+ exec(success, error, 'NetControllCordovaPluginsIntegration', 'Cielo.LioLocal.CreateDraftOrder', [params]);
26
+ }
27
+
28
+ exports.AddOrderItem = function (params, success, error) {
29
+ exec(success, error, 'NetControllCordovaPluginsIntegration', 'Cielo.LioLocal.AddOrderItem', [params]);
15
30
  }
16
31
 
17
32
  exports.MakePayment = function (params, success, error) {
18
33
  exec(success, error, 'NetControllCordovaPluginsIntegration', 'Cielo.LioLocal.MakePayment', [params]);
19
34
  }
20
35
 
36
+
37
+
38
+
21
39
  exports.ListOrders = function (params, success, error) {
22
40
  exec(success, error, 'NetControllCordovaPluginsIntegration', 'Cielo.LioLocal.ListOrders', [params]);
23
41
  }
24
42
 
43
+
44
+
25
45
  exports.CancelPayment = function (param, success, error) {
26
46
  exec(success, error, 'NetControllCordovaPluginsIntegration', 'Cielo.LioLocal.CancelPayment', [param]);
27
47
  }
28
48
 
49
+ exports.PrintSimpleText = function (params, success, error) {
50
+ exec(success, error, 'NetControllCordovaPluginsIntegration', 'Cielo.LioLocal.PrintSimpleText', [params]);
51
+ }
52
+
53
+ exports.PrintQrCode = function (params, success, error) {
54
+ exec(success, error, 'NetControllCordovaPluginsIntegration', 'Cielo.LioLocal.PrintQrCode', [params]);
55
+ }
56
+
57
+ exports.PrintBarCode = function (params, success, error) {
58
+ exec(success, error, 'NetControllCordovaPluginsIntegration', 'Cielo.LioLocal.PrintBarCode', [params]);
59
+ }
60
+
61
+ // exports.PlaceOrder = function (params, success, error) {
62
+ // exec(success, error, 'NetControllCordovaPluginsIntegration', 'Cielo.LioLocal.PlaceOrder', [params]);
63
+ // }
64
+
65
+
66
+
67
+
68
+ exports.TerminalInformation = function (success, error) {
69
+ exec(success, error, 'NetControllCordovaPluginsIntegration', 'Cielo.LioLocal.TerminalInformation');
70
+ }
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
29
81