@@ -4,38 +4,38 @@ export default defineEventHandler(async (event) => {
4
4
try {
5
5
const body = await readBody ( event )
6
6
7
- logger . log ( '[PayOS Webhook] Received webhook data:' , body )
7
+ console . log ( '[PayOS Webhook] Received webhook data:' , body )
8
8
9
9
const webhookData = getPayOSAdmin ( ) . verifyPaymentWebhookData ( body )
10
10
11
11
if ( ! webhookData ) {
12
- logger . error ( '[PayOS Webhook] Invalid webhook data received:' , body )
12
+ console . error ( '[PayOS Webhook] Invalid webhook data received:' , body )
13
13
throw createError ( {
14
14
statusCode : 400 ,
15
15
message : ErrorMessage . INVALID_WEBHOOK_BODY ,
16
16
data : body ,
17
17
} )
18
18
}
19
19
20
- logger . log ( '[PayOS Webhook] Verified webhook data:' , webhookData )
20
+ console . log ( '[PayOS Webhook] Verified webhook data:' , webhookData )
21
21
const transactionStatus = webhookData . code === '00' ? PaymentStatus . RESOLVED : PaymentStatus . FAILED
22
22
23
23
const { updatePaymentStatus, updateProviderTransactionStatus, getProviderTransactionByOrderCode } = usePayment ( )
24
24
25
25
const paymentTransactionOfProvider = await getProviderTransactionByOrderCode ( String ( webhookData . orderCode ) )
26
26
27
27
if ( ! paymentTransactionOfProvider ?. payment . order . package ) {
28
- logger . warn ( `[PayOS Webhook] Transaction not found or invalid: orderCode=${ webhookData . orderCode } ` )
28
+ console . warn ( `[PayOS Webhook] Transaction not found or invalid: orderCode=${ webhookData . orderCode } ` )
29
29
return { success : true }
30
30
}
31
31
32
- logger . log ( `[PayOS Webhook] Processing transaction: orderCode=${ webhookData . orderCode } , status=${ transactionStatus } ` )
32
+ console . log ( `[PayOS Webhook] Processing transaction: orderCode=${ webhookData . orderCode } , status=${ transactionStatus } ` )
33
33
34
34
const priceDiscount = Number ( paymentTransactionOfProvider . payment . order . package . price_discount )
35
35
const price = Number ( paymentTransactionOfProvider . payment . order . package . price )
36
36
37
37
if ( priceDiscount !== Number ( webhookData . amount ) && price !== Number ( webhookData . amount ) ) {
38
- logger . error ( `[PayOS Webhook] Amount mismatch, transaction [${ paymentTransactionOfProvider . id } ]: expected=${ price } , received=${ webhookData . amount } ` )
38
+ console . error ( `[PayOS Webhook] Amount mismatch, transaction [${ paymentTransactionOfProvider . id } ]: expected=${ price } , received=${ webhookData . amount } ` )
39
39
40
40
throw createError ( {
41
41
statusCode : 400 ,
@@ -48,33 +48,33 @@ export default defineEventHandler(async (event) => {
48
48
49
49
// The userId is already the UUID from our database since we've updated
50
50
// our schemas to use UUID references between tables
51
- logger . log ( `[PayOS Webhook] Adding credits: userId=${ userId } , amount=${ creditAmount } ` )
51
+ console . log ( `[PayOS Webhook] Adding credits: userId=${ userId } , amount=${ creditAmount } ` )
52
52
53
53
await addCreditToUser ( userId , creditAmount )
54
54
55
- logger . log ( `[PayOS Webhook] Credits added successfully: userId=${ userId } , amount=${ creditAmount } ` )
55
+ console . log ( `[PayOS Webhook] Credits added successfully: userId=${ userId } , amount=${ creditAmount } ` )
56
56
57
57
if ( ! paymentTransactionOfProvider ?. payment . order . package ) {
58
- logger . error ( `[PayOS Webhook] No product found for transaction: ${ webhookData . orderCode } ` )
58
+ console . error ( `[PayOS Webhook] No product found for transaction: ${ webhookData . orderCode } ` )
59
59
throw createError ( {
60
60
statusCode : 400 ,
61
61
message : 'No product found for this transaction!' ,
62
62
} )
63
63
}
64
64
65
- logger . log ( `[PayOS Webhook] Updating transaction ${ paymentTransactionOfProvider . id } to status: ${ transactionStatus } ` )
65
+ console . log ( `[PayOS Webhook] Updating transaction ${ paymentTransactionOfProvider . id } to status: ${ transactionStatus } ` )
66
66
67
67
await updateProviderTransactionStatus ( paymentTransactionOfProvider . id , transactionStatus , webhookData . transactionDateTime )
68
68
69
69
await updatePaymentStatus ( paymentTransactionOfProvider . payment . id , transactionStatus )
70
70
71
- logger . log ( `[PayOS Webhook] Transaction updated successfully: id=${ paymentTransactionOfProvider . id } , status=${ transactionStatus } ` )
71
+ console . log ( `[PayOS Webhook] Transaction updated successfully: id=${ paymentTransactionOfProvider . id } , status=${ transactionStatus } ` )
72
72
73
- logger . log ( '[PayOS Webhook] Webhook processing completed successfully' )
73
+ console . log ( '[PayOS Webhook] Webhook processing completed successfully' )
74
74
return { success : true }
75
75
}
76
76
catch ( error : any ) {
77
- logger . error ( '[PayOS Webhook] Error processing webhook:' , error )
77
+ console . error ( '[PayOS Webhook] Error processing webhook:' , error )
78
78
79
79
throw parseError ( error )
80
80
}
0 commit comments