Invoice Creation

This (final) step follows a positive customer evaluation and order confirmation. It is used to verify the user-entered information (during evaluation) and create an invoice, which then appears as a new invoice in the Twisto eshop administration. When the goods are ready for shipment, the eshop activates the invoice in the administration manually or through a request to our API automatically. The invoice is printed in PDF format by the eshop and added to the goods for the customer.

Invoice Image

Implementation Method

Invoice creation is performed after the order is completed in the eshop, at the moment when it is confirmed and saved in the eshop, and its unique identifier is known. When using the PHP library, simply call the Twisto::createInvoice method. This method sends a POST request to the Twisto API. If the request fails due to incorrect data or a connection issue, a TwistoError exception is raised.

The method takes the transaction identifier transaction_id, obtained after the customer evaluation request is completed, along with the order and customer data. The customer and order data must be identical to the evaluation data. If they differ, the invoice creation fails, and the order should be canceled or the customer should be given an alternative payment method.

If the request is processed successfully, an invoice is created, and its number (variable symbol) is returned. This can be used later to activate the invoice via the API.

Optionally, by providing an optional parameter eshop_invoice_id, you can specify the variable symbol with which the payment from the Twisto account will be sent to the eshop. If this parameter is omitted, the payments will contain our generated invoice number invoice_id as the variable symbol. In both cases, the customer sees our invoice number invoice_id as the variable symbol on the invoice.

In case of successful invoice creation, the response will be:

{ "invoice_id": "10100001" }

Usage example

Warning: The createInvoice is the final step of verification. In case it fails, the customer must not be informed about successful completion, and no email should be sent to them. This order is not created in the Twisto system, so Twisto does not send any money to the eshop for it.

<?php // příklad je velmi podobný vyhodnocení zákazníka, create_invoice slouží k ověření zadaných údajů a vytvoření faktury v našem systému // transaction_id je platné pouze 10 minut po vytvoření a lze použít jen jednou try { // $order je už uložená objednávka s order_id, je instancí třídy Order // $eshop_invoice_id je variabilní symbol, se kterým budeme eshopu zasílat platby $invoice_id = $twisto->createInvoice($transaction_id, $customer, $order, $eshop_invoice_id); } catch (Twisto\Error $e) { // pokud dojde k chybě, stornovat objednávku } ?>

Data format

The data format is similar to the customer evaluation but includes some additional information. The NewOrder type is replaced by Order, which contains additional information, mainly the ID of the created order in the eshop. Additionally, the successful evaluation identifier transaction_id is sent.

NameRequiredData typeValue
transaction_idStringTransaction ID obtained after successful evaluation
customerCustomerCustomer information
orderOrderOrder information
eshop_invoice_idStringOptional variable symbol to be sent with the payment