Invoices are usually a key part of B2B purchasing workflow. It’s typical for company buyers to pay with credit initially on an order (in BigCommerce, this means using the Check/Purchase Order payment method), then pay an invoice for that order at a later date.
We’ve already seen a glimpse of the Credit and Payment Terms configuration that are related to credit payment workflow. In this section, we’ll discuss invoices themselves.
The storefront-facing experience related to invoices only begins after an invoice has been created by the merchant. Therefore, the GraphQL storefront API does not expose any operations related to the creation, update, or deletion of invoices, only those related to viewing a company’s invoices and initiating payment for them.
The current company’s invoices can be fetched with the invoices query.
The invoices query is available when the user associated with the Bearer token has the Senior Buyer role or higher, or a custom role with the “Invoices - View” permission.
invoices supports standard pagination arguments.invoiceNumber, orderNumber, purchaseOrderNumber, and status.beginDateAt, endDateAt, beginDueDateAt, and endDueDateAt. All of these arguments except an integer timestamp value.idIn, which accepts a string value with a comma-separated list of invoice IDs. (For example, “5556677,5556678”)customerId field actually contains the ID of the company.status of an invoice will be 0 if the invoice is open (meaning no payment has been made), 1 if partial payment has been applied, and 2 if the invoice is fully paid. When the open balance of an invoice has been reduced to 0, the status will automatically be set to 2.details returns a complex object, but its GraphQL type does not allow more granular querying of the sub-fields. The details fields (header.billingAddress, details.shipments, etc) contain full information about the order that was invoiced.pendingPaymentCount relates to the payment records that have been recorded against the invoice (see next section). While the amounts of any payments applied to the invoice will be reflected in its open balance, any of those payments that are still in “Awaiting Processing” or “Processing” status will be reflected in pendingPaymentCount.openBalance.value will equal the original invoice balance minus all applied payments.The invoice query can be used to fetch a single invoice using its ID.
The invoice query is available when the user associated with the Bearer token has the Senior Buyer role or higher, or a custom role with the “Invoices - View” permission.
This query returns the same GraphQL type as the nodes returned from invoices, so the same fields can be queried.
Invoice information is also available in the form of downloadable CSV exports or PDFs.
Both of the following mutations - invoicesExport and invoicePdf- are available when the user associated with the Bearer token has the Senior Buyer role or higher, or a custom role with the “Invoices - View” permission.
The invoicesExport mutation can be used to export a CSV file containing one or more invoices.
The invoiceFilterData argument can be provided to filter the exported results.
In addition to fields for filtering on invoice date, the invoiceFilterData also supports the fields invoiceNumber, orderNumber, status, and idIn. As with the invoices query, idIn accepts a comma-separated string.
The invoicePdf mutation is intended only for a single invoice, returning a PDF download URL.
The isPayNow argument accepted by invoicePdf controls the appearance of a pay button in the final PDF. If isPayNow is TRUE, the PDF will include a “Pay Now” button that links the user to checkout for the invoice payment.
Once an invoice has been created, company users need the ability to make payment on it from the storefront.
Similar to the case with creating an order from a quote, this can be done with the invoiceCreateBcCart mutation.
The invoiceCreateBcCart mutation is available when the user associated with the Bearer token has the Admin role or a custom role with the “Invoices - Pay invoices” permission.
details field of the bcCartData argument is required but should receive an empty object.amount less than the open balance of the invoice. Attempting to provide a value for amount greater than the open balance will result in a validation error.cartId queried in the response is a BigCommerce cart identifier.Redirecting a user to the checkoutUrl will initiate a BigCommerce checkout with the invoice payment loaded into the “cart.” The allowed payment methods you’ve configured in your store for invoice payment will be reflected in the checkout, and once the order is placed, the payment will be applied to the invoice.
Note that the bcCartData argument for invoiceCreateBcCart actually accepts an array of lineItems. This means that it’s possible to initiate a checkout for the payment of multiple invoices.
It is possible to utilize the BigCommerce REST Management API to manually construct a cart with the “Invoice Payment” product installed by B2B Edition with the proper modifier option, but this is not an officially supported workflow.