# Finalize Invoice POST https://app.paymentkit.com/api/{account_id}/invoices/{external_id}/finalize Finalize an invoice (transition from DRAFT to OPEN). Triggers PDF generation after finalization. Requirements: - Invoice must be in DRAFT state Returns: - The finalized invoice with OPEN status Reference: https://docs.paymentkit.com/api-reference/api-reference/invoices/finalize-invoice ## OpenAPI Specification ```yaml openapi: 3.1.0 info: title: Core API version: 1.0.0 paths: /api/{account_id}/invoices/{external_id}/finalize: post: operationId: finalize-invoice summary: Finalize Invoice description: |- Finalize an invoice (transition from DRAFT to OPEN). Triggers PDF generation after finalization. Requirements: - Invoice must be in DRAFT state Returns: - The finalized invoice with OPEN status tags: - subpackage_invoices parameters: - name: external_id in: path required: true schema: type: string - name: account_id in: path required: true schema: type: string - name: Authorization in: header description: Bearer authentication required: true schema: type: string responses: '200': description: Successful Response content: application/json: schema: $ref: '#/components/schemas/Invoice' '422': description: Validation Error content: application/json: schema: $ref: '#/components/schemas/HTTPValidationError' servers: - url: https://app.paymentkit.com - url: https://staging.paymentkit.com components: schemas: InvoiceState: type: string enum: - draft - open - partially_paid - paid - past_due - void - uncollectible title: InvoiceState CurrencyCode: type: string enum: - aed - afn - all - amd - ang - aoa - ars - aud - awg - azn - bam - bbd - bdt - bgn - bhd - bif - bmd - bnd - bob - brl - bsd - btn - bwp - byn - bzd - cad - cdf - chf - clp - cny - cop - crc - cuc - cup - cve - czk - djf - dkk - dop - dzd - egp - ern - etb - eur - fjd - fkp - gbp - gel - ghs - gip - gmd - gnf - gtq - gyd - hkd - hnl - hrk - htg - huf - idr - ils - inr - iqd - irr - isk - jmd - jod - jpy - kes - kgs - khr - kmf - kpw - krw - kwd - kyd - kzt - lak - lbp - lkr - lrd - lsl - lyd - mad - mdl - mga - mkd - mmk - mnt - mop - mru - mur - mvr - mwk - mxn - myr - mzn - nad - ngn - nio - nok - npr - nzd - omr - pab - pen - pgk - php - pkr - pln - pyg - qar - ron - rsd - rub - rwf - sar - sbd - scr - sdg - sek - sgd - shp - sle - sos - srd - ssp - stn - svc - syp - szl - thb - tjs - tmt - tnd - top - try - ttd - twd - tzs - uah - ugx - usd - uyu - uzs - ves - vnd - vuv - wst - xaf - xcd - xof - xpf - yer - zar - zmw - zwl description: ISO 4217 currency codes. title: CurrencyCode CollectionMethod: type: string enum: - charge_automatically - send_invoice title: CollectionMethod TierAmountInfoMode: type: string enum: - volume - graduated description: 'Pricing mode: ''volume'' or ''graduated''' title: TierAmountInfoMode TierAmountAtom: type: object properties: units_upto: type: - integer - 'null' description: Upper limit for this tier. Use null for infinity (last tier) unit_amount_atom: type: integer description: Price per unit in this tier (in atomic units) flat_amount_atom: type: integer default: 0 description: Flat fee for this tier (in atomic units) required: - unit_amount_atom description: Individual tier configuration for tiered pricing. title: TierAmountAtom TierAmountInfo: type: object properties: mode: $ref: '#/components/schemas/TierAmountInfoMode' description: 'Pricing mode: ''volume'' or ''graduated''' amount_atoms: type: array items: $ref: '#/components/schemas/TierAmountAtom' description: List of pricing tiers required: - mode - amount_atoms description: Tiered pricing configuration. title: TierAmountInfo Price: type: object properties: id: type: string account_id: type: string product_id: type: string product_name: type: - string - 'null' product_description: type: - string - 'null' name: type: - string - 'null' unit_amount_atom: type: - integer - 'null' currency: $ref: '#/components/schemas/CurrencyCode' is_active: type: boolean unit_label: type: - string - 'null' pricing_type: type: string recurring_interval: type: - string - 'null' recurring_interval_count: type: - integer - 'null' auto_renew: type: - boolean - 'null' contract_term_multiple: type: - integer - 'null' trial_days: type: integer usage_type: type: string metered_id: type: - string - 'null' billing_scheme: type: string tier_amount_info: oneOf: - $ref: '#/components/schemas/TierAmountInfo' - type: 'null' prerequisite_price_ids: type: - array - 'null' items: type: string exclusive_customer_ids: type: - array - 'null' items: type: string metadata: type: - object - 'null' additionalProperties: description: Any type custom_fields: type: - object - 'null' additionalProperties: description: Any type description: >- Custom field values. Only included when expand=custom_fields is specified. quantity_divisor: type: integer default: 1 created_at: type: string format: date-time updated_at: type: string format: date-time required: - id - account_id - product_id - name - unit_amount_atom - currency - is_active - unit_label - pricing_type - recurring_interval - recurring_interval_count - auto_renew - contract_term_multiple - trial_days - usage_type - metered_id - billing_scheme - tier_amount_info - prerequisite_price_ids - exclusive_customer_ids - metadata - created_at - updated_at title: Price InvoiceItem: type: object properties: id: type: string invoice_id: type: - string - 'null' price: $ref: '#/components/schemas/Price' product_name: type: - string - 'null' description: type: - string - 'null' quantity: type: integer amount: type: integer proration: type: boolean default: false period_start: type: - string - 'null' format: date-time period_end: type: - string - 'null' format: date-time metadata: type: - object - 'null' additionalProperties: description: Any type created_at: type: string format: date-time updated_at: type: string format: date-time required: - id - invoice_id - price - description - quantity - amount - metadata - created_at - updated_at title: InvoiceItem BillingReason: type: string enum: - manual - subscription_create - subscription_cycle - subscription_threshold - subscription_update - upcoming title: BillingReason Invoice: type: object properties: id: type: string customer_id: type: string status: $ref: '#/components/schemas/InvoiceState' currency: $ref: '#/components/schemas/CurrencyCode' subtotal_amount_atom: type: - integer - 'null' tax_amount_atom: type: - integer - 'null' total_amount_atom: type: - integer - 'null' due_amount_atom: type: - integer - 'null' paid_amount_atom: type: - integer - 'null' remaining_amount_atom: type: - integer - 'null' applied_balance_amount_atom: type: - integer - 'null' total_discount_amount_atom: type: - integer - 'null' issued_at: type: string format: date-time due_date: type: - string - 'null' format: date-time period_start: type: - string - 'null' format: date-time period_end: type: - string - 'null' format: date-time collection_method: $ref: '#/components/schemas/CollectionMethod' description: type: - string - 'null' metadata: type: - object - 'null' additionalProperties: description: Any type custom_fields: type: - object - 'null' additionalProperties: description: Any type description: >- Custom field values. Only included when expand=custom_fields is specified. items: type: array items: $ref: '#/components/schemas/InvoiceItem' created_at: type: string format: date-time updated_at: type: string format: date-time invoice_number: type: - integer - 'null' billing_reason: oneOf: - $ref: '#/components/schemas/BillingReason' - type: 'null' subscription_id: type: - string - 'null' invoice_pdf_url: type: - string - 'null' receipt_pdf_url: type: - string - 'null' required: - id - customer_id - status - currency - subtotal_amount_atom - tax_amount_atom - total_amount_atom - due_amount_atom - paid_amount_atom - remaining_amount_atom - issued_at - due_date - description - metadata - created_at - updated_at title: Invoice ValidationErrorLocItems: oneOf: - type: string - type: integer title: ValidationErrorLocItems ValidationError: type: object properties: loc: type: array items: $ref: '#/components/schemas/ValidationErrorLocItems' msg: type: string type: type: string required: - loc - msg - type title: ValidationError HTTPValidationError: type: object properties: detail: type: array items: $ref: '#/components/schemas/ValidationError' title: HTTPValidationError securitySchemes: HTTPBearer: type: http scheme: bearer ``` ## SDK Code Examples ```python import requests url = "https://app.paymentkit.com/api/account_id/invoices/external_id/finalize" payload = {} headers = { "Authorization": "Bearer ", "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` ```javascript const url = 'https://app.paymentkit.com/api/account_id/invoices/external_id/finalize'; const options = { method: 'POST', headers: {Authorization: 'Bearer ', 'Content-Type': 'application/json'}, body: '{}' }; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://app.paymentkit.com/api/account_id/invoices/external_id/finalize" payload := strings.NewReader("{}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "Bearer ") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby require 'uri' require 'net/http' url = URI("https://app.paymentkit.com/api/account_id/invoices/external_id/finalize") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["Authorization"] = 'Bearer ' request["Content-Type"] = 'application/json' request.body = "{}" response = http.request(request) puts response.read_body ``` ```java import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://app.paymentkit.com/api/account_id/invoices/external_id/finalize") .header("Authorization", "Bearer ") .header("Content-Type", "application/json") .body("{}") .asString(); ``` ```php request('POST', 'https://app.paymentkit.com/api/account_id/invoices/external_id/finalize', [ 'body' => '{}', 'headers' => [ 'Authorization' => 'Bearer ', 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` ```csharp using RestSharp; var client = new RestClient("https://app.paymentkit.com/api/account_id/invoices/external_id/finalize"); var request = new RestRequest(Method.POST); request.AddHeader("Authorization", "Bearer "); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = [ "Authorization": "Bearer ", "Content-Type": "application/json" ] let parameters = [] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://app.paymentkit.com/api/account_id/invoices/external_id/finalize")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ```