Create invoice

This last step follows a positive customer credit check. It serves to confirm the order and create an invoice in the Twisto system, which will also be displayed in the e-shop administration.

At the time of shipment, the e-shop will activate the invoice in the administration or through our API (preferred). Then the e-shop prints its standard order PDF invoice and inserts it into the package for shipment.

Invoice Image

An invoice is created when the order is completed in the e-shop, when it is confirmed and stored in the e-shop and the order number is known (e-shop’s variable code). API calls are made directly from the e-shop system.

The API call requires the transaction identifier transaction_id obtained when the customer credit check request is completed. For one transaction_id, only one invoice can be created. An invoice request is required to be sent within 10 minutes of the evaluation. After this time, it expires and the invoice creation returns an error.

If an invoice fails due to an error, the order must be canceled and must not be shipped. Until the order has an invoice (i.e. the call to create invoice was not executed correctly), Twisto will not send any money to the eshop.

If the request is successful, the invoice is created and the returned payload contains data from the Twisto system, such as invoice number, which can be used later to activate the invoice via the API.

Optionally, by specifying an optional parameter, you can specify eshop_invoice_id – this number will be used as a variable code when sending money from Twisto account to the merchant. If this parameter is omitted, variable code for the payments will be invoice_id which is the invoice number generated by Twisto. In both cases, the customer only sees Twisto invoice number(invoice_id) as a variable code for payment.

Implementation

<?php try { $invoice = Twisto\Invoice::create($twisto, $transaction_id, $eshop_invoice_id); // Twisto Invoice ID is stored in $invoice->invoice_id } catch (Twisto\Error $e) { // if an error occurs because of expiration or incorrectly sent data, please cancel the order // například $mysqli->query("UPDATE eshop_orders SET status='cancelled' WHERE invoice_id = " . (int)$eshop_invoice_id); } ?>

Data format

Request

NameRequiredData typeMaximum lengthValue
transaction_idStringTransaction ID obtained after successful evaluation
eshop_invoice_idString10Optional variable code for sending a payment to merchant’s bank account. If not specified, the invoice_id is used. Only numeric characters are allowed.
Next parameters are only used for integration with payment processors
provider_idString13Payment provider order ID. Format EYDDDNNNNNNNN is required.
provider_dateStringDate when the transaction was processed in payment gateway. Format ISO-8601 with timezone.

Response

All invoice information is returned when the invoice is created correctly.

NameDatatypeValue
invoice_idStringTwisto InvoiceID

A complete list of attributes is available in the data specification.

{ "invoice_id": "66416319", "eshop_invoice_id": "", "customer_email": "novak@example.cz", "billing_address": { "type": 1, "name": "Jan Novák", "street": "Karlova 2", "city": "Praha 5", "zipcode": "10010", "phone_number": "+420732629228", "country": "CZ" }, "delivery_address": { "type": 1, "name": "Jan Novák", "street": "Karlova 2", "city": "Praha 5", "zipcode": "10010", "phone_number": "+420732629228", "country": "CZ" }, "date_created": "2018-06-13T09:53:56.657422Z", "date_returned": null, "date_cancelled": null, "date_activated": null, "date_paid": null, "pdf_url": null, "total_price_vat": "23200.00", "items": [ { "type": 2, "name": "Platba Twisto (na fakturu)", "product_id": "75325", "quantity": 1, "price_vat": "0.00", "vat": 21, "ean_code": null, "isbn_code": null, "issn_code": null, "heureka_category": null }, { "type": 1, "name": "DHL", "product_id": "a87ff679a2f3e71d9181a67b7542122c", "quantity": 1, "price_vat": "200.00", "vat": 21, "ean_code": null, "isbn_code": null, "issn_code": null, "heureka_category": null }, { "type": 0, "name": "MacBook", "product_id": "c81e728d9d4c2f636f067f89cc14862c", "quantity": 1, "price_vat": "23000.00", "vat": 21, "ean_code": "8859094127591", "isbn_code": null, "issn_code": null, "heureka_category": null } ], "has_account": false, "margin_amount": null, "margin_amount_vat": null, "paid_to_merchant_amount": 23200 }