Create invoice via API
If you are not technical enough, you can skip this step. If you understand how API works and you want to create an invoice using an API, you can visit our full API documentation at invoice API docs. To learn about the integration, you can also visit Integration. For testing, you can try to use Postman.
If you choose to use Xendit invoice UI, you can just get the invoice link from our response and embed it into your button or anywhere you want. By using API, You can also create your own User Interface and your own checkout or payment page. Our response will return data that you can use for your own UI. Ignore the invoice link and get other data that suits your need.
Let’s try to create an invoice which we will then pay so you can see how our invoice flow works. You can follow the steps below to implement our invoices API. You’ll need to POST this request. It will create an invoice which your customers can pay with the methods you have configured within the dashboard.
1 2 3 4 5 6
curl https://api.xendit.co/v2/invoices -X POST \ -u xnd_development_O46JfOtygef9kMNsK+ZPGT+ZZ9b3ooF4w3Dn+R1k+2fT/7GlCAN3jg==: \> -d external_id=demo-1531960366017 \ -d email@example.com \ -d description='Trip to Bali' \ -d amount=52000
1 2 3 4 5 6 7 8 9 10 11
<?php require 'vendor/autoload.php'; $options['secret_api_key'] = 'xnd_development_O46JfOtygef9kMNsK+ZPGT+ZZ9b3ooF4w3Dn+R1k+2fT/7GlCAN3jg=='; $xenditPHPClient = new XenditClient\XenditPHPClient($options); $external_id = 'demo_1475801962607'; $payer_email = 'firstname.lastname@example.org'; $description = 'Trip to Bali'; $amount = 13000; $response = $xenditPHPClient->createInvoice($external_id, $amount, $payer_email, $description); print_r($response); ?>
We have prefilled the above example with a sample API key and other filled parameter. You need to change the content of the parameter above with your desired parameter. You can also add optional parameter such as redirection link page, invoice duration and payment methods. The description of the parameter also can be found in invoice API docs.