Cara menggunakan php invoice generator

API - Generate Invoice QRIS Payment

Definisi

API ini digunakan untuk menampilkan Nominal Transaksi QRIS pada aplikasi Anda agar dapat digunakan oleh pengguna aplikasi untuk membayar/scan transaksi menggunakan metode QRIS.

Nominal Transaksi berupa Total Transaksi yang akan dibayar dan harus ditentukan dari aplikasi Anda.

Aplikasi Anda akan mendapatkan Konten QRIS (qris_content) yang dapat dimanfaatkan untuk menampilkan QR Code sesuai dengan library yang digunakan pada Bahasa Pemrograman yang Anda gunakan.

Disarankan untuk menyimpan Konten QRIS (qris_content), tanggal generate (qris_request_date) dan Invoice ID (qris_invoiceid) ke database Anda yang nanti dapat dimanfaatkan untuk menampilkan ulang sebelum Konten teks QRIS tersebut Expired dan Invoice ID (qris_invoiceid) dapat digunakan untuk memeriksa status pembayaran QRIS.

Batas waktu kadaluarsa (expired) 30 menit semenjak QRIS ditampilkan. Saat Expired maka QRIS akan gagal saat di-scan oleh pengguna.

Nominal Transaksi yang dapat digunakan untuk scan QRIS berbeda-beda minimal dan maksimalnya.

  • GOPAY minimal Rp.1
  • DANA minimal Rp.1
  • ShopeePay minimal Rp.1
  • LinkAja minimal Rp.100
  • OVO minimal Rp.1000

Maksimal jumlah transaksi biasanya adalah Rp 2.000.000 atau juga bisa lebih tergantung dari Jenis Akun pengguna disetiap aplikasi e-wallet.

Request Type
GET URL


    https://qris.id/restapi/qris/show_qris.php
    

GET Parameters
VariableTipeNilai contohrequiredDeskripsi
do string create-invoice required Harus bernilai create-invoice
apikey string a789789 required APIKEY diperoleh dari email aktivasi APIKEY
mID integer 123456 required mID diperoleh dari email aktivasi APIKEY
cliTrxNumber string PJ0099 required Nomor Nota Transaksi QRIS dari aplikasi Anda
cliTrxAmount integer 10000 required Nilai Transaksi QRIS dari aplikasi Anda yang akan dibayarkan Customer (Nilai Akhir sesudah diskon atau pajak atau biaya lainnya)
success Responses example in json


    {
        "status": "success",
        "data": {
            "qris_content": "00020101021226680016ID.CO.TELKOM.WWW011893600898025599662702150001952559966270303UMI51440014ID.CO.QRIS.WWW0215ID10200211817450303UMI520457325303360540825578.005502015802ID5916InterActive Corp6013KOTA SURABAYA61056013662130509413255111630439B7",
            "qris_request_date": "2020-08-07 11:13:42",
            "qris_invoiceid": "413255111",
            "qris_nmid": "ID1020021181745"
        }
    }
    

Dalam Response diatas Anda akan mendapatkan Response Konten QRIS (qris_content) yang dapat dimanfaatkan untuk menampilkan QR Code sesuai dengan library yang digunakan pada Bahasa Pemrograman yang Anda gunakan.

Invoice ID (qris_invoiceid) adalah Nomor Transaksi QRIS yang berupa integer yang dapat digunakan untuk memeriksa status pembayaran QRIS.

QRIS NMID (qris_nmid) adalah National Merchant ID untuk QRIS harus ditampilkan dibawah QR pada layar atau cetakan QRIS jika menggunakan aplikasi / software / web. Contoh Format yang disarankan sesuai ketentuan sebagai berikut :

Cara menggunakan php invoice generator

Batas waktu kadaluarsa (expired) 30 menit (dalam WIB atau GMT+7) semenjak QRIS ditampilkan, Anda dapat memanfaatkan (qris_request_date) untuk acuan menghitung expired. Saat Expired maka QRIS akan gagal saat di-scan oleh pengguna.

