定制 klsheng/myinvois-php-sdk 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

klsheng/myinvois-php-sdk

Composer 安装命令:

composer require klsheng/myinvois-php-sdk

包简介

MyInvois SDK for PHP

README 文档

README

Latest Version on Packagist Total Downloads License

Buy Me A Coffee

An object-oriented PHP library to create custom UBL v2.1 format supported by MyInvois System.

This SDK initially require UBL-Invoice package. However, MyInvois System doesn't fully support UBL v2.1 format, so UBL package re-create based on original author to support MyInvois System.

TODO

  • Login as Taxpayer System
  • Login as Intermediary System
  • Get All Document Types
  • Get Document Type
  • Get Document Type Version
  • Get Notifications
  • Validate Taxpayer's TIN
  • Search Taxpayer's TIN
  • Get Taxpayer From QR Code
  • Submit Documents (Invoice)
  • Submit Documents (CreditNote)
  • Submit Documents (DebitNote)
  • Submit Documents (RefundNote)
  • Submit Documents (Self-Billed Invoice)
  • Submit Documents (Self-Billed Credit Note)
  • Submit Documents (Self-Billed Debit Note)
  • Submit Documents (Self-Billed Refund Note)
  • Cancel Document
  • Reject Document
  • Get Recent Documents
  • Get Submission
  • Get Document
  • Get Document Details
  • Search Documents
  • Digital Signature
  • Get Document's QR Code URL
  • Number Formatter

Installation and usage

This package requires PHP 7.4 or higher.

The preferred way to install this extension is through composer.

To install, either run

$ composer require klsheng/myinvois-php-sdk "*"

or add

"klsheng/myinvois-php-sdk": "*"

to the require section of your composer.json file.

Dependencies

This package require the following extensions in order to work properly:

If you use Composer, these dependencies should be handled automatically. If you install manually, you'll want to make sure that these extensions are available.

It is recommended to install and use composer in PHP development when doesn't use any PHP framework (E.g: Laravel, Yii, etc)

To use MyInvois PHP SDK without PHP framework environment

You may refer to README at PurePHPExample.

Usage

You may refer example to create UBL v2.1 document supported by MyInvois System at CreateDocumentExample.

Sample usage:

Login as Taxpayer System

use Klsheng\Myinvois\MyInvoisClient;

$prodMode = false;
$client = new MyInvoisClient('client_id', 'client_secret', $prodMode);

$client->login();
$access_token = $client->getAccessToken();
// Store $access_token somewhere to re-use it again within 1hour

// OR
$client->setAccessToken('access_token');

Login as Intermediary System

use Klsheng\Myinvois\MyInvoisClient;

$prodMode = false;
$client = new MyInvoisClient('client_id', 'client_secret', $prodMode);

$client->login($onbehalfof);
$access_token = $client->getAccessToken();
// Store $access_token somewhere to re-use it again within 1hour

// OR
$client->setAccessToken('access_token');
$client->setOnbehalfof($onbehalfof);

Get All Document Types

$response = $client->getAllDocumentTypes();

Get Document Type

$response = $client->getDocumentType($id);

Get Document Type Version

$response = $client->getDocumentTypeVersion($id, $versionId);

Get Notifications

$response = $client->getNotifications();
// OR
$dateFrom = new \DateTime('2015-02-13T14:20:10Z'); 
$dateTo = '2015-02-13T14:20:10Z';
$type = '2';
$language = 'en';
$status = 'delivered';
$pageNo = 3;
$pageSize = 20;

$response = $client->getNotifications($dateFrom, $dateTo, $type, $language, $status, $pageNo, $pageSize);

Validate Taxpayer's TIN

$tin = 'C00000000000';
$idType = 'NRIC';
$idValue = '770625015324';

$response = $client->validateTaxPayerTin($tin, $idType, $idValue);

Search Taxpayer's TIN

