@@ -6,41 +6,53 @@ import type {
66 PlugpagAbortResult ,
77 PlugpagConstants ,
88} from './PlugpagNitro.nitro' ;
9+ import { PaymentType , InstallmentType , ErrorCode } from './PlugpagNitro.nitro' ;
910
10- const PlugpagNitroModule =
11- NitroModules . createHybridObject < PlugpagNitro > ( 'PlugpagNitro' ) ;
11+ // Re-export enums and types for easy access
12+ export {
13+ PaymentType ,
14+ InstallmentType ,
15+ ErrorCode ,
16+ ActionType ,
17+ } from './PlugpagNitro.nitro' ;
1218
13- // Export types
1419export type {
1520 PlugpagInitializationResult ,
1621 PlugpagTransactionResult ,
1722 PlugpagAbortResult ,
1823 PlugpagConstants ,
19- } ;
24+ PlugpagPaymentData ,
25+ PlugpagVoidData ,
26+ } from './PlugpagNitro.nitro' ;
27+
28+ const PlugpagNitroModule =
29+ NitroModules . createHybridObject < PlugpagNitro > ( 'PlugpagNitro' ) ;
2030
21- // Payment options interface
31+ // Payment options interface using enum types
2232export interface PaymentOptions {
2333 amount : number ;
24- type : number ;
25- installmentType ?: number ;
34+ type : PaymentType ;
35+ installmentType ?: InstallmentType ;
2636 installments ?: number ;
2737 printReceipt ?: boolean ;
2838 userReference ?: string ;
2939}
3040
31- // Payment type constants from PagBank SDK
41+ // Payment type constants (deprecated - use PaymentType enum instead)
42+ /** @deprecated Use PaymentType enum instead */
3243export const PaymentTypes = {
33- CREDIT : 1 ,
34- DEBIT : 2 ,
35- VOUCHER : 3 ,
36- PIX : 5 ,
44+ CREDIT : PaymentType . CREDIT ,
45+ DEBIT : PaymentType . DEBIT ,
46+ VOUCHER : PaymentType . VOUCHER ,
47+ PIX : PaymentType . PIX ,
3748} as const ;
3849
39- // Installment type constants
50+ // Installment type constants (deprecated - use InstallmentType enum instead)
51+ /** @deprecated Use InstallmentType enum instead */
4052export const InstallmentTypes = {
41- NO_INSTALLMENT : 1 ,
42- SELLER_INSTALLMENT : 2 ,
43- BUYER_INSTALLMENT : 3 ,
53+ NO_INSTALLMENT : InstallmentType . NO_INSTALLMENT ,
54+ SELLER_INSTALLMENT : InstallmentType . SELLER_INSTALLMENT ,
55+ BUYER_INSTALLMENT : InstallmentType . BUYER_INSTALLMENT ,
4456} as const ;
4557
4658// Simple error handling wrapper
@@ -93,14 +105,14 @@ export async function initializeAndActivatePinPad(
93105 */
94106export async function doPayment ( options : {
95107 amount : number ;
96- type : number ;
97- installmentType ?: number ;
108+ type : PaymentType ;
109+ installmentType ?: InstallmentType ;
98110 installments ?: number ;
99111 printReceipt ?: boolean ;
100112 userReference ?: string ;
101113} ) : Promise < PlugpagTransactionResult > {
102114 const paymentOptions = {
103- installmentType : options . installmentType ?? InstallmentTypes . NO_INSTALLMENT ,
115+ installmentType : options . installmentType ?? InstallmentType . NO_INSTALLMENT ,
104116 installments : options . installments ?? 1 ,
105117 printReceipt : options . printReceipt ?? true ,
106118 userReference : options . userReference ?? `payment-${ Date . now ( ) } ` ,
@@ -120,15 +132,15 @@ export async function doPayment(options: {
120132}
121133
122134/**
123- * Void/refund a previous payment transaction
135+ * Refund a previous payment transaction
124136 */
125- export async function voidPayment ( options : {
137+ export async function refundPayment ( options : {
126138 transactionCode : string ;
127139 transactionId : string ;
128140 printReceipt ?: boolean ;
129141} ) : Promise < PlugpagTransactionResult > {
130- return safeModuleCall ( 'voidPayment ' , ( ) =>
131- PlugpagNitroModule . voidPayment (
142+ return safeModuleCall ( 'refundPayment ' , ( ) =>
143+ PlugpagNitroModule . refundPayment (
132144 options . transactionCode ,
133145 options . transactionId ,
134146 options . printReceipt ?? true
@@ -166,7 +178,7 @@ export async function reprintCustomerReceipt(): Promise<void> {
166178export function isTransactionSuccessful (
167179 result : PlugpagTransactionResult
168180) : boolean {
169- return result . result === 0 ; // PlugPag.RET_OK = 0
181+ return result . result === ErrorCode . OK ;
170182}
171183
172184/**
@@ -187,49 +199,61 @@ export function getTransactionError(
187199export const PaymentPresets = {
188200 creditCard : ( amount : number , installments : number = 1 ) => ( {
189201 amount,
190- type : PaymentTypes . CREDIT ,
202+ type : PaymentType . CREDIT ,
191203 installmentType :
192204 installments > 1
193- ? InstallmentTypes . BUYER_INSTALLMENT
194- : InstallmentTypes . NO_INSTALLMENT ,
205+ ? InstallmentType . BUYER_INSTALLMENT
206+ : InstallmentType . NO_INSTALLMENT ,
195207 installments,
196208 } ) ,
197209
198210 debitCard : ( amount : number ) => ( {
199211 amount,
200- type : PaymentTypes . DEBIT ,
201- installmentType : InstallmentTypes . NO_INSTALLMENT ,
212+ type : PaymentType . DEBIT ,
213+ installmentType : InstallmentType . NO_INSTALLMENT ,
202214 installments : 1 ,
203215 } ) ,
204216
205217 pix : ( amount : number ) => ( {
206218 amount,
207- type : PaymentTypes . PIX ,
208- installmentType : InstallmentTypes . NO_INSTALLMENT ,
219+ type : PaymentType . PIX ,
220+ installmentType : InstallmentType . NO_INSTALLMENT ,
209221 installments : 1 ,
210222 } ) ,
211223
212224 voucher : ( amount : number ) => ( {
213225 amount,
214- type : PaymentTypes . VOUCHER ,
215- installmentType : InstallmentTypes . NO_INSTALLMENT ,
226+ type : PaymentType . VOUCHER ,
227+ installmentType : InstallmentType . NO_INSTALLMENT ,
216228 installments : 1 ,
217229 } ) ,
218230} as const ;
219231
220232// Default export
221233export default {
234+ // Core functions
222235 getConstants,
223236 getTerminalSerialNumber,
224237 initializeAndActivatePinPad,
225238 doPayment,
226- voidPayment ,
239+ refundPayment ,
227240 doAbort,
228241 print,
229242 reprintCustomerReceipt,
243+
244+ // Helper functions
230245 isTransactionSuccessful,
231246 getTransactionError,
247+
248+ // Enums (recommended)
249+ PaymentType,
250+ InstallmentType,
251+ ErrorCode,
252+
253+ // Legacy constants (deprecated)
232254 PaymentTypes,
233255 InstallmentTypes,
256+
257+ // Presets
234258 PaymentPresets,
235259} ;
0 commit comments