react-native-pos-pagseguro 1.0.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.
Files changed (125) hide show
  1. package/LICENSE +20 -0
  2. package/PosPagseguro.podspec +29 -0
  3. package/README.md +193 -0
  4. package/android/CMakeLists.txt +24 -0
  5. package/android/build.gradle +132 -0
  6. package/android/gradle.properties +5 -0
  7. package/android/libs/wrapper-1.30.52.aar +0 -0
  8. package/android/src/main/AndroidManifest.xml +2 -0
  9. package/android/src/main/cpp/cpp-adapter.cpp +6 -0
  10. package/android/src/main/java/com/margelo/nitro/pospagseguro/PosPagseguro.kt +251 -0
  11. package/android/src/main/java/com/margelo/nitro/pospagseguro/PosPagseguroPackage.kt +23 -0
  12. package/android/src/main/java/com/margelo/nitro/pospagseguro/maps/SubAcquirer.kt +23 -0
  13. package/android/src/main/java/com/margelo/nitro/pospagseguro/maps/TransactionResult.kt +53 -0
  14. package/android/src/main/java/com/margelo/nitro/pospagseguro/maps/Userdata.kt +17 -0
  15. package/ios/PosPagseguro.swift +5 -0
  16. package/lib/module/PosPagseguro.nitro.js +4 -0
  17. package/lib/module/PosPagseguro.nitro.js.map +1 -0
  18. package/lib/module/index.js +7 -0
  19. package/lib/module/index.js.map +1 -0
  20. package/lib/module/package.json +1 -0
  21. package/lib/module/pag_seguro.js +290 -0
  22. package/lib/module/pag_seguro.js.map +1 -0
  23. package/lib/module/types/device.js +71 -0
  24. package/lib/module/types/device.js.map +1 -0
  25. package/lib/module/types/exceptions.js +16 -0
  26. package/lib/module/types/exceptions.js.map +1 -0
  27. package/lib/module/types/payments.js +84 -0
  28. package/lib/module/types/payments.js.map +1 -0
  29. package/lib/typescript/package.json +1 -0
  30. package/lib/typescript/src/PosPagseguro.nitro.d.ts +27 -0
  31. package/lib/typescript/src/PosPagseguro.nitro.d.ts.map +1 -0
  32. package/lib/typescript/src/index.d.ts +7 -0
  33. package/lib/typescript/src/index.d.ts.map +1 -0
  34. package/lib/typescript/src/pag_seguro.d.ts +188 -0
  35. package/lib/typescript/src/pag_seguro.d.ts.map +1 -0
  36. package/lib/typescript/src/types/device.d.ts +92 -0
  37. package/lib/typescript/src/types/device.d.ts.map +1 -0
  38. package/lib/typescript/src/types/exceptions.d.ts +16 -0
  39. package/lib/typescript/src/types/exceptions.d.ts.map +1 -0
  40. package/lib/typescript/src/types/payments.d.ts +205 -0
  41. package/lib/typescript/src/types/payments.d.ts.map +1 -0
  42. package/nitro.json +16 -0
  43. package/nitrogen/generated/android/c++/JCapabilities.hpp +100 -0
  44. package/nitrogen/generated/android/c++/JCardIssuerNationality.hpp +61 -0
  45. package/nitrogen/generated/android/c++/JCustomError.hpp +61 -0
  46. package/nitrogen/generated/android/c++/JFunc_void_std__string.hpp +76 -0
  47. package/nitrogen/generated/android/c++/JHybridPosPagseguroSpec.cpp +248 -0
  48. package/nitrogen/generated/android/c++/JHybridPosPagseguroSpec.hpp +81 -0
  49. package/nitrogen/generated/android/c++/JInstallmentTypes.hpp +61 -0
  50. package/nitrogen/generated/android/c++/JPaymentData.hpp +81 -0
  51. package/nitrogen/generated/android/c++/JPaymentTypes.hpp +64 -0
  52. package/nitrogen/generated/android/c++/JSubAcquirer.hpp +101 -0
  53. package/nitrogen/generated/android/c++/JTransactionResult.hpp +208 -0
  54. package/nitrogen/generated/android/c++/JUserData.hpp +86 -0
  55. package/nitrogen/generated/android/c++/JVariant_CustomError_TransactionResult.cpp +26 -0
  56. package/nitrogen/generated/android/c++/JVariant_CustomError_TransactionResult.hpp +75 -0
  57. package/nitrogen/generated/android/c++/JVariant_Double_CustomError.cpp +26 -0
  58. package/nitrogen/generated/android/c++/JVariant_Double_CustomError.hpp +70 -0
  59. package/nitrogen/generated/android/c++/JVoidPayData.hpp +72 -0
  60. package/nitrogen/generated/android/c++/JVoidType.hpp +58 -0
  61. package/nitrogen/generated/android/kotlin/com/margelo/nitro/pospagseguro/Capabilities.kt +37 -0
  62. package/nitrogen/generated/android/kotlin/com/margelo/nitro/pospagseguro/CardIssuerNationality.kt +24 -0
  63. package/nitrogen/generated/android/kotlin/com/margelo/nitro/pospagseguro/CustomError.kt +41 -0
  64. package/nitrogen/generated/android/kotlin/com/margelo/nitro/pospagseguro/Func_void_std__string.kt +80 -0
  65. package/nitrogen/generated/android/kotlin/com/margelo/nitro/pospagseguro/HybridPosPagseguroSpec.kt +132 -0
  66. package/nitrogen/generated/android/kotlin/com/margelo/nitro/pospagseguro/InstallmentTypes.kt +24 -0
  67. package/nitrogen/generated/android/kotlin/com/margelo/nitro/pospagseguro/PaymentData.kt +53 -0
  68. package/nitrogen/generated/android/kotlin/com/margelo/nitro/pospagseguro/PaymentTypes.kt +25 -0
  69. package/nitrogen/generated/android/kotlin/com/margelo/nitro/pospagseguro/SubAcquirer.kt +71 -0
  70. package/nitrogen/generated/android/kotlin/com/margelo/nitro/pospagseguro/TransactionResult.kt +149 -0
  71. package/nitrogen/generated/android/kotlin/com/margelo/nitro/pospagseguro/UserData.kt +59 -0
  72. package/nitrogen/generated/android/kotlin/com/margelo/nitro/pospagseguro/Variant_CustomError_TransactionResult.kt +59 -0
  73. package/nitrogen/generated/android/kotlin/com/margelo/nitro/pospagseguro/Variant_Double_CustomError.kt +59 -0
  74. package/nitrogen/generated/android/kotlin/com/margelo/nitro/pospagseguro/VoidPayData.kt +47 -0
  75. package/nitrogen/generated/android/kotlin/com/margelo/nitro/pospagseguro/VoidType.kt +23 -0
  76. package/nitrogen/generated/android/kotlin/com/margelo/nitro/pospagseguro/pospagseguroOnLoad.kt +35 -0
  77. package/nitrogen/generated/android/pospagseguro+autolinking.cmake +83 -0
  78. package/nitrogen/generated/android/pospagseguro+autolinking.gradle +27 -0
  79. package/nitrogen/generated/android/pospagseguroOnLoad.cpp +46 -0
  80. package/nitrogen/generated/android/pospagseguroOnLoad.hpp +25 -0
  81. package/nitrogen/generated/ios/PosPagseguro+autolinking.rb +60 -0
  82. package/nitrogen/generated/ios/PosPagseguro-Swift-Cxx-Bridge.cpp +65 -0
  83. package/nitrogen/generated/ios/PosPagseguro-Swift-Cxx-Bridge.hpp +422 -0
  84. package/nitrogen/generated/ios/PosPagseguro-Swift-Cxx-Umbrella.hpp +81 -0
  85. package/nitrogen/generated/ios/c++/HybridPosPagseguroSpecSwift.cpp +11 -0
  86. package/nitrogen/generated/ios/c++/HybridPosPagseguroSpecSwift.hpp +236 -0
  87. package/nitrogen/generated/ios/swift/Capabilities.swift +96 -0
  88. package/nitrogen/generated/ios/swift/CardIssuerNationality.swift +44 -0
  89. package/nitrogen/generated/ios/swift/CustomError.swift +35 -0
  90. package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +47 -0
  91. package/nitrogen/generated/ios/swift/Func_void_std__string.swift +47 -0
  92. package/nitrogen/generated/ios/swift/Func_void_std__variant_CustomError__TransactionResult_.swift +59 -0
  93. package/nitrogen/generated/ios/swift/Func_void_std__variant_double__CustomError_.swift +59 -0
  94. package/nitrogen/generated/ios/swift/HybridPosPagseguroSpec.swift +72 -0
  95. package/nitrogen/generated/ios/swift/HybridPosPagseguroSpec_cxx.swift +434 -0
  96. package/nitrogen/generated/ios/swift/InstallmentTypes.swift +44 -0
  97. package/nitrogen/generated/ios/swift/PaymentData.swift +74 -0
  98. package/nitrogen/generated/ios/swift/PaymentTypes.swift +48 -0
  99. package/nitrogen/generated/ios/swift/SubAcquirer.swift +85 -0
  100. package/nitrogen/generated/ios/swift/TransactionResult.swift +674 -0
  101. package/nitrogen/generated/ios/swift/UserData.swift +169 -0
  102. package/nitrogen/generated/ios/swift/Variant_CustomError_TransactionResult.swift +18 -0
  103. package/nitrogen/generated/ios/swift/Variant_Double_CustomError.swift +18 -0
  104. package/nitrogen/generated/ios/swift/VoidPayData.swift +64 -0
  105. package/nitrogen/generated/ios/swift/VoidType.swift +40 -0
  106. package/nitrogen/generated/shared/c++/Capabilities.hpp +76 -0
  107. package/nitrogen/generated/shared/c++/CardIssuerNationality.hpp +80 -0
  108. package/nitrogen/generated/shared/c++/CustomError.hpp +87 -0
  109. package/nitrogen/generated/shared/c++/HybridPosPagseguroSpec.cpp +37 -0
  110. package/nitrogen/generated/shared/c++/HybridPosPagseguroSpec.hpp +102 -0
  111. package/nitrogen/generated/shared/c++/InstallmentTypes.hpp +63 -0
  112. package/nitrogen/generated/shared/c++/PaymentData.hpp +108 -0
  113. package/nitrogen/generated/shared/c++/PaymentTypes.hpp +69 -0
  114. package/nitrogen/generated/shared/c++/SubAcquirer.hpp +127 -0
  115. package/nitrogen/generated/shared/c++/TransactionResult.hpp +234 -0
  116. package/nitrogen/generated/shared/c++/UserData.hpp +112 -0
  117. package/nitrogen/generated/shared/c++/VoidPayData.hpp +98 -0
  118. package/nitrogen/generated/shared/c++/VoidType.hpp +62 -0
  119. package/package.json +179 -0
  120. package/src/PosPagseguro.nitro.ts +32 -0
  121. package/src/index.ts +19 -0
  122. package/src/pag_seguro.ts +306 -0
  123. package/src/types/device.ts +97 -0
  124. package/src/types/exceptions.ts +19 -0
  125. package/src/types/payments.ts +215 -0