$taxPayerName = 'AXXX_XXXX SMART';
// OR
// $taxPayerName = 'AXXX_XXXX+SMART';
// OR
// $taxPayerName = '';
$idType = 'NRIC';
$idValue = '770625015324';
$fileType = null; // null or '1' or '2'

$response = $client->searchTaxPayerTin($taxPayerName, $idType, $idValue, $fileType);

Get Taxpayer From QR Code

$qrCodeText = '4e1bc907-25b7-45b1-9620-2d671a6f9cae';

$response = $client->getTaxPayerFromQrcode($qrCodeText);

Submit JSON document

use Klsheng\Myinvois\Helper\MyInvoisHelper;
use Klsheng\Myinvois\Example\Ubl\CreateDocumentExample;
use Klsheng\Myinvois\Ubl\Constant\InvoiceTypeCodes;

$id = 'INV20240418105410';
$supplier = [
    'TIN' => 'C00000000000',
    'BRN' => '0000000-T',
];
$customer = [
    'TIN' => 'C00000000000',
    'BRN' => '0000000-T',
];
$delivery = [
    'TIN' => 'C00000000000',
    'BRN' => '0000000-T',
];

// Example contains hardcoded test data, you may need to modify it yourself
$example = new CreateDocumentExample();
$invoice = $example->createJsonDocument(InvoiceTypeCodes::INVOICE, $id, $supplier, $customer, $delivery, true, '/path/to/eInvoice.crt', '/path/to/eInvoice.key');

// If you are using p12 or pfx file, you may use following code to generate document
/*
$invoice = $example->createJsonDocument(InvoiceTypeCodes::INVOICE, $id, $supplier, $customer, $delivery, true, '/path/to/eInvoice.p12', null, 'passphrase');
*/

// In case there is DS326 error, you may use following code to re-arrange issuer key sequences
// Default sequence -> ['CN', 'E', 'OU', 'O', 'C']
/*
$invoice = $example->createJsonDocument(InvoiceTypeCodes::INVOICE, $id, $supplier, $customer, $delivery, true, '/path/to/eInvoice.p12', null, 'passphrase', ['C', 'O', 'OU', 'E', 'CN']);
*/

$documents = [];
$document = MyInvoisHelper::getSubmitDocument($id, $invoice);
$documents[] = $document;

$response = $client->submitDocument($documents);

Submit XML document

use Klsheng\Myinvois\Helper\MyInvoisHelper;
use Klsheng\Myinvois\Example\Ubl\CreateDocumentExample;
use Klsheng\Myinvois\Ubl\Constant\InvoiceTypeCodes;

$id = 'INV20240418105410';
$supplier = [
    'TIN' => 'C00000000000',
    'BRN' => '0000000-T',
];
$customer = [
    'TIN' => 'C00000000000',
    'BRN' => '0000000-T',
];
$delivery = [
    'TIN' => 'C00000000000',
    'BRN' => '0000000-T',
];

// Example contains hardcoded test data, you may need to modify it yourself
$example = new CreateDocumentExample();
$invoice = $example->createXmlDocument(InvoiceTypeCodes::INVOICE, $id, $supplier, $customer, $delivery, true, '/path/to/eInvoice.crt', '/path/to/eInvoice.key');

// If you are using p12 or pfx file, you may use following code to generate document
/*
$invoice = $example->createXmlDocument(InvoiceTypeCodes::INVOICE, $id, $supplier, $customer, $delivery, true, '/path/to/eInvoice.p12', null, 'passphrase');
*/

// In case there is DS326 error, you may use following code to re-arrange issuer key sequences
// Default sequence -> ['CN', 'E', 'OU', 'O', 'C']
/*
$invoice = $example->createXmlDocument(InvoiceTypeCodes::INVOICE, $id, $supplier, $customer, $delivery, true, '/path/to/eInvoice.p12', null, 'passphrase', ['C', 'O', 'OU', 'E', 'CN']);
*/

