Create order with service charge taxable in line item

i don’t know how to create a sample order with service charge taxable in line item.

below is request:
{
“idempotency_key”: “{{$guid}}”,
“order”: {
“location_id”: “LF1GYFQK5DCP4”,
“line_items”: [
{
“catalog_object_id”: “G254XOXDZYCYNED7CW3J6SQA”,
“quantity”: “2”,
“name”: “Lychee & Peach Tea Slush(LCHJ 1,T200,L1)芝芝粉荔桃”,
“variation_name”: “”,
“base_price_money”: {
“amount”: 200,
“currency”: “USD”
},
“item_type”: “ITEM”,
“applied_taxes”: [
{
“tax_uid”: “e23972c7-6da5-4905-952a-26a06ac2788a”
}
],
“applied_service_charges”: [
{
“uid”: “serviceCharge”,
“service_charge_uid”: “e23972c7-6da5-4905-952a-26a06ac27666”
}
]
}
],
“taxes”: [
{
“uid”: “e23972c7-6da5-4905-952a-26a06ac2788a”,
“name”: “tax”,
“percentage”:“2”,
“type”: “ADDITIVE”,
“scope”: “LINE_ITEM”
}
],
“service_charges”: [
{
“uid”: “e23972c7-6da5-4905-952a-26a06ac27666”,
“amount_money”: {
“amount”: 20,
“currency”: “USD”
},
“name”: “Fee”,
“calculation_phase”: “SUBTOTAL_PHASE”,
“scope”: “LINE_ITEM”,
“taxable”: false,
“applied_taxes”: [
{
“tax_uid”: “e23972c7-6da5-4905-952a-26a06ac2788a”
}
]
}
],
“pricing_options”: {
“auto_apply_discounts”: false,
“auto_apply_taxes”: false
}
}
}

and response is:
{
“errors”: [
{
“code”: “BAD_REQUEST”,
“detail”: “Unexpected calculation phase SURCHARGE_PHASE for applied service charge custom-surcharge:e23972c7-6da5-4905-952a-26a06ac27666.”,
“category”: “INVALID_REQUEST_ERROR”
}
]
}

could you tell me the reason why it fails,
or give me a correct sample?

:wave: I’m Square Dev AI, here to help answer your question!
Based on the information you’ve provided, the following documentation will help answer your question:

Additional Documentation

Square-Applied Order Taxes
Configure the Order-Ahead Sample Application
Create and Publish Invoices

If this documentation helped you find a solution, please check the box indicating that this reply solves the problem.
Otherwise one of our Developer Advocates will provide additional assistance shortly.

The error message indicates that the calculation phase for the applied service charge is unexpected. In your request, you have set the “calculation_phase” to “SUBTOTAL_PHASE” for the service charge. However, the error message suggests that it should be “SURCHARGE_PHASE”.

Also, the “scope” field in the service charge should be “ORDER” instead of “LINE_ITEM”. The “scope” field in the service charge object determines whether the service charge is applied to the entire order or to individual line items. In your case, since you are applying the service charge at the order level, you should set the “scope” field to “ORDER”.

Here is a corrected version of your request:

{
    "idempotency_key": "{{$guid}}",
    "order": {
        "location_id": "LF1GYFQK5DCP4",
        "line_items": [
            {
                "catalog_object_id": "G254XOXDZYCYNED7CW3J6SQA",
                "quantity": "2",
                "name": "Lychee & Peach Tea Slush(LCHJ 1,T200,L1)芝芝粉荔桃",
                "variation_name": "",
                "base_price_money": {
                    "amount": 200,
                    "currency": "USD"
                },
                "item_type": "ITEM",
                "applied_taxes": [
                    {
                        "tax_uid": "e23972c7-6da5-4905-952a-26a06ac2788a"
                    }
                ]
            }
        ],
        "taxes": [
            {
                "uid": "e23972c7-6da5-4905-952a-26a06ac2788a",
                "name": "tax",
                "percentage":"2",
                "type": "ADDITIVE",
                "scope": "LINE_ITEM"
            }
        ],
        "service_charges": [
            {
                "uid": "e23972c7-6da5-4905-952a-26a06ac27666",
                "amount_money": {
                    "amount": 20,
                    "currency": "USD"
                },
                "name": "Fee",
                "calculation_phase": "SURCHARGE_PHASE",
                "scope": "ORDER",
                "taxable": false,
                "applied_taxes": [
                    {
                        "tax_uid": "e23972c7-6da5-4905-952a-26a06ac2788a"
                    }
                ]
            }
        ],
        "pricing_options": {
            "auto_apply_discounts": false,
            "auto_apply_taxes": false
        }
    }
}

Please replace the placeholders with your actual values and try again.

This answer was reviewed by @Bryan-Square.

copy the sample code in your response, it’s wrong too.

{
“errors”: [
{
“code”: “INVALID_ENUM_VALUE”,
“detail”: “SURCHARGE_PHASE is not a valid enum value for CalculationPhase (line 40, character 38)”,
“field”: “order.service_charges[0].calculation_phase”,
“category”: “INVALID_REQUEST_ERROR”
}
]
}