package/package.json ADDED
@@ -0,0 +1,179 @@
1
+ {
2
+ "name": "react-native-pos-pagseguro",
3
+ "version": "1.0.0",
4
+ "description": "Integration of plugpag for React Native",
5
+ "main": "./lib/module/index.js",
6
+ "types": "./lib/typescript/src/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "source": "./src/index.tsx",
10
+ "types": "./lib/typescript/src/index.d.ts",
11
+ "default": "./lib/module/index.js"
12
+ },
13
+ "./package.json": "./package.json"
14
+ },
15
+ "files": [
16
+ "src",
17
+ "lib",
18
+ "android",
19
+ "ios",
20
+ "cpp",
21
+ "nitrogen",
22
+ "nitro.json",
23
+ "*.podspec",
24
+ "react-native.config.js",
25
+ "!ios/build",
26
+ "!android/build",
27
+ "!android/gradle",
28
+ "!android/gradlew",
29
+ "!android/gradlew.bat",
30
+ "!android/local.properties",
31
+ "!**/__tests__",
32
+ "!**/__fixtures__",
33
+ "!**/__mocks__",
34
+ "!**/.*"
35
+ ],
36
+ "scripts": {
37
+ "example": "yarn workspace react-native-pos-pagseguro-example",
38
+ "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
39
+ "prepublishOnly": "bob build",
40
+ "nitrogen": "nitrogen",
41
+ "typecheck": "tsc",
42
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
43
+ "test": "jest",
44
+ "release": "release-it --only-version"
45
+ },
46
+ "keywords": [
47
+ "react-native",
48
+ "pagseguro",
49
+ "pos",
50
+ "payment",
51
+ "plugpag",
52
+ "moderninha",
53
+ "terminal",
54
+ "android",
55
+ "nitro-modules",
56
+ "pix",
57
+ "credit-card",
58
+ "debit",
59
+ "voucher",
60
+ "point-of-sale",
61
+ "mpos",
62
+ "react-native-pos",
63
+ "pagamento",
64
+ "maquininha",
65
+ "pagseguro-pos"
66
+ ],
67
+ "repository": {
68
+ "type": "git",
69
+ "url": "git+https://github.com/CECSMH/react-native-pos-pagseguro.git"
70
+ },
71
+ "author": "CECSMH (https://github.com/CECSMH)",
72
+ "license": "MIT",
73
+ "bugs": {
74
+ "url": "https://github.com/CECSMH/react-native-pos-pagseguro/issues"
75
+ },
76
+ "homepage": "https://github.com/CECSMH/react-native-pos-pagseguro#readme",
77
+ "publishConfig": {
78
+ "registry": "https://registry.npmjs.org/"
79
+ },
80
+ "devDependencies": {
81
+ "@commitlint/config-conventional": "^19.8.1",
82
+ "@react-native/babel-preset": "0.83.0",
83
+ "@react-native/eslint-config": "0.83.0",
84
+ "@release-it/conventional-changelog": "^10.0.1",
85
+ "del-cli": "^6.0.0",
86
+ "nitrogen": "^0.32.0",
87
+ "prettier": "^2.8.8",
88
+ "react": "19.2.0",
89
+ "react-native": "0.83.0",
90
+ "react-native-builder-bob": "^0.40.13",
91
+ "react-native-nitro-modules": "^0.32.0",
92
+ "release-it": "^19.0.4",
93
+ "turbo": "^2.5.6",
94
+ "typescript": "^5.9.2"
95
+ },
96
+ "peerDependencies": {
97
+ "react": "*",
98
+ "react-native": "*",
99
+ "react-native-nitro-modules": "^0.32.0"
100
+ },
101
+ "workspaces": [
102
+ "example"
103
+ ],
104
+ "packageManager": "yarn@4.11.0",
105
+ "react-native-builder-bob": {
106
+ "source": "src",
107
+ "output": "lib",
108
+ "targets": [
109
+ [
110
+ "custom",
111
+ {
112
+ "script": "nitrogen",
113
+ "clean": "nitrogen/"
114
+ }
115
+ ],
116
+ [
117
+ "module",
118
+ {
119
+ "esm": true
120
+ }
121
+ ],
122
+ [
123
+ "typescript",
124
+ {
125
+ "project": "tsconfig.build.json"
126
+ }
127
+ ]
128
+ ]
129
+ },
130
+ "prettier": {
131
+ "quoteProps": "consistent",
132
+ "singleQuote": true,
133
+ "tabWidth": 2,
134
+ "trailingComma": "es5",
135
+ "useTabs": false
136
+ },
137
+ "jest": {
138
+ "preset": "react-native",
139
+ "modulePathIgnorePatterns": [
140
+ "<rootDir>/example/node_modules",
141
+ "<rootDir>/lib/"
142
+ ]
143
+ },
144
+ "commitlint": {
145
+ "extends": [
146
+ "@commitlint/config-conventional"
147
+ ]
148
+ },
149
+ "release-it": {
150
+ "git": {
151
+ "commitMessage": "chore: release ${version}",
152
+ "tagName": "v${version}"
153
+ },
154
+ "npm": {
155
+ "publish": true
156
+ },
157
+ "github": {
158
+ "release": true
159
+ },
160
+ "plugins": {
161
+ "@release-it/conventional-changelog": {
162
+ "preset": {
163
+ "name": "angular"
164
+ }
165
+ }
166
+ }
167
+ },
168
+ "create-react-native-library": {
169
+ "type": "nitro-module",
170
+ "languages": "kotlin-swift",
171
+ "tools": [
172
+ "eslint",
173
+ "jest",
174
+ "lefthook",
175
+ "release-it"
176
+ ],
177
+ "version": "0.56.0"
178
+ }
179
+ }
@@ -0,0 +1,32 @@
1
+ import type { HybridObject } from 'react-native-nitro-modules';
2
+
3
+ import type { CustomError } from './types/exceptions';
4
+ import type { PaymentData, TransactionResult, VoidPayData } from './types/payments';
5
+ import type { Capabilities, SubAcquirer, UserData } from './types/device';
6
+
7
+ export interface PosPagseguro extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
8
+ getModel(): string;
9
+ getSerialNumber(): string;
10
+ getSubAcquirerData(): SubAcquirer | undefined;
11
+ getUserData(): UserData;
12
+
13
+ reboot(): void;
14
+
15
+ reprintCustomerReceipt(): Promise<number | CustomError>;
16
+ reprintStablishmentReceipt(): Promise<number | CustomError>;
17
+
18
+ printFromFile(file_path: string, quality: number, bottomPad?: number): Promise<number | CustomError>;
19
+ printFromBase64(base_64: string, quality: number, bottomPad?: number): Promise<number | CustomError>;
20
+
21
+ abort(): CustomError | undefined;
22
+
23
+ isServiceBusy(): boolean;
24
+ isAuthenticated(): boolean;
25
+ hasCapability(capability: Capabilities): boolean;
26
+ initialize(activation_code: string): void;
27
+
28
+ doPayment(payment_data: PaymentData, process_callback: (event: string) => void): Promise<TransactionResult | CustomError>;
29
+ voidPayment(void_data: VoidPayData, process_callback: (event: string) => void): Promise<TransactionResult | CustomError>;
30
+
31
+ getLastApprovedTransaction(): TransactionResult | CustomError;
32
+ }
package/src/index.ts ADDED
@@ -0,0 +1,19 @@
1
+ import PagSeguro from './pag_seguro';
2
+ import { PaymentError, PrintError } from './types/exceptions';
3
+ import { InstallmentTypes, PaymentTypes, VoidType } from './types/payments';
4
+ import type { PaymentData, TransactionResult, VoidPayData } from './types/payments';
5
+
6
+
7
+ export type {
8
+ PaymentData,
9
+ VoidPayData,
10
+ TransactionResult
11
+ }
12
+ export {
13
+ PagSeguro as default,
14
+ VoidType,
15
+ PrintError,
16
+ PaymentError,
17
+ PaymentTypes,
18
+ InstallmentTypes,
19
+ }
@@ -0,0 +1,306 @@
1
+ import { NitroModules } from "react-native-nitro-modules";
2
+
3
+ import type { PosPagseguro } from "./PosPagseguro.nitro";
4
+ import { InstallmentTypes, PaymentTypes, VoidType, type PaymentData, type TransactionResult, type VoidPayData } from "./types/payments";
5
+
6
+ import { AbordError, PaymentError, PrintError } from "./types/exceptions";
7
+ import { Capabilities, type SubAcquirer, type UserData } from "./types/device";
8
+
9
+ const PosPagseguroHybridObject = NitroModules.createHybridObject<PosPagseguro>('PosPagseguro');
10
+
11
+ /**
12
+ * PagSeguro POS SDK para React Native
13
+ *
14
+ * Biblioteca de alto desempenho para integração com terminais PagSeguro (Moderninha, Smart, Pro, etc.)
15
+ * utilizando react-native-nitro-modules para comunicação nativa direta em Swift (iOS) e Kotlin (Android).
16
+ *
17
+ * ### Funcionalidades principais
18
+ * - Inicialização e ativação do terminal
19
+ * - Pagamentos: Crédito, Débito, Voucher e PIX
20
+ * - Parcelamento (à vista, lojista sem juros, comprador com juros)
21
+ * - Cancelamento/estorno de transações
22
+ * - Consulta da última transação aprovada
23
+ * - Reimpressão de vias (cliente e estabelecimento)
24
+ * - Impressão personalizada (arquivo ou Base64)
25
+ * - Aborto de operações em andamento
26
+ * - Reinício do terminal
27
+ * - Consulta de informações do dispositivo e estabelecimento
28
+ * - Verificação de recursos (impressora, NFC, chip, tarja, etc.)
29
+ *
30
+ * ### Tratamento de erros
31
+ * A maioria dos métodos assíncronos lança exceções específicas:
32
+ * - {@link PaymentError} → Erros de pagamento, validação ou comunicação
33
+ * - {@link PrintError} → Falhas na impressão ou reimpressão
34
+ * - {@link AbordError} → Erro ao tentar abortar operação
35
+ *
36
+ * ### Exemplo básico de uso
37
+ * ```ts
38
+ * await PagSeguro.initialize("SEU_CODIGO");
39
+ *
40
+ * const resultado = await PagSeguro.do_payment({
41
+ * amount: 1000, // R$ 10.00
42
+ * type: PaymentTypes.CREDIT,
43
+ * installment_type: InstallmentTypes.SELLER_INSTALLMENT,
44
+ * installments: 3,
45
+ * print_receipt: true
46
+ * });
47
+ *
48
+ * console.log("NSU:", resultado.transaction_code);
49
+ * ```
50
+ *
51
+ * @module PagSeguro
52
+ */
53
+ export default class PagSeguro {
54
+ /**
55
+ * Inicializa o terminal PagSeguro com o código de ativação fornecido.
56
+ *
57
+ * Deve ser chamado antes de qualquer outra operação.
58
+ * Após a inicialização bem-sucedida, o terminal fica autenticado e pronto para pagamentos.
59
+ *
60
+ * @param activation_code Código de ativação do terminal (fornecido pelo PagSeguro)
61
+ * @throws PaymentError Caso o código seja inválido ou ocorra falha na comunicação
62
+ *
63
+ * @example
64
+ * await PagSeguro.initialize("ABC123456");
65
+ */
66
+ static initialize(activation_code: string): void {
67
+ PosPagseguroHybridObject.initialize(activation_code);
68
+ };
69
+
70
+ /**
71
+ * Reinicia o terminal PagSeguro.
72
+ */
73
+ static reboot() { PosPagseguroHybridObject.reboot() }
74
+
75
+ /**
76
+ * Realiza um pagamento no terminal PagSeguro.
77
+ *
78
+ * Suporta todos os tipos de pagamento disponíveis (crédito, débito, voucher, PIX)
79
+ * e diferentes modalidades de parcelamento.
80
+ *
81
+ * @param data Dados do pagamento
82
+ * @param process_callback Callback opcional chamado com mensagens de progresso (ex: "APROXIME, INSIRA OU PASSE O CARTÃO")
83
+ * @returns Resultado completo da transação aprovada
84
+ * @throws PaymentError Em caso de erro de validação, rejeição ou falha na comunicação
85
+ *
86
+ * @example
87
+ * const tx = await PagSeguro.do_payment({
88
+ * amount: 2500, // R$ 25.00
89
+ * type: PaymentTypes.PIX,
90
+ * installment_type: InstallmentTypes.NO_INSTALLMENT,
91
+ * installments: 1,
92
+ * print_receipt: true
93
+ * });
94
+ */
95
+ static async do_payment(data: PaymentData, process_callback: (message: string) => void = () => { }): Promise<TransactionResult> {
96
+ validate_payment_data(data);
97
+ const r = await PosPagseguroHybridObject.doPayment(data, process_callback);
98
+ if ("message" in r && "code" in r) throw new PaymentError(r.code, r.message);
99
+ return r;
100
+ };
101
+
102
+ /**
103
+ * Realiza o cancelamento ou estorno de uma transação previamente aprovada.
104
+ *
105
+ * Funciona apenas para transações realizadas no mesmo dia (regra PagSeguro).
106
+ * Para cancelamentos administrativos de dias anteriores, usar o portal.
107
+ *
108
+ * @param data Dados necessários para identificar a transação a ser cancelada
109
+ * @param process_callback Callback opcional com mensagens de progresso
110
+ * @returns Resultado da operação de cancelamento
111
+ * @throws PaymentError Em caso de erro de validação ou rejeição
112
+ */
113
+ static async void_payment(data: VoidPayData, process_callback: (message: string) => void = () => { }): Promise<TransactionResult> {
114
+ validate_void_pay_data(data);
115
+ const r = await PosPagseguroHybridObject.voidPayment(data, process_callback);
116
+ if ("message" in r && "code" in r) throw new PaymentError(r.code, r.message);
117
+ return r;
118
+ }
119
+
120
+ /**
121
+ * Aborta imediatamente qualquer operação em andamento no terminal
122
+ *
123
+ * @throws AbordError Caso o aborto não seja possível ou falhe
124
+ */
125
+ static abort_current_operation(): void {
126
+ const r = PosPagseguroHybridObject.abort();
127
+ if (r == undefined) return;
128
+ if ("message" in r && "code" in r) throw new AbordError(r.code, r.message);
129
+ }
130
+
131
+ /**
132
+ * Obtém os dados da última transação aprovada realizada no terminal.
133
+ *
134
+ * @returns Dados completos da transação (valor, NSU, bandeira, etc.)
135
+ * @throws PaymentError Se não houver transação aprovada ou em caso de erro
136
+ */
137
+ static get_last_approved_transaction(): TransactionResult{
138
+ const r = PosPagseguroHybridObject.getLastApprovedTransaction();
139
+ if ("message" in r && "code" in r) throw new PaymentError(r.code, r.message);
140
+ return r;
141
+ };
142
+
143
+ /**
144
+ * Reimprime a via do cliente da última transação aprovada.
145
+ *
146
+ * @returns Linhas impressas
147
+ * @throws PrintError Em caso de falha na impressora
148
+ */
149
+ static async reprint_customer_receipt(): Promise<number> {
150
+ const r = await PosPagseguroHybridObject.reprintCustomerReceipt();
151
+ if (typeof r === "number") return r;
152
+ throw new PrintError(r.code, r.message);
153
+ }
154
+
155
+ /**
156
+ * Reimprime a via do estabelecimento da última transação aprovada.
157
+ *
158
+ * @returns Linhas impressas
159
+ * @throws PrintError Em caso de falha
160
+ */
161
+ static async reprint_stablishment_receipt(): Promise<number> {
162
+ const r = await PosPagseguroHybridObject.reprintStablishmentReceipt();
163
+ if (typeof r === "number") return r;
164
+ throw new PrintError(r.code, r.message);
165
+ }
166
+
167
+ /**
168
+ * Verifica se há usuário autenticado.
169
+ */
170
+ static is_authenticated(): boolean {
171
+ return PosPagseguroHybridObject.isAuthenticated();
172
+ };
173
+
174
+ /**
175
+ * Verifica se o terminal está executando alguma operação no momento.
176
+ */
177
+ static is_busy(): boolean {
178
+ return PosPagseguroHybridObject.isServiceBusy();
179
+ };
180
+
181
+ /**
182
+ * Retorna o modelo do terminal PagSeguro.
183
+ */
184
+ static get_model(): string {
185
+ return PosPagseguroHybridObject.getModel();
186
+ };
187
+
188
+ /**
189
+ * Retorna os dados do usuário logado no terminal (vendedor).
190
+ */
191
+ static get_userdata(): UserData {
192
+ return PosPagseguroHybridObject.getUserData();
193
+ };
194
+
195
+ /**
196
+ * Retorna o número de série do terminal.
197
+ */
198
+ static get_serial_number(): string {
199
+ return PosPagseguroHybridObject.getSerialNumber();
200
+ };
201
+
202
+ /**
203
+ * Retorna os dados do estabelecimento cadastrado no terminal (subadquirente).
204
+ */
205
+ static get_sub_acquirer_data(): SubAcquirer | undefined {
206
+ return PosPagseguroHybridObject.getSubAcquirerData();
207
+ };
208
+
209
+ /**
210
+ * Imprime um arquivo de imagem armazenado no dispositivo.
211
+ *
212
+ * @param path Caminho completo do arquivo no filesystem
213
+ * @param quality Qualidade da impressão. Padrão: 1
214
+ * @param bottomPad Número de linhas em branco ao final. Padrão: 70
215
+ * @returns Linhas impressas
216
+ * @throws PrintError Em caso de falha
217
+ */
218
+ static async print_from_filepath(path: string, quality: number = 1, bottomPad = 70): Promise<number> {
219
+ const r = await PosPagseguroHybridObject.printFromFile(path, quality, bottomPad);
220
+ if (typeof r === "number") return r;
221
+ throw new PrintError(r.code, r.message);
222
+ };
223
+
224
+ /**
225
+ * Imprime uma imagem a partir de uma string Base64.
226
+ * @param base64str String no formato Base64 (sem prefixo data:image/...)
227
+ * @param quality Qualidade da impressão. Padrão: 1
228
+ * @param bottomPad Linhas em branco ao final. Padrão: 70
229
+ * @returns Linhas impressas
230
+ * @throws PrintError Em caso de falha
231
+ */
232
+ static async print_from_base64(base64str: string, quality: number = 1, bottomPad = 70): Promise<number> {
233
+ const r = await PosPagseguroHybridObject.printFromBase64(base64str, quality, bottomPad);
234
+ if (typeof r === "number") return r;
235
+ throw new PrintError(r.code, r.message);
236
+ };
237
+
238
+ /**
239
+ * Verificação de recursos disponíveis no terminal.
240
+ *
241
+ * Permite adaptar a UI conforme os módulos presentes.
242
+ */
243
+ static readonly capabilities = {
244
+ /** Verifica presença de módulo Bluetooth */
245
+ has_bluetooth() {
246
+ return PosPagseguroHybridObject.hasCapability(Capabilities.BLUETOOTH);
247
+ },
248
+
249
+ /** Verifica leitor de tarja magnética */
250
+ has_mag() {
251
+ return PosPagseguroHybridObject.hasCapability(Capabilities.MAG);
252
+ },
253
+
254
+ /** Verifica leitor de chip (EMV) */
255
+ has_icc() {
256
+ return PosPagseguroHybridObject.hasCapability(Capabilities.ICC);
257
+ },
258
+
259
+ /** Verifica suporte a Contactless/NFC */
260
+ has_picc() {
261
+ return PosPagseguroHybridObject.hasCapability(Capabilities.PICC);
262
+ },
263
+
264
+ /** Verifica presença de impressora térmica */
265
+ has_printer() {
266
+ return PosPagseguroHybridObject.hasCapability(Capabilities.PRINTER);
267
+ },
268
+
269
+ /** Verifica conexão Ethernet */
270
+ has_ethernet() {
271
+ return PosPagseguroHybridObject.hasCapability(Capabilities.ETHERNET);
272
+ },
273
+
274
+ /** Verifica modem 3G/4G */
275
+ has_modem() {
276
+ return PosPagseguroHybridObject.hasCapability(Capabilities.MODEM);
277
+ }
278
+ }
279
+ }
280
+
281
+ function validate_payment_data(data: PaymentData): void {
282
+ if (data.amount <= 0) throw new PaymentError("INVALID_ARG", "O valor deve ser maior que zero.");
283
+ if (data.installments < 1) throw new PaymentError("INVALID_ARG", "O número de parcelas deve ser pelo menos 1.");
284
+ if (!Object.values(PaymentTypes).includes(data.type)) throw new PaymentError("INVALID_ARG", "O tipo de pagamento informado não é válido.");
285
+ if (!Object.values(InstallmentTypes).includes(data.installment_type)) throw new PaymentError("INVALID_ARG", `O tipo de parcelamento informado não é válido.`);
286
+ if (data.user_reference !== undefined) {
287
+ const ref = String(data.user_reference);
288
+ const regex = /^[a-zA-Z0-9]+$/;
289
+ if (!regex.test(ref)) throw new PaymentError("INVALID_ARG", "A referência do usuário deve conter apenas letras ou números.");
290
+ };
291
+ };
292
+
293
+ function validate_void_pay_data(data: VoidPayData): void {
294
+ if (!data.transaction_code || typeof data.transaction_code !== 'string' || data.transaction_code.trim() === '') {
295
+ throw new PaymentError("INVALID_ARG", "O transaction_code é obrigatório e deve ser uma string não vazia.");
296
+ }
297
+ if (!data.transaction_id || typeof data.transaction_id !== 'string' || data.transaction_id.trim() === '') {
298
+ throw new PaymentError("INVALID_ARG", "O transaction_id é obrigatório e deve ser uma string não vazia.");
299
+ }
300
+ if (data.print_receipt !== undefined && typeof data.print_receipt !== 'boolean') {
301
+ throw new PaymentError("INVALID_ARG", "O print_receipt deve ser do tipo boolean.");
302
+ }
303
+ if (data.void_type !== undefined && !Object.values(VoidType).includes(data.void_type)) {
304
+ throw new PaymentError("INVALID_ARG", "O void_type informado não é válido.");
305
+ }
306
+ }
@@ -0,0 +1,97 @@
1
+
2
+ export type SubAcquirer = {
3
+ name: string;
4
+ address: string;
5
+ city: string;
6
+ uf: string;
7
+ country: string;
8
+ zip_code: string;
9
+ mcc: string;
10
+ cnpj_cpf: string;
11
+ doc_type: string;
12
+ telephone: string;
13
+ full_name: string;
14
+ merchant_id: string;
15
+ }
16
+
17
+ export type UserData = {
18
+ address?: string;
19
+ city?: string;
20
+ cnpj_cpf?: string;
21
+ address_complement?: string;
22
+ company_name?: string;
23
+ nick_name?: string;
24
+ address_state?: string;
25
+ email?: string;
26
+ }
27
+
28
+
29
+ enum Capabilities {
30
+ /**
31
+ * Módulo de leitor de tarja magnética.
32
+ */
33
+ MAG = 1,
34
+ /**
35
+ * Módulo de leitor de chip.
36
+ */
37
+ ICC = 2,
38
+ /**
39
+ * Módulo de leitura por aproximação (Contactless).
40
+ */
41
+ PICC = 3,
42
+ /**
43
+ * Módulo de teclado seguro.
44
+ */
45
+ PED = 4,
46
+ /**
47
+ * Módulo de teclado externo.
48
+ */
49
+ KEYBOARD = 5,
50
+ /**
51
+ * Módulo de impressora.
52
+ */
53
+ PRINTER = 6,
54
+ /**
55
+ * Módulo de bluetooth.
56
+ */
57
+ BLUETOOTH = 7,
58
+ /**
59
+ * Módulo de caixa registradora.
60
+ */
61
+ CASH_BOX = 8,
62
+ /**
63
+ * Módulo de tela auxiliar.
64
+ */
65
+ CUSTOMER_DISPLAY = 9,
66
+ /**
67
+ * Módulo de rede.
68
+ */
69
+ ETHERNET = 10,
70
+ /**
71
+ * Módulo de leitor de digital.
72
+ */
73
+ FINGERPRINT_READER = 11,
74
+ /**
75
+ * Módulo de acelerômetro.
76
+ */
77
+ G_SENSOR = 12,
78
+ /**
79
+ * Módulo de saída HDMI.
80
+ */
81
+ HDMI = 13,
82
+ /**
83
+ * Módulo de leitor de cartões.
84
+ */
85
+ ID_CARD_READER = 14,
86
+ /**
87
+ * Módulo de SM.
88
+ */
89
+ SM = 15,
90
+ /**
91
+ * Módulo de modem.
92
+ */
93
+ MODEM = 16
94
+ }
95
+
96
+
97
+ export { Capabilities }
@@ -0,0 +1,19 @@
1
+
2
+
3
+ export type CustomError = {
4
+ code: string,
5
+ message: string
6
+ }
7
+
8
+ class CustomException extends Error {
9
+ code: string;
10
+ constructor(code: string, message: string) {
11
+ super(message);
12
+ this.code = code;
13
+ }
14
+ };
15
+
16
+
17
+ export class PaymentError extends CustomException{};
18
+ export class PrintError extends CustomException{};
19
+ export class AbordError extends CustomException{};