$documents = [];
$document = MyInvoisHelper::getSubmitDocument($id, $invoice);
$documents[] = $document;

$response = $client->submitDocument($documents);

Cancel Document

$reason = 'Customer refund';
$response = $client->cancelDocument($id, $reason);

Reject Document

$reason = 'Customer reject';
$response = $client->rejectDocument($id, $reason);

Get Recent Documents

$response = $client->getRecentDocuments();
// OR
$pageNo = 3;
$pageSize = 20;
$submissionDateFrom = '2022-11-25T01:59:10Z';
$submissionDateTo = new \DateTime('2022-12-22T23:59:59Z');
$issueDateFrom = null;
$issueDateTo = null;
$direction = 'Sent';
$status = 'Valid';
$documentType = '01';
$receiverId = 'A12345678';
$receiverIdType = 'PASSPORT';
$receiverTin = 'C2584563200';
$issuerId = null;
$issuerIdType = null;
$issuerTin = null;

$response = $client->getRecentDocuments($pageNo, $pageSize, $submissionDateFrom, $submissionDateTo, $issueDateFrom, $issueDateTo, $direction, $status, $documentType, $receiverId, $receiverIdType, $receiverTin, $issuerId, $issuerIdType, $issuerTin);

Get Submission

$response = $client->getSubmission($id);
// OR
$pageNo = 1;
$pageSize = 100;

$response = $client->getSubmission($id, $pageNo, $pageSize);

Get Document

$response = $client->getDocument($id);

Get Document Details

$response = $client->getDocumentDetail($id);

Search Documents

$submissionDateFrom = new \DateTime('2024-12-31T00:00:00Z'); 
$submissionDateTo = '2025-01-02T00:00:00Z';

$response = $client->searchDocuments(null, $submissionDateFrom, $submissionDateTo);
// OR
$id = 'F9D425P6DS7D8IU';
$submissionDateFrom = new \DateTime('2024-12-31T00:00:00Z'); 
$submissionDateTo = '2025-01-02T00:00:00Z';
$pageNo = 1;
$pageSize = 100;
$issueDateFrom = null;
$issueDateTo = null;
$direction = 'Sent';
$status = 'Valid';
$documentType = '01';
$searchQuery = null;

$response = $client->searchDocuments($id, $submissionDateFrom, $submissionDateTo, $pageNo, $pageSize, $issueDateFrom, $issueDateTo, $direction, $status, $documentType, $searchQuery);

Get Document's QR Code URL

use Klsheng\Myinvois\MyInvoisClient;

$prodMode = false;
$client = new MyInvoisClient('client_id', 'client_secret', $prodMode);

$id = '0000000000000'; // Document's UUID
$longId = '11111111111111'; // Document's Long Id
$url = $client->generateDocumentQrCodeUrl($id, $longId);

Number Formatter

In order to support different number format, a configuration is added. Please call NumberFormatConfiguration as early as possible or before build() operation.

use Klsheng\Myinvois\Ubl\Configuration\NumberFormatConfiguration;

$amount = 1436.5153;

// Default number format
// 1436.52

NumberFormatConfiguration::setPrecision(3);
// 1436.515

NumberFormatConfiguration::setPrecision(3);
NumberFormatConfiguration::setThousandsSeparator(',');
// 1,436.515

klsheng/myinvois-php-sdk 适用场景与选型建议

klsheng/myinvois-php-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17.5k 次下载、GitHub Stars 达 100, 最近一次更新时间为 2024 年 05 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「Malaysia」 「einvoicing」 「lhdn」 「myinvois」 「irbm」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 klsheng/myinvois-php-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 klsheng/myinvois-php-sdk 我们能提供哪些服务?
定制开发 / 二次开发

基于 klsheng/myinvois-php-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 17.5k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 100
  • 点击次数: 34
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 100
  • Watchers: 8
  • Forks: 49
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-05-13