{
    "swagger": "2.0",
    "info": {
        "description": "Sell digital products easily",
        "version": "1.0.0",
        "title": "Payhip API"
    },
    "host": "payhip.com",
    "basePath": "/api/v1",
    "schemes": [
        "https"
    ],
    "produces": [
        "application/json"
    ],
    "securityDefinitions": {
        "api_key": {
            "type": "apiKey",
            "in": "header",
            "name": "PAYHIP-API-KEY"
        }
    },
    "security": [
        {
            "api_key": []
        }
    ],
    "paths": {
        "/coupons": {
            "get": {
                "tags": [
                    "Coupons"
                ],
                "summary": "Returns all coupons. A single coupon if a coupon_id is supplied",
                "parameters": [
                    {
                        "name": "id",
                        "in": "query",
                        "description": "The unqiue identifier for the coupon.",
                        "required": false,
                        "type": "string"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "An array of coupons",
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#/definitions/Coupon"
                            }
                        }
                    },
                    "default": {
                        "description": "Unexpected error",
                        "schema": {
                            "$ref": "#/definitions/Error"
                        }
                    }
                }
            },
            "post": {
                "tags": [
                    "Coupons"
                ],
                "summary": "Returns all coupons. A single coupon if a coupon_id is supplied",
                "consumes": [
                    "application/x-www-form-urlencoded"
                ],
                "parameters": [
                    {
                        "name": "code",
                        "in": "formData",
                        "description": "The code for the coupon.",
                        "required": true,
                        "type": "string"
                    },
                    {
                        "name": "percentage",
                        "in": "formData",
                        "description": "The percentage discount for the coupon.",
                        "required": true,
                        "type": "string"
                    },
                    {
                        "name": "product_id",
                        "in": "formData",
                        "description": "The product ID if coupon is specific to a product.",
                        "required": false,
                        "type": "string"
                    },
                    {
                        "name": "expiry",
                        "in": "formData",
                        "description": "The expiry of the coupon in a timestamp format.",
                        "required": false,
                        "type": "string"
                    },
                    {
                        "name": "limit",
                        "in": "formData",
                        "description": "The maximum limit for the coupon usage.",
                        "required": false,
                        "type": "string"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "An array of coupons",
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#/definitions/Coupon"
                            }
                        }
                    },
                    "default": {
                        "description": "Unexpected error",
                        "schema": {
                            "$ref": "#/definitions/Error"
                        }
                    }
                }
            },
            "put": {
                "tags": [
                    "Coupons"
                ],
                "summary": "Edit an existing coupon",
                "consumes": [
                    "application/x-www-form-urlencoded"
                ],
                "parameters": [
                    {
                        "name": "id",
                        "in": "query",
                        "description": "The unqiue identifier for the coupon.",
                        "required": true,
                        "type": "string"
                    },
                    {
                        "name": "code",
                        "in": "formData",
                        "description": "The code for the coupon.",
                        "required": false,
                        "type": "string"
                    },
                    {
                        "name": "percentage",
                        "in": "formData",
                        "description": "The percentage discount for the coupon.",
                        "required": false,
                        "type": "string"
                    },
                    {
                        "name": "product_id",
                        "in": "formData",
                        "description": "The product ID if coupon is specific to a product.",
                        "required": false,
                        "type": "string"
                    },
                    {
                        "name": "expiry",
                        "in": "formData",
                        "description": "The expiry of the coupon in a timestamp format.",
                        "required": false,
                        "type": "string"
                    },
                    {
                        "name": "limit",
                        "in": "formData",
                        "description": "The maximum limit for the coupon usage.",
                        "required": false,
                        "type": "string"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "An array of coupons",
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#/definitions/Coupon"
                            }
                        }
                    },
                    "default": {
                        "description": "Unexpected error",
                        "schema": {
                            "$ref": "#/definitions/Error"
                        }
                    }
                }
            },
            "delete": {
                "tags": [
                    "Coupons"
                ],
                "summary": "Deletes a coupon.",
                "parameters": [
                    {
                        "name": "id",
                        "in": "query",
                        "description": "The unqiue identifier for the coupon.",
                        "required": true,
                        "type": "string"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "An array of coupons",
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#/definitions/CouponVerify"
                            }
                        }
                    },
                    "default": {
                        "description": "Unexpected error",
                        "schema": {
                            "$ref": "#/definitions/Error"
                        }
                    }
                }
            }
        },
        "/coupons/verify": {
            "get": {
                "tags": [
                    "Coupons"
                ],
                "summary": "Verifies a coupon.",
                "parameters": [
                    {
                        "name": "code",
                        "in": "query",
                        "description": "The coupon code.",
                        "required": true,
                        "type": "string"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "An array of coupons",
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#/definitions/Coupon"
                            }
                        }
                    },
                    "default": {
                        "description": "Unexpected error",
                        "schema": {
                            "$ref": "#/definitions/Error"
                        }
                    }
                }
            }
        },
        "/coupons/hascoupon": {
            "get": {
                "tags": [
                    "Coupons"
                ],
                "summary": "Checks whether a product has a coupon.",
                "parameters": [
                    {
                        "name": "id",
                        "in": "query",
                        "description": "The product IDs to check for a coupon.",
                        "required": true,
                        "type": "array",
                        "items": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "An array of coupons",
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#/definitions/Coupon"
                            }
                        }
                    },
                    "default": {
                        "description": "Unexpected error",
                        "schema": {
                            "$ref": "#/definitions/Error"
                        }
                    }
                }
            }
        },
        "/language": {
            "get": {
                "tags": [
                    "Language"
                ],
                "summary": "Returns language text",
                "parameters": [
                    {
                        "name": "id",
                        "in": "query",
                        "description": "The unqiue identifier for the language.",
                        "required": false,
                        "type": "string"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "An array of language text",
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#/definitions/Lang"
                            }
                        }
                    },
                    "default": {
                        "description": "Unexpected error",
                        "schema": {
                            "$ref": "#/definitions/Error"
                        }
                    }
                }
            }
        }
    },
    "definitions": {
        "Coupon": {
            "type": "object",
            "properties": {
                "coupon_id": {
                    "type": "string",
                    "description": "A unqiue identifier for a coupon"
                },
                "code": {
                    "type": "string",
                    "description": "The coupon value."
                },
                "percentage": {
                    "type": "string",
                    "description": "The percentage discount."
                },
                "usage": {
                    "type": "string",
                    "description": "The number of times the coupon has been used."
                },
                "product_id": {
                    "type": "string",
                    "description": "The product id the coupon applies to. Null is returned if it applies to all products."
                },
                "product_name": {
                    "type": "string",
                    "description": "The product the coupon applies to. All is returned if it applies to all products."
                },
                "expiry": {
                    "type": "string",
                    "description": "The date of the order."
                },
                "limit": {
                    "type": "number",
                    "description": "The number of times this coupon can be used."
                }
            }
        },
        "CouponVerify": {
            "type": "object",
            "properties": {
                "coupon_id": {
                    "type": "string",
                    "description": "A unqiue identifier for a coupon"
                },
                "code": {
                    "type": "string",
                    "description": "The coupon value"
                },
                "percentage": {
                    "type": "string",
                    "description": "The percentage discount"
                },
                "valid": {
                    "type": "string",
                    "description": "The number of times the coupon has been used"
                },
                "product_id": {
                    "type": "string",
                    "description": "The coupon applies to these product ids"
                },
                "expiry": {
                    "type": "string",
                    "description": "The expiry date of the coupon."
                },
                "limit": {
                    "type": "number",
                    "description": "The number of times this coupon can be used."
                }
            }
        },
        "Cart": {
            "type": "object",
            "properties": {
                "products": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/CartItem"
                    }
                },
                "coupons": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/CouponItem"
                    }
                },
                "address_1": {
                    "description": "The address line one for the transaction.",
                    "type": "string"
                },
                "address_2": {
                    "description": "The address line two for the transaction.",
                    "type": "string"
                },
                "city": {
                    "description": "The city for the transaction.",
                    "type": "string"
                },
                "country": {
                    "description": "The country for the transaction.",
                    "type": "string"
                },
                "postcode": {
                    "description": "The postcode for the transaction.",
                    "type": "string"
                },
                "vat_number": {
                    "description": "The vat number for the transaction.",
                    "type": "string"
                }
            }
        },
        "CouponItem": {
            "type": "object",
            "properties": {
                "code": {
                    "type": "string",
                    "description": "The coupon code."
                }
            }
        },
        "CartItem": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "string",
                    "description": "The id of the product."
                },
                "quantity": {
                    "type": "number",
                    "format": "int32",
                    "description": "The quantity of the product."
                },
                "pwyw": {
                    "type": "boolean",
                    "description": "Whether pay-what-you-want is enabled."
                },
                "original_price": {
                    "type": "number",
                    "format": "int32",
                    "description": "The original price of the product."
                },
                "price": {
                    "type": "number",
                    "format": "int32",
                    "description": "The price of the product."
                }
            }
        },
        "Lang": {
            "type": "object",
            "properties": {
                "l_cart_heading": {
                    "type": "string",
                    "description": "Cart."
                }
            }
        },
        "Error": {
            "type": "object",
            "properties": {
                "code": {
                    "type": "string",
                    "description": "A short error code"
                },
                "message": {
                    "type": "string",
                    "description": "A description of the status or error"
                }
            }
        }
    }
}
