Payment Service
ccr-payment-service รับผิดชอบ payment transaction และ integration กับ payment gateway
Capability หลัก
| Capability | รายละเอียด |
|---|---|
| Initiate payment | เริ่ม transaction สำหรับ booking |
| Webhook | รับ callback จาก Omise/payment gateway |
| Payment detail | ดู transaction รายตัวหรือราย booking |
| Payment methods | แสดงวิธีชำระเงินที่รองรับ |
| Subscribe | ติดตาม transaction status แบบ subscription |
| Bank master data | แสดงข้อมูลธนาคารสำหรับ refund/transfer |
Initiate payment rules
| Rule | รายละเอียดจาก PaymentTransactionService |
|---|---|
| Booking must exist | หา booking จาก Payment DB ด้วย BookingId |
| Guest payment | ถ้า CustomerId == Guid.Empty, booking ต้องไม่มี CreatedBy |
| Member payment | booking ต้องมี CreatedBy และต้องตรงกับ CustomerId |
| Expired booking | ถ้า booking status Expired หรือเวลาปัจจุบันถึง/เลย ExpireAt จะ reject |
| Amount | ถ้า latest BookingInfo.AdditionalAmount เป็นค่าบวก ใช้ additional amount; ไม่งั้นใช้ booking.Amount |
| Transaction start | สร้าง transaction status Pending ก่อนเรียก Omise |
Payment method behavior
| Payment method | Flow |
|---|---|
| Non-card เช่น PromptPay/TrueMoney | CreateChargeWithSourceAsync, เก็บ AuthorizeUri, คืน ScannableCodeUri ถ้ามี |
| Credit/Debit with saved method | ใช้ SavedPaymentMethod.CustomerToken สร้าง charge |
| Credit/Debit with new token | สร้าง Omise customer token, charge, และถ้าเป็น member จะ save card |
Webhook behavior
| Omise webhook | ผลลัพธ์ |
|---|---|
key ไม่ใช่ charge.complete | ignore |
data.status = successful | transaction Completed, set PaidAt, booking Confirm, payment status Paid, notify Booking Service ผ่าน gRPC, notify subscriber successful |
data.status = pending | transaction Pending |
| status อื่น | transaction NotCompleted, booking payment status Failed, notify subscriber failed |
gRPC sync กับ Booking Service
| Method | ใช้เมื่อ |
|---|---|
CreateBookingAsync | Booking Service สร้าง booking แล้ว sync shadow booking เข้า Payment DB |
UpdateBookingAsync | Booking edit แล้ว sync amount/version/additional/refund amount |
BookingExpiredAsync | Booking หมดเวลาชำระเงินและ mark pending transactions เป็น Expired |
CancelBookingAsync | Booking ถูก cancel และ mark pending transactions เป็น Cancelled |
NotifyPaymentCompletedAsync | Payment completed แล้วแจ้ง Booking Service ให้ confirm booking |
Database
| DbSet | รายละเอียด |
|---|---|
PaymentTransactions | รายการ transaction |
SavedPaymentMethods | วิธีชำระเงินที่บันทึก (เก็บข้อมูลบัตรเครดิต เช่น LastFourDigits, CardBrand เช่น visa, mastercard, jcb, และ CustomerToken) |
Bookings, BookingInfos | Booking snapshot/reference |
Customers | Customer snapshot/reference |
BankMasterdatas | Master data ธนาคาร |