{
  "openapi": "3.0.4",
  "info": {
    "title": "SmartPay REST API",
    "description": "REST API for working with RTO Contracts",
    "contact": {
      "email": "aaron@smartpayrentals.com"
    },
    "version": "0.0.1"
  },
  "servers": [
    {
      "url": "https://dev-84759587.smartpayrentals.com/cal_api"
    }
  ],
  "security": [
    {
      "api_key": []
    }
  ],
  "tags": [
    {
      "name": "Products"
    },
    {
      "name": "Calculator"
    },
    {
      "name": "Contracts"
    }
  ],
  "paths": {
    "/products": {
      "get": {
        "tags": [
          "Products"
        ],
        "summary": "returns a list of product types",
        "responses": {
          "200": {
            "description": "list of products",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Product"
                  }
                }
              }
            }
          },
          "403": {
            "$ref": "#/components/responses/UnauthorizedError"
          }
        }
      }
    },
    "/calculator/length_options": {
      "get": {
        "tags": [
          "Calculator"
        ],
        "summary": "return list of contract length options for a given state and product type",
        "parameters": [
          {
            "name": "state",
            "in": "query",
            "description": "Two Letter State Abbreviations",
            "required": true,
            "schema": {
              "maxLength": 2,
              "minLength": 2,
              "type": "string"
            }
          },
          {
            "name": "product",
            "in": "query",
            "description": "product type key",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "list of contract options",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/contract_option"
                  }
                }
              }
            }
          },
          "403": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "422": {
            "description": "Query String missing required fields"
          }
        }
      }
    },
    "/calculator/price": {
      "post": {
        "tags": [
          "Calculator"
        ],
        "summary": "Get Estimated Monthly payment, Upfront funds, etc",
        "requestBody": {
          "description": "Object",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/calculator"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Pricing Data",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/contract_pricing"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/JsonError"
          },
          "403": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "422": {
            "$ref": "#/components/responses/MissingFields"
          }
        },
        "x-codegen-request-body-name": "body"
      }
    },
    "/contract/new": {
      "post": {
        "tags": [
          "Contracts"
        ],
        "summary": "Create a new contract",
        "requestBody": {
          "description": "Object",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Contract"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Successful Contract Creation",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "contract_id": {
                      "type": "string",
                      "format": "uuid",
                      "example": "edd21720-e839-457b-aac4-2cdeaa50ed9a"
                    },
                    "contract_data": {
                      "type": "object",
                      "properties": {
                        "contract_length": {
                          "type": "integer",
                          "example": 36
                        },
                        "monthly_rent_payment": {
                          "type": "number",
                          "example": 44.68
                        },
                        "monthly_rent_payment_with_tax": {
                          "type": "number",
                          "example": 47.36
                        },
                        "ldw": {
                          "type": "number",
                          "example": 7.95
                        },
                        "ldw_with_tax": {
                          "type": "number",
                          "example": 8.43
                        },
                        "total_monthly_payment": {
                          "type": "number",
                          "example": 52.63
                        },
                        "total_monthly_payment_with_tax": {
                          "type": "number",
                          "example": 55.79
                        },
                        "security_deposit": {
                          "type": "number",
                          "example": 44.68
                        },
                        "security_deposit_with_tax": {
                          "type": "number",
                          "example": 47.36
                        },
                        "delivery_fee": {
                          "type": "number",
                          "example": 100
                        },
                        "cra": {
                          "type": "number",
                          "example": 130.39
                        },
                        "cra_with_tax": {
                          "type": "number",
                          "example": 138.21
                        },
                        "upfront_payment": {
                          "type": "number",
                          "example": 283.02
                        },
                        "upfront_payment_with_tax": {
                          "type": "number",
                          "description": "Total Upfront payment including tax",
                          "example": 300
                        },
                        "override_code_required": {
                          "type": "boolean",
                          "description": "If the structure is above the limit, an override code is required to submit the contract.  The dealer can call into the office for a code.",
                          "example": false
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/JsonError"
          },
          "403": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "422": {
            "$ref": "#/components/responses/MissingFields"
          }
        },
        "x-codegen-request-body-name": "body"
      }
    },
    "/contract/{contract_id}/signature_link": {
      "post": {
        "tags": [
          "Contracts"
        ],
        "summary": "Send a signature link for a contract",
        "parameters": [
          {
            "name": "contract_id",
            "in": "path",
            "description": "contract id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "phone_number": {
                    "type": "string",
                    "format": "XXXXXXXXXX",
                    "example": "5555555555"
                  },
                  "email": {
                    "type": "string",
                    "format": "email",
                    "example": "email@example.com"
                  }
                }
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Success Confirmation",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "result": {
                      "type": "boolean",
                      "example": true
                    }
                  }
                }
              }
            }
          },
          "403": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "422": {
            "$ref": "#/components/responses/MissingFields"
          }
        },
        "x-codegen-request-body-name": "body"
      }
    },
    "/contract/{contract_id}/edit": {
      "post": {
        "tags": [
          "Contracts"
        ],
        "summary": "Edit a contract",
        "parameters": [
          {
            "name": "contract_id",
            "in": "path",
            "description": "contract id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "description": "Object",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Contract"
              }
            }
          },
          "required": false
        },
        "responses": {
          "200": {
            "description": "Successful Contract Edit",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "contract_id": {
                      "type": "string",
                      "format": "uuid",
                      "example": "edd21720-e839-457b-aac4-2cdeaa50ed9a"
                    },
                    "contract_data": {
                      "type": "object",
                      "properties": {
                        "contract_length": {
                          "type": "integer",
                          "example": 36
                        },
                        "monthly_rent_payment": {
                          "type": "number",
                          "example": 44.68
                        },
                        "monthly_rent_payment_with_tax": {
                          "type": "number",
                          "example": 47.36
                        },
                        "ldw": {
                          "type": "number",
                          "example": 7.95
                        },
                        "ldw_with_tax": {
                          "type": "number",
                          "example": 8.43
                        },
                        "total_monthly_payment": {
                          "type": "number",
                          "example": 52.63
                        },
                        "total_monthly_payment_with_tax": {
                          "type": "number",
                          "example": 55.79
                        },
                        "security_deposit": {
                          "type": "number",
                          "example": 44.68
                        },
                        "security_deposit_with_tax": {
                          "type": "number",
                          "example": 47.36
                        },
                        "delivery_fee": {
                          "type": "number",
                          "example": 100
                        },
                        "cra": {
                          "type": "number",
                          "example": 130.39
                        },
                        "cra_with_tax": {
                          "type": "number",
                          "example": 138.21
                        },
                        "upfront_payment": {
                          "type": "number",
                          "example": 283.02
                        },
                        "upfront_payment_with_tax": {
                          "type": "number",
                          "description": "Total Upfront payment including tax",
                          "example": 300
                        },
                        "override_code_required": {
                          "type": "boolean",
                          "description": "If the structure is above the limit, an override code is required to submit the contract.  The dealer can call into the office for a code.",
                          "example": false
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/JsonError"
          },
          "403": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "422": {
            "description": "Contract not found"
          }
        },
        "x-codegen-request-body-name": "body"
      }
    },
    "/contract/{contract_id}/status": {
      "get": {
        "tags": [
          "Contracts"
        ],
        "summary": "Returns contract status information",
        "parameters": [
          {
            "name": "contract_id",
            "in": "path",
            "description": "contract id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Contract status",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "enum": [
                        "Submitted",
                        "Signed",
                        "Awaiting Invoice",
                        "Processing Invoice",
                        "Complete",
                        "Cancelled"
                      ],
                      "example": "Submitted",
                      "description": " Submitted: The contract was submitted by the dealer<br> Signed: The contract has been signed by the customer<br> Awaiting Invoice: The dealer has indicated the structure was delivered, but has not provided SmartPay with an invoice yet<br> Processing Invoice: The dealer has provided SmartPay with an invoice, but the invoice has not been processed yet<br> Complete: The invoice has been processed and paid to the Dealer<br> Cancelled: The contract has been cancelled  "
                    },
                    "signature_status": {
                      "type": "string",
                      "enum": [
                        "signed",
                        "not signed"
                      ],
                      "example": "signed"
                    },
                    "invoice_status": {
                      "type": "string",
                      "enum": [
                        "not received",
                        "under review",
                        "accepted"
                      ],
                      "example": "under review"
                    },
                    "contract_signed": {
                      "type": "boolean",
                      "description": "If the contract has a valid signature",
                      "example": true
                    },
                    "invoice_received": {
                      "type": "boolean",
                      "description": "If we have received an invoice signifying that the structure has been delivered",
                      "example": true
                    },
                    "contract_cancelled": {
                      "type": "boolean",
                      "description": "If the contract has been cancelled",
                      "example": false
                    },
                    "contract_editable": {
                      "type": "boolean",
                      "description": "If the contract can be edited by the dealer",
                      "example": true
                    }
                  }
                }
              }
            }
          },
          "403": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "422": {
            "description": "Contract not found"
          }
        }
      }
    },
    "/contract/{contract_id}/cancel": {
      "post": {
        "tags": [
          "Contracts"
        ],
        "summary": "Cancels the contract",
        "parameters": [
          {
            "name": "contract_id",
            "in": "path",
            "description": "contract id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    }
                  }
                }
              }
            }
          },
          "403": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "422": {
            "description": "Contract not found, or already cancelled"
          }
        }
      }
    },
    "/contract/{contract_id}/files": {
      "get": {
        "tags": [
          "Contracts"
        ],
        "summary": "Get a list of files available for the contract",
        "parameters": [
          {
            "name": "contract_id",
            "in": "path",
            "description": "contract id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "string",
                        "format": "uuid",
                        "example": "ed22d3b8-9c57-414c-836e-9ae50e4e4901"
                      },
                      "file_name": {
                        "type": "string",
                        "example": "contract.pdf"
                      },
                      "type": {
                        "type": "string",
                        "enum": [
                          "Contract Document",
                          "Signed Contract Document",
                          "Customer Signature",
                          "Driver License",
                          "Dealer Invoice",
                          "Dealer File Uploads",
                          "Other"
                        ],
                        "example": "Contract Document"
                      },
                      "mime_type": {
                        "type": "string",
                        "example": "application/pdf"
                      }
                    }
                  }
                }
              }
            }
          },
          "403": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "422": {
            "description": "Contract not found"
          }
        }
      }
    },
    "/contract/{contract_id}/file/{file_id}": {
      "get": {
        "tags": [
          "Contracts"
        ],
        "summary": "Get a file",
        "parameters": [
          {
            "name": "contract_id",
            "in": "path",
            "description": "contract id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "file_id",
            "in": "path",
            "description": "file id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Requested File Contents",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "image/*": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "403": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "422": {
            "description": "Contract or File not found"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Product": {
        "required": [
          "key",
          "name"
        ],
        "type": "object",
        "properties": {
          "key": {
            "type": "string",
            "example": "shed"
          },
          "name": {
            "type": "string",
            "example": "Shed - in stock"
          }
        }
      },
      "contract_option": {
        "required": [
          "length",
          "name"
        ],
        "type": "object",
        "properties": {
          "length": {
            "type": "integer",
            "example": 36
          },
          "name": {
            "type": "string",
            "example": "36 Month Lease Contract"
          },
          "delivery_fee": {
            "type": "boolean",
            "description": "If a delivery fee can be added for this term option",
            "example": true
          },
          "cra": {
            "type": "boolean",
            "description": "If CRA (Customer Reserve Account) is available for this term option.",
            "example": true
          },
          "ldw": {
            "type": "boolean",
            "description": "If LDW (Liability Damage Waiver) is available for this term option",
            "example": true
          }
        }
      },
      "calculator": {
        "required": [
          "address",
          "width",
          "length",
          "product",
          "structure_cost"
        ],
        "type": "object",
        "properties": {
          "product": {
            "type": "string",
            "example": "shed"
          },
          "width": {
            "type": "integer",
            "example": 10
          },
          "length": {
            "type": "integer",
            "example": 12
          },
          "structure_cost": {
            "type": "number",
            "example": 1100
          },
          "delivery_fee": {
            "type": "number",
            "example": 100
          },
          "increased_total_due": {
            "type": "number",
            "description": "If the customer wants to put additional money upfront to reduce their monthly payments, put the total amount they want to put down upfront (including all taxes) here.  If this number is lower than they default upfront funds amount, this will be ignored.  Or if CRA is not available for the requested state/term, if will be ignored.",
            "example": 300
          },
          "ldw": {
            "type": "boolean",
            "example": true
          },
          "address": {
            "$ref": "#/components/schemas/Address"
          }
        }
      },
      "contract_pricing": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "contract_length": {
              "type": "integer",
              "example": 36
            },
            "monthly_rent_payment": {
              "type": "number",
              "example": 44.68
            },
            "monthly_rent_payment_with_tax": {
              "type": "number",
              "example": 47.36
            },
            "ldw": {
              "type": "number",
              "example": 7.95
            },
            "ldw_with_tax": {
              "type": "number",
              "example": 8.43
            },
            "total_monthly_payment": {
              "type": "number",
              "example": 52.63
            },
            "total_monthly_payment_with_tax": {
              "type": "number",
              "example": 55.79
            },
            "security_deposit": {
              "type": "number",
              "example": 44.68
            },
            "security_deposit_with_tax": {
              "type": "number",
              "example": 47.36
            },
            "delivery_fee": {
              "type": "number",
              "example": 100
            },
            "cra": {
              "type": "number",
              "example": 130.39
            },
            "cra_with_tax": {
              "type": "number",
              "example": 138.21
            },
            "upfront_payment": {
              "type": "number",
              "example": 283.02
            },
            "upfront_payment_with_tax": {
              "type": "number",
              "description": "Total Upfront payment including tax",
              "example": 300
            },
            "override_code_required": {
              "type": "boolean",
              "description": "If the structure is above the limit, an override code is required to submit the contract.  The dealer can call into the office for a code.",
              "example": false
            }
          }
        }
      },
      "Contract": {
        "required": [
          "customer",
          "structure"
        ],
        "type": "object",
        "properties": {
          "structure": {
            "$ref": "#/components/schemas/structure"
          },
          "customer": {
            "required": [
              "address",
              "driver_license_number",
              "email",
              "first_name",
              "last_name",
              "primary_phone"
            ],
            "type": "object",
            "properties": {
              "first_name": {
                "type": "string",
                "example": "John"
              },
              "last_name": {
                "type": "string",
                "example": "Doe"
              },
              "suffix": {
                "type": "string"
              },
              "driver_license_number": {
                "type": "string",
                "example": "12345678"
              },
              "primary_phone": {
                "type": "string",
                "example": "1234567890"
              },
              "secondary_phone": {
                "type": "string",
                "example": "1234567890"
              },
              "email": {
                "type": "string",
                "format": "email",
                "example": "email@example.com"
              },
              "address": {
                "$ref": "#/components/schemas/Address"
              }
            }
          },
          "structure_address": {
            "$ref": "#/components/schemas/Address"
          },
          "billing_address": {
            "$ref": "#/components/schemas/Address"
          }
        }
      },
      "Address": {
        "type": "object",
        "properties": {
          "address": {
            "maxLength": 255,
            "type": "string",
            "example": "123 Street Road"
          },
          "city": {
            "maxLength": 255,
            "type": "string",
            "example": "Lancaster"
          },
          "state": {
            "maxLength": 2,
            "minLength": 2,
            "type": "string",
            "format": "USPS 2-letter code",
            "example": "PA"
          },
          "zip": {
            "maxLength": 5,
            "minLength": 5,
            "type": "string",
            "example": "17601"
          }
        }
      },
      "signature_link": {
        "type": "object",
        "properties": {
          "phone": {
            "type": "string",
            "format": "phone",
            "example": "1234567890"
          },
          "email": {
            "type": "string",
            "format": "email",
            "example": "abc@example.com"
          }
        }
      },
      "structure": {
        "required": [
          "condition",
          "delivery_fee",
          "description",
          "length",
          "product",
          "contract_length",
          "roof",
          "serial_number",
          "siding",
          "structure_cost",
          "trim",
          "width"
        ],
        "type": "object",
        "properties": {
          "structure_cost": {
            "type": "number",
            "description": "Structure Cost without Sales Tax",
            "example": 1100
          },
          "delivery_fee": {
            "type": "number",
            "example": 100
          },
          "increased_total_due": {
            "type": "number",
            "description": "If the customer wants to put additional money upfront to reduce their monthly payments, put the total amount they want to put down upfront (including all taxes) here.  If this number is lower than they default upfront funds amount, this will be ignored.  Or if CRA is not available for the requested state/term, if will be ignored.",
            "example": 300
          },
          "ldw": {
            "type": "boolean",
            "example": true
          },
          "product": {
            "type": "string",
            "description": "key from Products endpoint",
            "example": "shed"
          },
          "contract_length": {
            "type": "integer",
            "description": "Lease Contract Length",
            "example": 36
          },
          "width": {
            "type": "integer",
            "example": 10
          },
          "length": {
            "type": "integer",
            "example": 12
          },
          "description": {
            "type": "string",
            "example": "A-Frame"
          },
          "roof": {
            "type": "string",
            "description": "Roof Color",
            "example": "Brown"
          },
          "siding": {
            "type": "string",
            "description": "Siding Color",
            "example": "Red"
          },
          "trim": {
            "type": "string",
            "description": "Trim Color",
            "example": "White"
          },
          "serial_number": {
            "type": "string",
            "example": "8575213"
          },
          "condition": {
            "type": "string",
            "example": "new",
            "enum": [
              "new",
              "used"
            ]
          },
          "model_year": {
            "type": "string",
            "example": "2024"
          },
          "expected_delivery_date": {
            "type": "string",
            "format": "date",
            "example": "2021-07-15"
          },
          "sales_rep": {
            "type": "string",
            "example": "John Doe"
          },
          "override_code": {
            "type": "string",
            "description": "If the structure cost is over the limit, an override code will be required.",
            "example": "abc123"
          }
        }
      }
    },
    "responses": {
      "UnauthorizedError": {
        "description": "Authentication information is missing, invalid, or not allowed to access the requested resource"
      },
      "JsonError": {
        "description": "Json body is malformed, or missing required parameters"
      },
      "MissingFields": {
        "description": "Json body missing required fields"
      }
    },
    "securitySchemes": {
      "api_key": {
        "type": "apiKey",
        "name": "X-API-Key",
        "in": "header"
      }
    }
  },
  "x-original-swagger-version": "2.0"
}