failed Responses example in json


    {
        "status": "failed",
        "data": {
            "qris_status": "invalid amount / invalid APIKEY / invalid mID / transcation number is empty / mandatory parameter is not valid / what we do for you?"
        }
    }
    

Invoicr is a free and open-source PHP invoice generator that is capable of churning out HTML, PDF, and DOCX invoices. It is a simple fuss-free package that will give developers a quick boost with their invoice generation needs.

TABLE OF CONTENTS

DOWNLOAD & NOTES

First, here are the download links and a quick “setup guide” for the impatient folks who don’t have the patience to read through everything.

INSTALLATION & REQUIREMENTS

There is no “installation” involved, only a small hassle:

  • Open invlib/invoicr.php, change (C1) company information to your own.
  • That’s all – See example.php for a quick start.
  • MPDF requires GD extension to work properly.

LICENSE & DOWNLOAD

Invoicr is released under the MIT License. You are free to use it for personal and commercial projects, and modify it as you see fit. On the condition that the software is provided “as-is”. There are no warranties provided and “no strings attached”. Code Boxx and the authors are not liable for any claims, damages, or liabilities.

GitHub | SourceForge

THE INVOICE TEMPLATES

CREDITS & LIBRARIES USED

Invoicr is made possible with the following open source projects:

  • MPDF for adding the PDF capabilities.
  • PHPWord for the DOCX capability.

HOW TO USE

Cara menggunakan php invoice generator
So far so good? Let us now go through a quick crash course on how to use Invoicr.

STEP 1) LOAD INVOICR LIBRARY

// (A) LOAD INVOICR
require "invlib/invoicr.php";

Start by including the invlib/invoicr.php library in your own project. This will automatically create a $invoicr object.

STEP 2) FEED INVOICE INFORMATION

// (B) SET INVOICE DATA
// (B1) COMPANY INFORMATION
/* RECOMMENDED TO JUST PERMANENTLY CODE INTO INVLIB/INVOICR.PHP > (C1)
$invoicr->set("company", [
  "http://localhost/code-boxx-logo.png",
  "D:/http/code-boxx-logo.png", 
  "Code Boxx", 
  "Street Address, City, State, Zip",
  "Phone: xxx-xxx-xxx | Fax: xxx-xxx-xxx",
  "https://code-boxx.com",
  ""
]); */

// (B2) INVOICE HEADER
$invoicr->set("head", [
  ["Invoice #", "CB-123-456"],
  ["DOP", "2011-11-11"],
  ["P.O. #", "CB-789-123"],
  ["Due Date", "2011-12-12"]
]);

// (B3) BILL TO
$invoicr->set("billto", [
  "Customer Name",
  "Street Address", 
  "City, State, Zip"
]);

// (B4) SHIP TO
$invoicr->set("shipto", [
  "Customer Name",
  "Street Address", 
  "City, State, Zip"
]);

// (B5) ITEMS - ADD ONE-BY-ONE
$items = [
  ["Rubber Hose", "5m long rubber hose", 3, "$5.50", "$16.50"],
  ["Rubber Duck", "Good bathtub companion", 8, "$4.20", "$33.60"],
  ["Rubber Band", "", 10, "$0.10", "$1.00"],
  ["Rubber Stamp", "", 3, "$12.30", "$36.90"],
  ["Rubber Shoe", "For slipping, not for running", 1, "$20.00", "$20.00"]
];
// foreach ($items as $i) { $invoicr->add("items", $i); }

// (B6) ITEMS - OR SET ALL AT ONCE
$invoicr->set("items", $items);

// (B7) TOTALS
$invoicr->set("totals", [
  ["SUB-TOTAL", "$108.00"],
  ["DISCOUNT 10%", "-$10.80"],
  ["GRAND TOTAL", "$97.20"]
]);

// (B8) NOTES, IF ANY
$invoicr->set("notes", [
  "Cheques should be made payable to Code Boxx",
  "Get a 10% off with the next purchase with discount code DOGE1234!"
]);

This is probably the most “complicated” step, you need to use $invoicr->set() or $invoicr->add() to feed Invoicr with information:

  • Company logo, name, address, contact.
  • Invoice information.
  • Bill to.
  • Ship to.
  • The items.
  • Totals.
  • Notes, if any.

STEP 3) CHOOSE A TEMPLATE & OUTPUT THE INVOICE

// (C) OUTPUT
// (C1) CHOOSE A TEMPLATE
$invoicr->template("apple");
// $invoicr->template("banana");
// $invoicr->template("blueberry");
// $invoicr->template("lime");
// $invoicr->template("simple");
// $invoicr->template("strawberry");

// (C2) OUTPUT IN HTML
// DEFAULT : DISPLAY IN BROWSER 
// 1 : DISPLAY IN BROWSER 
// 2 : FORCE DOWNLOAD 
// 3 : SAVE ON SERVER
$invoicr->outputHTML();
// $invoicr->outputHTML(1);
// $invoicr->outputHTML(2, "invoice.html");
// $invoicr->outputHTML(3, __DIR__ . DIRECTORY_SEPARATOR . "invoice.html");

// (C3) OUTPUT IN PDF
// DEFAULT : DISPLAY IN BROWSER 
// 1 : DISPLAY IN BROWSER 
// 2 : FORCE DOWNLOAD 
// 3 : SAVE ON SERVER
// $invoicr->outputPDF();
// $invoicr->outputPDF(1);
// $invoicr->outputPDF(2, "invoice.pdf");
// $invoicr->outputPDF(3, __DIR__ . DIRECTORY_SEPARATOR . "invoice.pdf");

// (C4) OUTPUT IN DOCX
// DEFAULT : FORCE DOWNLOAD
// 1 : FORCE DOWNLOAD 
// 2 : SAVE ON SERVER
// $invoicr->outputDOCX();
// $invoicr->outputDOCX(1, "invoice.docx");
// $invoicr->outputDOCX(2, __DIR__ . DIRECTORY_SEPARATOR . "invoice.docx");

Finally, choose a template to use and output the invoice.

CUSTOM TEMPLATE

Want to build your own customized theme? It is actually pretty easy to do so… If you are unsure at any point, feel free to use the “default” simple.php template files as a reference.

STEP 1) CREATE AN EMPTY PHP FILE

Start by creating a new PHP file in the respective template folder – invlib/DOCX, invlib/HTML, or invlib/PDF. For example, if we want to add a new “durian” template for HTML, we create invlib/HTML/durian.php.

STEP 2) BUILD THE TEMPLATE

2A) ACCESSING INVOICE INFORMATION

In the template file, we can access the various invoice information previously set with $invoicr->set() or $invoicr->add().

  • $this->company – Company logo, name, address, contact.
  • $this->head- Invoice information.
  • $this->billto – Bill to.
  • $this->shipto – Ship to.
  • $this->items – The items.
  • $this->totals – Totals.
  • $this->notes – Notes, if any.

2B) HTML TEMPLATES

To create an HTML template, simply put all the HTML code into $this->data. For example, we can access the items to create a list.

invlib/HTML/durian.php

$this->data = "<ul>";
foreach ($this->items as $i) {
  $this->data .= "<li>". $i[0] ."</li>";
}
$this->data .= "</ul>";

2C) PDF TEMPLATES

PDF generation is handled by MPDF, and it is capable of taking in HTML to generate PDF.

invlib/PDF/durian.php

$this->data = "<ul>";
foreach ($this->items as $i) { $this->data .= "<li>". $i[0] ."</li>"; }
$this->data .= "</ul>";
$mpdf->WriteHTML($this->data);

Check out the official MPDF documentation if you need more information.

2D) DOCX TEMPLATES

PHPWord handles the DOCX generation, and it is the “unfriendliest” to work with… Just read through the official PHPWord documentation for more information.

invlib/DOCX/durian.php

$section = $pw->addSection();
$table = $section->addTable($tableStyle);
foreach ($this->items as $i) {
  $table->addRow();
  $cell = $table->addCell(2000, $style);
  $cell->addText($i[0]);
}