Skip to content

Runtime_CalculateCharges#


Description#

This function allows you to apply a shipping method and/or a payment method to a checkout session. Tax is automatically recalculated when this function runs. If calling this function from a Miva page, there is a helper function with the same name that is part of runtime.js.

Request Body Parameters#

Parameter
Type Description
Session_Type String This will always be “runtime”
Session_ID String The Session ID of the basket
Checkout_Session_ID String Checkout Session ID. This is available once OCST (Bill To/Ship To) has been submitted
PaymentMethod String Optional. Needs to be in the following format: module_code:method_code. Example: ‘authnet:visa’
ShippingMethod String Optional. Needs to be in the following format: module_code:method_code. Example: ‘flatrate:freeship’

Response Parameters#

Parameter
Type Description
success boolean Boolean value for if the request was successful
total Number Basket Total after payment, shipping, tax have been applied
subtotal Number Basket subtotal. Tax is not included in this calculation
formatted_total String Basket Total after payment, shipping, tax have been applied
formatted_subtotal String Basket subtotal. Tax is not included in this calculation
charges Object Object containing the basket charges array (added in Version 10.10.01)

charges Object#

Parameter
Type Description
type String Specifies the type of charge, such as “Shipping”, “Handling”, or “Tax”.
descrip String Provides a short description or label for the charge.
amount Number The raw amount of the charge
disp_amt Number The amount to be displayed to the user, often identical to amount unless modified for display.
tax_exempt Boolean Indicates whether the charge is tax-exempt (true) or taxable (false).
tax Number The tax amount associated with the charge, if applicable.
formatted_amount String The formatted version of amount as a string.
formatted_disp_amt String The formatted version of disp_amt.
formatted_tax String The formatted version of the tax field as a string.

Note

Content-Type for the request must be ‘application/json’

Example Request#

{
    "Store_Code": "{{Store_Code}}",
    "Miva_Request_Timestamp": "{{$timestamp}}",
    "Function": "Runtime_CalculateCharges",
    "Session_Type": "runtime",
    "Checkout_Session_ID": "6c91bb39caaa7aa4866a7f9ddc2edasd",
    "Session_ID": "b4ddb93804b45e1e3c9b22165ddasds",
    "PaymentMethod": "",
    "ShippingMethod": "flatrate:FREESHIP"
}

Example Response#

{
    "success": 1,
    "data": {
        "total": 7.8,
        "subtotal": 7.5,
        "formatted_total": "$7.80",
        "formatted_subtotal": "$7.50",
        "charges":
        [
            {
                "type":               "TAX",
                "descrip":            "Tax",
                "amount":             12.34,
                "disp_amt":           12.34,
                "tax_exempt":         true,
                "tax":                0.00,
                "formatted_amount":   "$12.34",
                "formatted_disp_amt": "$12.34",
                "formatted_tax":      "$0.00"
            }
        ]
    }
}