Order Calculation Examples
This guide provides practical examples showing how to structure Order API payloads for common commerce scenarios including discounts, points redemption, and coupons.
Endpoint: POST https://api.gameball.co/api/v4.0/integrations/orders
Headers:
apikey: {your-api-key}
secretkey: {your-secret-key}
Content-Type: application/json
Field Definitions
Understanding how each field is calculated is essential for correct order tracking and points earning.
Line Item Fields
| Field | Definition | Example |
|---|
price | Unit price of a single item (does NOT change with quantity) | If 1 unit = $150, then price: 150 even if qty is 5 |
discount | Total discount applied to this line item (NOT per unit) | If $50 discount on 2 units, then discount: 50 |
taxes | Total tax for this line item after discount (NOT per unit) | If line total after discount = $250 at 15% VAT, then taxes: 37.5 |
Order Level Fields
| Field | Definition | Example |
|---|
totalPrice | Sum of all line items + taxes (before any discounts) | Items = 500, Taxes = 75 → totalPrice: 575 |
totalDiscount | Sum of ALL discounts (line item + order level + points + coupon) | Line discount 50 + Points 100 → totalDiscount: 150 |
totalPaid | What customer actually paid (totalPrice - totalDiscount) | 575 - 150 = totalPaid: 425 |
Points are earned based on totalPaid only.
Line Item Level
lineTotal = quantity × price
lineItemTax = (lineTotal - lineItemDiscount) × taxRate
Order Level
totalPrice = Σ(quantity × price) + Σ(taxes)
totalDiscount = Σ(lineItem.discount) + orderLevelDiscount + pointsRedeemed + couponDiscount
totalPaid = totalPrice - totalDiscount
Line Item Attributes Reference
| Attribute | Type | Description |
|---|
productId | string | Unique product identifier |
sku | string | Stock keeping unit |
title | string | Product name |
quantity | number | Number of units |
price | number | Unit price |
discount | number | Total discount on this line item |
taxes | number | Total tax on this line item |
weight | number | Product weight |
vendor | string | Vendor/supplier name |
category | array | Product categories |
tags | array | Product tags |
collection | array | Product collections |
extra | object | Custom attributes (division, department, etc.) |
Example 1: Basic Order with Line Items
Scenario: Customer purchases items with no discounts applied.
| Component | Calculation | Value |
|---|
| Vitamin C (2 × $150) | | $300 |
| Face Moisturizer (1 × $200) | | $200 |
| Subtotal | | $500 |
| Vitamin C Tax | $300 × 15% | $45 |
| Face Moisturizer Tax | $200 × 15% | $30 |
| Total Tax | | $75 |
| totalPrice | 500 + 75 | $575 |
| totalDiscount | | $0 |
| totalPaid | 575 - 0 | $575 |
{
"customerId": "+11234567890",
"mobile": "+11234567890",
"orderId": "INV-2026-001234",
"orderDate": "2026-03-25T14:30:00Z",
"totalPrice": 575,
"totalDiscount": 0,
"totalPaid": 575,
"channel": "pos",
"lineItems": [
{
"productId": "PROD-12345",
"sku": "SKU-VIT-C-1000",
"title": "Vitamin C 1000mg",
"quantity": 2,
"price": 150,
"discount": 0,
"taxes": 45,
"weight": 0.1,
"vendor": "Nature's Best",
"category": ["Vitamins", "Supplements"],
"tags": ["immunity", "antioxidant", "daily-health"],
"collection": ["Best Sellers", "Health Essentials"],
"extra": {
"division": "Personal Care",
"department": "Vitamins & Supplements",
"categoryGroup": "Vitamins",
"merchandiseCategory": "Vitamin C"
}
},
{
"productId": "PROD-67890",
"sku": "SKU-MOIST-50ML",
"title": "Face Moisturizer 50ml",
"quantity": 1,
"price": 200,
"discount": 0,
"taxes": 30,
"weight": 0.15,
"vendor": "CeraVe",
"category": ["Skin Care", "Face Care"],
"tags": ["moisturizer", "hydration", "daily-care"],
"collection": ["Skin Care Essentials"],
"extra": {
"division": "Skin Care",
"department": "Face Care",
"categoryGroup": "Moisturizers",
"merchandiseCategory": "Face Moisturizer"
}
}
],
"merchant": {
"uniqueId": "merchant-001",
"name": "Your Store"
},
"branch": {
"uniqueId": "branch-001",
"name": "Main Branch"
}
}
The examples below show only the fields that change from Example 1. All other fields (lineItems, merchant, branch) remain the same unless specified.
Example 2: Order with Line Item Discount
Scenario: A specific item has a discount (e.g., item on sale). Tax is calculated on the discounted amount.
| Component | Calculation | Value |
|---|
| Vitamin C (2 × $150) | | $300 |
| Face Moisturizer (1 × $200) | | $200 |
| Subtotal | | $500 |
| Vitamin C Discount | | $50 |
| Vitamin C Tax | (300−50) × 15% | $37.50 |
| Face Moisturizer Tax | $200 × 15% | $30 |
| Total Tax | | $67.50 |
| totalPrice | 500 + 67.50 | $567.50 |
| totalDiscount | | $50 |
| totalPaid | 567.50 - 50 | $517.50 |
{
"orderId": "INV-2026-001235",
"totalPrice": 567.5,
"totalDiscount": 50,
"totalPaid": 517.5,
"lineItems": [
{
"productId": "PROD-12345",
"quantity": 2,
"price": 150,
"discount": 50,
"taxes": 37.5
},
{
"productId": "PROD-67890",
"quantity": 1,
"price": 200,
"discount": 0,
"taxes": 30
}
]
}
Example 3: Order with Order-Level Discount
Scenario: A commercial discount is applied to the entire order (not distributed to line items).
| Component | Calculation | Value |
|---|
| Vitamin C (2 × $150) | | $300 |
| Face Moisturizer (1 × $200) | | $200 |
| Subtotal | | $500 |
| Vitamin C Tax | $300 × 15% | $45 |
| Face Moisturizer Tax | $200 × 15% | $30 |
| Total Tax | | $75 |
| totalPrice | 500 + 75 | $575 |
| Order-Level Discount | 15% off | $75 |
| totalDiscount | | $75 |
| totalPaid | 575 - 75 | $500 |
{
"orderId": "INV-2026-001236",
"totalPrice": 575,
"totalDiscount": 75,
"totalPaid": 500
}
Line items have discount: 0. The 75 discount is at the order level only (totalDiscount).
Example 4: Order with Points Redemption
Scenario: Customer redeems points to pay part of the order.
| Component | Calculation | Value |
|---|
| Vitamin C (2 × $150) | | $300 |
| Face Moisturizer (1 × $200) | | $200 |
| Subtotal | | $500 |
| Vitamin C Tax | $300 × 15% | $45 |
| Face Moisturizer Tax | $200 × 15% | $30 |
| Total Tax | | $75 |
| totalPrice | 500 + 75 | $575 |
| Points Redeemed | | $100 |
| totalDiscount | | $100 |
| totalPaid | 575 - 100 | $475 |
Step 1: Hold Points (before order)
POST /api/v4.0/integrations/transactions/hold
Response returns holdReference: "HOLD-ABC123"
Step 2: Complete Order with holdReference
{
"orderId": "INV-2026-001237",
"totalPrice": 575,
"totalDiscount": 100,
"totalPaid": 475,
"redemption": {
"pointsHoldReference": "HOLD-ABC123"
}
}
Points redeemed value (100) is included in totalDiscount. Customer earns points only on totalPaid (475).
Example 5: Order with Coupon
Scenario: Customer applies a coupon code.
| Component | Calculation | Value |
|---|
| Vitamin C (2 × $150) | | $300 |
| Face Moisturizer (1 × $200) | | $200 |
| Subtotal | | $500 |
| Vitamin C Tax | $300 × 15% | $45 |
| Face Moisturizer Tax | $200 × 15% | $30 |
| Total Tax | | $75 |
| totalPrice | 500 + 75 | $575 |
| Coupon Discount | | $50 |
| totalDiscount | | $50 |
| totalPaid | 575 - 50 | $525 |
Step 1: Lock Coupon (before order)
POST /api/v4.0/integrations/coupons/lock
Response returns lockReference: "LOCK-XYZ789"
Step 2: Complete Order with lockReference
{
"orderId": "INV-2026-001238",
"totalPrice": 575,
"totalDiscount": 50,
"totalPaid": 525,
"redemption": {
"couponsLockReference": "LOCK-XYZ789",
"couponCodes": ["SUMMER50"]
}
}
Example 6: Mixed - Points + Discount + Coupon
Scenario: Customer has commercial discount, redeems points, AND uses a coupon.
| Component | Calculation | Value |
|---|
| Vitamin C (2 × $150) | | $300 |
| Face Moisturizer (1 × $200) | | $200 |
| Subtotal | | $500 |
| Vitamin C Tax | $300 × 15% | $45 |
| Face Moisturizer Tax | $200 × 15% | $30 |
| Total Tax | | $75 |
| totalPrice | 500 + 75 | $575 |
| Commercial Discount | | $25 |
| Points Redeemed | | $50 |
| Coupon Discount | | $25 |
| totalDiscount | 25 + 50 + 25 | $100 |
| totalPaid | 575 - 100 | $475 |
{
"orderId": "INV-2026-001239",
"totalPrice": 575,
"totalDiscount": 100,
"totalPaid": 475,
"redemption": {
"pointsHoldReference": "HOLD-ABC123",
"couponsLockReference": "LOCK-XYZ789",
"couponCodes": ["LOYALTY25"]
}
}
Key Points:
- All discounts (commercial + points + coupon) are summed in
totalDiscount
- Gameball only uses
totalPaid for earning points
- The
pointsHoldReference links the points redemption
- The
couponsLockReference links the coupon burn
Example 7: Order Level Discount + Points Redemption
Scenario: Customer has a commercial discount on the order AND redeems points (no coupon).
| Component | Calculation | Value |
|---|
| Vitamin C (2 × $150) | | $300 |
| Face Moisturizer (1 × $200) | | $200 |
| Subtotal | | $500 |
| Vitamin C Tax | $300 × 15% | $45 |
| Face Moisturizer Tax | $200 × 15% | $30 |
| Total Tax | | $75 |
| totalPrice | 500 + 75 | $575 |
| Commercial Discount | | $50 |
| Points Redeemed | | $75 |
| totalDiscount | 50 + 75 | $125 |
| totalPaid | 575 - 125 | $450 |
{
"orderId": "INV-2026-001240",
"totalPrice": 575,
"totalDiscount": 125,
"totalPaid": 450,
"redemption": {
"pointsHoldReference": "HOLD-DEF456"
}
}
Key Points:
- Commercial discount (50) + Points redeemed (75) = Total Discount (125)
- Only
pointsHoldReference in redemption object (no coupon)
- Customer earns points on
totalPaid (450)
Summary Table
| Example | Scenario | Subtotal | Tax | totalPrice | totalDiscount | totalPaid | Points Earned On |
|---|
| 1 | Basic Order | $500 | $75 | $575 | $0 | $575 | $575 |
| 2 | Line Item Discount | $500 | $67.50 | $567.50 | $50 | $517.50 | $517.50 |
| 3 | Order Level Discount | $500 | $75 | $575 | $75 | $500 | $500 |
| 4 | Points Redemption | $500 | $75 | $575 | $100 | $475 | $475 |
| 5 | Coupon | $500 | $75 | $575 | $50 | $525 | $525 |
| 6 | Mixed (All) | $500 | $75 | $575 | $100 | $475 | $475 |
| 7 | Order Discount + Points | $500 | $75 | $575 | $125 | $450 | $450 |
Key Takeaway
Points are calculated based on totalPaid only.Gameball doesn’t need to know the breakdown of discounts. Just send:
totalPrice (items + taxes, before discounts)
totalDiscount (sum of ALL discounts)
totalPaid (what customer actually paid)