Skip to content

Order & Payment Types

Order Types and Payment Types are global master data entities used to classify sales orders within the Merq platform. Unlike other master data (Channel, Account, etc.), these entities are not workspace-scoped and are shared across all workspaces.

Key characteristics:

  • Global entities — No workspace_id field, shared across all workspaces
  • Used in sales order creation — Required fields when creating a sales order
  • Read-only for mobile — Mobile app can only read active types via /app/v1/ endpoints
  • CRUD for web admin — Full create, read, update, delete via /office/v1/ endpoints with RBAC
  • Seeded with defaults — 3 order types and 3 payment types seeded on initial deployment
FieldTypeDescriptionConstraints
idintegerPrimary keyAuto-increment
namestringDisplay name (e.g., “Sell In”)VARCHAR(100), NOT NULL
codestringMachine code (e.g., “sell_in”)VARCHAR(50), NOT NULL, UNIQUE
is_activebooleanWhether type is currently activeDEFAULT TRUE
created_attimestampCreation timestampTIMESTAMPTZ
updated_attimestampLast update timestampTIMESTAMPTZ
deleted_attimestampSoft delete timestampTIMESTAMPTZ (nullable)
FieldTypeDescriptionConstraints
idintegerPrimary keyAuto-increment
namestringDisplay name (e.g., “Cash”)VARCHAR(100), NOT NULL
codestringMachine code (e.g., “cash”)VARCHAR(50), NOT NULL, UNIQUE
is_activebooleanWhether type is currently activeDEFAULT TRUE
created_attimestampCreation timestampTIMESTAMPTZ
updated_attimestampLast update timestampTIMESTAMPTZ
deleted_attimestampSoft delete timestampTIMESTAMPTZ (nullable)

Seeded by the sales order migration:

IDNameCodeDescription
1Sell Insell_inInitial stock for new outlet
2ReplenishmentreplenishmentRegular restock order
3Pre Orderpre_orderFuture delivery order
IDNameCodeDescription
1CashcashPayment on delivery
2TransfertransferBank transfer
3CreditcreditCredit terms
MethodEndpointPermissionDescription
GET/app/v1/order-typesAuthenticatedList active types (mobile)
GET/office/v1/order-typesorder_type.view or order_type.manageList all types (web admin)
GET/office/v1/order-types/:idorder_type.view or order_type.manageGet single type (web admin)
POST/office/v1/order-typesorder_type.manage (full)Create new type
PUT/office/v1/order-types/:idorder_type.manage (full)Update type
DELETE/office/v1/order-types/:idorder_type.manage (full)Delete type (soft)
MethodEndpointPermissionDescription
GET/app/v1/payment-typesAuthenticatedList active types (mobile)
GET/office/v1/payment-typespayment_type.view or payment_type.manageList all types (web admin)
GET/office/v1/payment-types/:idpayment_type.view or payment_type.manageGet single type (web admin)
POST/office/v1/payment-typespayment_type.manage (full)Create new type
PUT/office/v1/payment-types/:idpayment_type.manage (full)Update type
DELETE/office/v1/payment-types/:idpayment_type.manage (full)Delete type (soft)

Note: App endpoints return only is_active=true types. Office endpoints return all types.

GET /app/v1/order-types

Response:

{
"data": [
{
"id": 1,
"name": "Sell In",
"code": "sell_in",
"is_active": true
},
{
"id": 2,
"name": "Replenishment",
"code": "replenishment",
"is_active": true
},
{
"id": 3,
"name": "Pre Order",
"code": "pre_order",
"is_active": true
}
],
"message": "order types retrieved",
"code": "ORDER_TYPE_LIST"
}
GET /app/v1/payment-types

Response:

{
"data": [
{
"id": 1,
"name": "Cash",
"code": "cash",
"is_active": true
},
{
"id": 2,
"name": "Transfer",
"code": "transfer",
"is_active": true
},
{
"id": 3,
"name": "Credit",
"code": "credit",
"is_active": true
}
],
"message": "payment types retrieved",
"code": "PAYMENT_TYPE_LIST"
}
POST /office/v1/order-types
Content-Type: application/json
{
"name": "Consignment",
"code": "consignment",
"is_active": true
}

Response:

{
"data": {
"id": 4,
"name": "Consignment",
"code": "consignment",
"is_active": true
},
"message": "order type created",
"code": "ORDER_TYPE_CREATED"
}
PUT /office/v1/payment-types/3
Content-Type: application/json
{
"name": "Credit Card",
"code": "credit_card",
"is_active": true
}

Response:

{
"data": null,
"message": "payment type updated",
"code": "PAYMENT_TYPE_UPDATED"
}
DELETE /office/v1/order-types/4

Response:

{
"data": null,
"message": "order type deleted",
"code": "ORDER_TYPE_DELETED"
}

Order types and payment types are required fields when creating a sales order:

Create Sales Order Request:

{
"outlet_id": 123,
"visit_id": 456,
"order_type_id": 2,
"payment_type_id": 1,
"items": [
{
"product_id": 10,
"quantity": 5,
"unit_price": 50000
}
],
"po_photos": ["photo1.jpg", "photo2.jpg"],
"signature": "signature.jpg"
}

Create Sales Order Response:

{
"data": {
"id": 789,
"order_type": {
"id": 2,
"name": "Replenishment",
"code": "replenishment"
},
"payment_type": {
"id": 1,
"name": "Cash",
"code": "cash"
},
"outlet_id": 123,
"total": 250000,
"status": "pending"
},
"message": "sales order created",
"code": "SALES_ORDER_CREATED"
}

Unlike other master data (Channel, Account, etc.), Order Types and Payment Types are global:

CharacteristicOrder/Payment TypesOther Master Data
Workspace ID❌ No✅ Yes
Scoped queries❌ No✅ Yes
Shared across workspaces✅ Yes❌ No
Customizable per workspace❌ No✅ Yes

Rationale:

  • Order types and payment types are universal business concepts
  • Consistency across workspaces for reporting
  • Simplified mobile app (same options everywhere)
  • Reduced configuration overhead for new workspaces
EntityView PermissionManage Permission
OrderTypeorder_type.vieworder_type.manage
PaymentTypepayment_type.viewpayment_type.manage

Permission constants:

  • PermissionKeyOrderTypeView — View order types (office)
  • PermissionKeyOrderTypeManage — Create, update, delete order types
  • PermissionKeyPaymentTypeView — View payment types (office)
  • PermissionKeyPaymentTypeManage — Create, update, delete payment types

Mobile access:

  • App endpoints (/app/v1/) require only authentication (no RBAC)
  • Read-only access to active types
  • Cannot create, update, or delete types

Office access:

  • List endpoints require order_type.view or payment_type.view (or manage)
  • Mutation endpoints (POST, PUT, DELETE) require *_manage with AccessLevelFull

Both order types and payment types follow the standard handler → service → repository pattern:

internal/handler/order_type_handler.go
internal/handler/payment_type_handler.go

Key implementation notes:

  • GetAll endpoints support pagination via page and limit query params
  • is_active filter applied automatically on app endpoints
  • Soft delete implemented via deleted_at timestamp
  • All office endpoints require authentication + RBAC middleware

Order Type Request:

type orderTypeRequest struct {
Name string `json:"name" binding:"required"`
Code string `json:"code" binding:"required"`
IsActive *bool `json:"is_active"`
}

Payment Type Request:

type paymentTypeRequest struct {
Name string `json:"name" binding:"required"`
Code string `json:"code" binding:"required"`
IsActive *bool `json:"is_active"`
}

Note: is_active defaults to true if not provided in request.