@@ -3,6 +3,7 @@ import { CartService } from '@cart/services/cart.service'
3
3
import { OrderStatus , TransactionStatus , UserRole } from '@common/contracts/constant'
4
4
import { Errors } from '@common/contracts/error'
5
5
import { AppException } from '@common/exceptions/app.exception'
6
+ import { DiscordService } from '@common/services/discord.service'
6
7
import { CustomerRepository } from '@customer/repositories/customer.repository'
7
8
import { MailerService } from '@nestjs-modules/mailer'
8
9
import { Injectable , Logger , OnModuleInit } from '@nestjs/common'
@@ -39,7 +40,8 @@ export class PayOSPaymentStrategy implements IPaymentStrategy, OnModuleInit {
39
40
private readonly productRepository : ProductRepository ,
40
41
private readonly paymentRepository : PaymentRepository ,
41
42
private readonly customerRepository : CustomerRepository ,
42
- private readonly mailerService : MailerService
43
+ private readonly mailerService : MailerService ,
44
+ private readonly discordService : DiscordService
43
45
) {
44
46
this . config = this . configService . get ( 'payment.payos' )
45
47
this . payOS = new PayOS ( this . config . clientId , this . config . apiKey , this . config . checksumKey )
@@ -264,6 +266,30 @@ export class PayOSPaymentStrategy implements IPaymentStrategy, OnModuleInit {
264
266
}
265
267
} )
266
268
// 10. Send notification to staff
269
+
270
+ // 4. Send notification to staff => Discord Bot
271
+ try {
272
+ this . discordService . sendMessage ( {
273
+ fields : [
274
+ {
275
+ name : 'PayOSPaymentStrategy' ,
276
+ value : 'processWebhookOrder'
277
+ } ,
278
+ {
279
+ name : 'Payment For Order' ,
280
+ value : 'SUCCESS'
281
+ } ,
282
+ {
283
+ name : 'orderId' ,
284
+ value : `${ orderId } `
285
+ } ,
286
+ {
287
+ name : 'Total Amount' ,
288
+ value : `${ order . totalAmount } `
289
+ }
290
+ ]
291
+ } )
292
+ } catch ( err ) { }
267
293
} else {
268
294
// Payment failed
269
295
this . logger . log ( 'processWebhook: payment FAILED' )
@@ -355,7 +381,29 @@ export class PayOSPaymentStrategy implements IPaymentStrategy, OnModuleInit {
355
381
)
356
382
357
383
// 3. Send email/notification to customer
358
- // 4. Send notification to staff
384
+ // 4. Send notification to staff => Discord Bot
385
+ try {
386
+ this . discordService . sendMessage ( {
387
+ fields : [
388
+ {
389
+ name : 'PayOSPaymentStrategy' ,
390
+ value : 'processWebhookAI'
391
+ } ,
392
+ {
393
+ name : 'Payment For AI' ,
394
+ value : 'SUCCESS'
395
+ } ,
396
+ {
397
+ name : 'orderId' ,
398
+ value : `${ orderId } `
399
+ } ,
400
+ {
401
+ name : 'credits' ,
402
+ value : `${ credits } `
403
+ }
404
+ ]
405
+ } )
406
+ } catch ( err ) { }
359
407
} else {
360
408
// Payment failed
361
409
this . logger . log ( 'processWebhook: payment FAILED' )
0 commit comments