# Voucher endpoints

# Apply voucher

Add a voucher to the customer' cart.

# Endpoint

POST /cart/voucher.js

# Parameters

Name Required
voucher true

# Examples

Axios request

axios.post('/cart/voucher.js', {
    voucher: 'SALE100'
})
.then((response) => {
    this.$root.cart = response.data
})
.catch(e => {
    console.log(e.response.data)
})

Successful response

{
    "id":1682439003100965,
    "attributes":[],
    "original_total_price":69800,
    "total_discount":10000,
    "total_price":59800,
    "tax_price":11960,
    "tax_rate":2500,
    "total_weight":2264,
    "item_count":2,
    "items":[
        {
            "id": "mRjW0Mz3redAlp961XdQaXnJGN57gxBk",
            "title": "Basic T-shirt - Black",
            "price": 69800,
            "line_price": 34900,
            "quantity": 2,
            "inventory_quantity": null,
            "sku": null,
            "grams": null,
            "vendor": "Your Shop",
            "properties": null,
            "variant_id": 1612407237867184,
            "product_id": 1612407237849627,
            "url": "https:\/\/your-shop.codefort.io\/products\/basic-t-shirt?variant=1612407237867184",
            "image": "https:\/\/files.codefort.com\/your-shop\/images\/products\/1024x1024\/5d35824e372de.jpg",
            "handle": "basic-t-shirt",
            "requires_shipping": true,
            "product_title": "Basic T-shirt",
            "product_description": null,
            "product_type": "T-shirts",
            "variant_title": "Black",
            "variant_options": null,
            "parent_row_id": null,
            "is_recurring": false
        }
    ],
    "requires_shipping": true,
    "has_free_shipping": false,
    "is_recurring": false,
    "voucher_code": "SALE100"
}

Failed response

{
    "message":"The given data was invalid.",
    "errors": {
        "voucher": [
            "The voucher requires a minimum purchase of €50,00",
        ]
    }
}

# Remove voucher

Remove the current applied voucher from the customer' cart.

# Endpoint

DELETE /cart/voucher.js

# Examples

Axios request

axios.delete('/cart/voucher.js')
.then((response) => {
    this.$root.cart = response.data
})
.catch(e => {
    console.log(e.response.data)
})

Successful response

{
    "id":1682439003100965,
    "attributes":[],
    "original_total_price":69800,
    "total_discount":0,
    "total_price":69800,
    "tax_price":11960,
    "tax_rate":2500,
    "total_weight":2264,
    "item_count":2,
    "items":[
        {
            "id": "mRjW0Mz3redAlp961XdQaXnJGN57gxBk",
            "title": "Basic T-shirt - Black",
            "price": 69800,
            "line_price": 34900,
            "quantity": 2,
            "inventory_quantity": null,
            "sku": null,
            "grams": null,
            "vendor": "Your Shop",
            "properties": null,
            "variant_id": 1612407237867184,
            "product_id": 1612407237849627,
            "url": "https:\/\/your-shop.codefort.io\/products\/basic-t-shirt?variant=1612407237867184",
            "image": "https:\/\/files.codefort.com\/your-shop\/images\/products\/1024x1024\/5d35824e372de.jpg",
            "handle": "basic-t-shirt",
            "requires_shipping": true,
            "product_title": "Basic T-shirt",
            "product_description": null,
            "product_type": "T-shirts",
            "variant_title": "Black",
            "variant_options": null,
            "parent_row_id": null,
            "is_recurring": false
        }
    ],
    "requires_shipping": true,
    "has_free_shipping": false,
    "is_recurring": false,
    "voucher_code": ""
}