xint0 / sw-php-client

SmarterWeb API PHP客户端

0.3.1 2024-09-02 09:52 UTC

This package is auto-updated.

Last update: 2024-09-02 15:56:20 UTC


README

描述

SmarterWeb财政凭证盖章和取消的Web服务客户端。

安装

快速安装

composer require xint0/sw-php-client

SmarterWeb PHP客户端需要一个提供psr/http-client-implementation的PSR-18 HTTP客户端,并使用php-http/discovery包来查找和安装实现(如果尚未安装)。

用法

一旦您拥有了使用SmarterWeb Web服务的令牌,您就可以创建一个Xint0\SmarterWeb\Api类的实例

盖章

从文件中读取的字符串盖章的财政凭证

use Xint0\SmarterWeb\Api;
use Xint0\SmarterWeb\Exceptions\ApiException;

$token = 'your_smarterweb_security_token';
$api = new Api($token);

$xml = file_get_contents('path_to_signed_fiscal_voucher.xml');

try {
    /*
     * Calls stamp method requesting version 1 response
     * see https://developers.sw.com.mx/knowledge-base/versiones-de-respuesta-timbrado/
     */
    $response = $api->stamp($xml);

    if ($response->success) {
        $fiscal_voucher_stamp_xml_fragment = $response->data['tfd'];
    } else {
        /**
         * In case service returns an error response more information is available
         * in message and messageDetail properties.
         * @see https://developers.sw.com.mx/knowledge-base/cancelacion-cfdi/
         */
        $message = $response->message;
        $messageDetail = $response->messageDetail;
    }
} catch (ApiException $exception) {
    /**
     * In case an error occurred when sending the request or receiving the response
     * an ApiException is thrown
     */
    $message = $exception->getMessage();
}

取消

使用已盖章的取消请求XML文件的资源请求财政凭证取消

use Xint0\SmarterWeb\Api;
use Xint0\SmarterWeb\Exceptions\ApiException;

$token = 'your_smarterweb_security_token';
$api = new Api($token);

$cancellation_request_xml = fopen('path_to_signed_cancellation_request.xml');

try {
    $response = $api->cancel($cancellation_request_xml);

    if ($response->success) {
        $data = $response->data;
        /**
         * The response data array has two keys: acuse and uuid.
         * The acuse key value is the cancellation request acknowledgement XML.
         * The uuid key value is and array with each of the fiscal voucher folios
         * included in the request as key and the cancellation request code as value.
         * @see https://developers.sw.com.mx/knowledge-base/cancelacion-cfdi/
         */
        $fiscal_voucher_cancellation_request_acknowledgement_xml = $data['acuse'];
        $individual_fiscal_voucher_cancellation_request_code = $data['uuid']['3EAEABC9-EA41-4627-9609-C6856B78E2B1'];
    } else {
        /**
         * In case service returns an error response more information is available
         * in message and messageDetail properties.
         * @see https://developers.sw.com.mx/knowledge-base/cancelacion-cfdi/
         */
        $message = $response->message;
        $messageDetail = $response->messageDetail;
    }
} catch (ApiException $exception) {
    /**
     * In case an error occurred when sending the request or receiving the response
     * an ApiException is thrown
     */
    $message = $exception->getMessage();
} finally {
    fclose($cancellation_request_xml);
}

支持

如果您需要帮助,您可以在以下位置创建问题:https://gitlab.com/xint0-open-source/sw-php-client/-/issues

路线图

方法是否实现
盖章
取消

贡献

您可以分叉项目并提交合并请求。

作者和致谢

向为项目做出贡献的人表示感谢。

许可证

此组件是在MIT许可证下开源的。