How to create invoice for terminal checkout payment and close the invoice as payed?

Guys, I would like to issue an invoice the the order that will be payed via terminal checkout.

If I understand the limitations correctly I cannot re-use the Order from TerminalCheckout cause the Order attached to the Invoice cannot be changed, so terminal checkout has to have it’s own Order instance. Then the Order for terminal checkout get payment information attached.

Since the the invoice is also payed cause it’s attached to copy of the order from the terminal checkout, I would like to complete it as well — attach a payment, or at least close it as payed.

I am basically looking to accomplish this through the API:

So how to create invoice for terminal checkout payment and close the invoice as payed?


Reference

Order update is not supported

After an order is associated with an invoice, you cannot update order fields that affect the order amount (or their child fields), such as:

  • line_items
  • taxes
  • discounts

To update these immutable fields, you must cancel the invoice, which also cancels the order. You can then create a new order and a new invoice. However, you can update order fields that don’t affect the cart.

Order used in Invoice cannot be referenced by Terminal Checkout

Payment for the order must be made on the invoice. You cannot use Square APIs such as PayOrderYou can pay for your orders with the Payments API (the CreatePayment endpoint) or with the Orders API (the PayOrder endpoint).Guide or CreatePaymentCreates a payment using the provided source.Endpoint to process a payment for an order that is associated with an invoice. After the invoice is paid in full, Square sets the state field of the order to COMPLETED.


When I try to attach a payment to the Invoice order I get a confusing error that does not indicate what is actually happening.

{
  "errors": [
    {
      "code": "FORBIDDEN",
      "detail": "The order `tcn...ZY` is owned by another application.",
      "category": "AUTHENTICATION_ERROR"
    }
  ],
  "payment": {
    "id": "x67x...fcZY",
    "created_at": "2024-08-08T08:34:02.469Z",
    "updated_at": "2024-08-08T08:34:02.539Z",
    "amount_money": {
      "amount": 321,
      "currency": "USD"
    },
    "status": "CANCELED",
    "source_type": "EXTERNAL",
    "location_id": "LYP...1KH",
    "order_id": "tcn...LZY",
    "total_money": {
      "amount": 321,
      "currency": "USD"
    },
    "capabilities": [
      "EDIT_AMOUNT_UP",
      "EDIT_AMOUNT_DOWN",
      "EDIT_TIP_AMOUNT_UP",
      "EDIT_TIP_AMOUNT_DOWN"
    ],
    "external_details": {
      "type": "EXTERNAL",
      "source": "terminal checkout duplicate"
    },
    "application_details": {
      "square_product": "ECOMMERCE_API",
      "application_id": "sandbox-sq0idb--TC...Iog"
    },
    "version_token": "P1T4...85o"
  }
}
`

--- 

If the information from thread [403 Error on Create payment with order_id](https://developer.squareup.com/forums/t/403-error-on-create-payment-with-order-id/1118) is correct then we're basically screwed and we need to create invoices elsewhere.

:wave: I’m Square Dev AI, here to help answer your question!
Based on the information you’ve provided, the following documentation will help answer your question:

Additional Documentation

Create and Publish Invoices
Create and Publish Invoices
Pay for Orders

If this documentation helped you find a solution, please check the box indicating that this reply solves the problem.
Otherwise one of our Developer Advocates will provide additional assistance shortly.

Yeah, once an invoice is created and published it can only be paid either through the invoice itself or the 1st party products. Paying for a published invoice with our APIs isn’t currently available. :slightly_smiling_face:

So how do I create na invoice related to the Terminal Checkout payment?

When I try to add invoice to the order paid with Terminal Checkout, I get this:

{
  "errors": [
    {
      "code": "BAD_REQUEST",
      "detail": "The order must be in the OPEN state to create an invoice",
      "field": "invoice.order_id",
      "category": "INVALID_REQUEST_ERROR"
    }
  ]
}

At this time the ability to pass an invoice order_id to a CreateTerminalCheckout call to pay for the invoice isn’t currently available. The invoice can only be paid within the 1st party app. Paying for it with our APIs isn’t currently available. We’re constantly working to improve our features based on feedback like this, so I’ll be sure to share your request to the API product team. :slightly_smiling_face: