gandhist/ematerai

Mekari eMaterai API Client for Laravel

dev-main 2023-08-24 03:25 UTC

This package is auto-updated.

Last update: 2024-09-24 05:59:28 UTC


README

Unofficial Laravel library for eMaterai by Mekari

This is the unofficial library for eMaterai API by Mekari, for official documentation please visit Mekari

1. Installation

Install using Composer CLI : composer require gandhist/ematerai

2. How to use

2.1 General Setting

Add to your env variables :

    MATERAI_CLIENT_ID=<your client id>
    MATERAI_SECRET=<your client_secret>
    MATERAI_CODE=<your_auth_code>
    MATERAI_IS_PRODUCTION=false

Add use Gandhist\Ematerai\Config;, set configuration :

    Config::$isProduction =  false;
    Config::$clientId =  env('MATERAI_CLIENT_ID');
    Config::$clientSecret =  env('MATERAI_SECRET');
    Config::$authCode =  env('MATERAI_CODE');

2. 2 Stamp a document

For stamping a document, you have to convert your PDF to base64, you can use Base64 Guru to convert your document. Add use Gandhist\Ematerai\Stamping;

    $stamp = new Stamping;
    $base64 = "your_base_64_pdf_file";
    $filename = "your_file_name.pdf";
    $callback = "https://webhook.site/e91fe71f-6672-4ae6-86b2-9018ba4df5a3?validation_key=ABCDE";
    $annotation = [[
        "page"  =>  4, // page you want to stamp
        "position_x"  =>  150, // set x axis
        "position_y"  =>  450, // set y axis
        "element_width"  =>  80,
        "element_height"  =>  80,
        "canvas_width"  =>  836,
        "canvas_height"  =>  1181,
        "type_of"  =>  "meterai"
    ]];
    $stamping = $stamp->stamp($base64, $filename, $annotation, $callback);

2.3 Get detail document by document id

Add use Gandhist\Ematerai\Document;

$doc = new Document;
return $doc->detail("<document-id>");

2.4 Resend/Restamp document by document id

Add use Gandhist\Ematerai\Stamping;

$doc = new Stamping;
return $doc->restamp("<document-id>");