IF user.tier == "Regular" THEN IF payment_method == "COD" THEN min_amount = 100000 ELSE min_amount = 50000 END IFELSE IF user.tier == "Silver" THEN min_amount = 25000ELSE IF user.tier IN ["Gold", "Platinum"] THEN min_amount = 0 // No minimumEND IFIF order.subtotal < min_amount THEN RETURN ERROR "Minimum order amount not met"END IF
FUNCTION CreateOrder(order): BEGIN TRANSACTION FOR EACH item IN order.items: product = GET Product WHERE id = item.product_id // Check available stock available_stock = product.stock - product.reserved_stock IF available_stock < item.quantity THEN ROLLBACK TRANSACTION RETURN ERROR "Insufficient stock for " + product.name END IF // Reserve stock product.reserved_stock += item.quantity UPDATE product END FOR // Create order with status "pending" order.status = "pending" order.reservation_expires_at = NOW() + 30 MINUTES INSERT order // Schedule auto-cancel job SCHEDULE_JOB(CancelExpiredOrder, order.id, 30 MINUTES) COMMIT TRANSACTION RETURN orderEND FUNCTIONFUNCTION ConfirmPayment(order_id): BEGIN TRANSACTION order = GET Order WHERE id = order_id IF order.status != "pending" THEN ROLLBACK TRANSACTION RETURN ERROR "Order cannot be confirmed" END IF FOR EACH item IN order.items: product = GET Product WHERE id = item.product_id // Move from reserved to sold product.reserved_stock -= item.quantity product.stock -= item.quantity UPDATE product END FOR order.status = "paid" order.paid_at = NOW() UPDATE order COMMIT TRANSACTION RETURN orderEND FUNCTIONFUNCTION CancelExpiredOrder(order_id): BEGIN TRANSACTION order = GET Order WHERE id = order_id IF order.status == "pending" AND NOW() > order.reservation_expires_at THEN // Release reserved stock FOR EACH item IN order.items: product = GET Product WHERE id = item.product_id product.reserved_stock -= item.quantity UPDATE product END FOR order.status = "cancelled" order.cancel_reason = "Payment timeout" order.cancelled_at = NOW() UPDATE order END IF COMMIT TRANSACTIONEND FUNCTION
discount: Total discount dari coupon dan membership
tax: Pajak (PPN 11%)
shipping_cost: Biaya pengiriman
Constraints:
subtotal >= 0
discount <= subtotal
tax_rate = 0.11 (11% PPN)
total >= 0
Examples:
Example 1: Regular order Items: - Product A: 2 x Rp 50,000 = Rp 100,000 - Product B: 1 x Rp 75,000 = Rp 75,000 subtotal = Rp 175,000 discount = Rp 0 (no coupon) tax = Rp 175,000 * 0.11 = Rp 19,250 shipping_cost = Rp 15,000 total = Rp 175,000 - Rp 0 + Rp 19,250 + Rp 15,000 total = Rp 209,250
Example 2: With coupon Items: - Product A: 3 x Rp 100,000 = Rp 300,000 subtotal = Rp 300,000 coupon = 10% discount = Rp 30,000 member_discount = Rp 0 discount = Rp 30,000 tax = (Rp 300,000 - Rp 30,000) * 0.11 = Rp 29,700 shipping_cost = Rp 0 (free shipping) total = Rp 300,000 - Rp 30,000 + Rp 29,700 + Rp 0 total = Rp 299,700
Template Usage: Copy template yang sesuai dan isi dengan business logic spesifik untuk fitur Anda. Pastikan semua rules, validations, dan calculations terdokumentasi dengan jelas dan disertai contoh.
Pro Tip: Dokumentasikan business logic sebelum implementasi untuk memastikan semua stakeholder aligned dengan requirements!