Skip to main content

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 paymentbooking ต้องมี 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 methodFlow
Non-card เช่น PromptPay/TrueMoneyCreateChargeWithSourceAsync, เก็บ 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.completeignore
data.status = successfultransaction Completed, set PaidAt, booking Confirm, payment status Paid, notify Booking Service ผ่าน gRPC, notify subscriber successful
data.status = pendingtransaction Pending
status อื่นtransaction NotCompleted, booking payment status Failed, notify subscriber failed

gRPC sync กับ Booking Service​

Methodใช้เมื่อ
CreateBookingAsyncBooking Service สร้าง booking แล้ว sync shadow booking เข้า Payment DB
UpdateBookingAsyncBooking edit แล้ว sync amount/version/additional/refund amount
BookingExpiredAsyncBooking หมดเวลาชำระเงินและ mark pending transactions เป็น Expired
CancelBookingAsyncBooking ถูก cancel และ mark pending transactions เป็น Cancelled
NotifyPaymentCompletedAsyncPayment completed แล้วแจ้ง Booking Service ให้ confirm booking

Database​

DbSetรายละเอียด
PaymentTransactionsรายการ transaction
SavedPaymentMethodsวิธีชำระเงินที่บันทึก (เก็บข้อมูลบัตรเครดิต เช่น LastFourDigits, CardBrand เช่น visa, mastercard, jcb, และ CustomerToken)
Bookings, BookingInfosBooking snapshot/reference
CustomersCustomer snapshot/reference
BankMasterdatasMaster data ธนาคาร