承接 factpulse/sdk 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

factpulse/sdk

Composer 安装命令:

composer require factpulse/sdk

包简介

REST API for electronic invoicing in France: Factur-X (CII), UBL 2.1, AFNOR PDP/PA, electronic signatures. ## 🎯 Main Features ### 📄 Invoice Generation - **Formats**: CII XML, UBL 2.1 XML, or Factur-X PDF/A-3 - **Profiles** (CII/PDF): MINIMUM, BASIC, EN16931, EXTENDED - **UBL**: Always EN16931 comp

README 文档

README

Official PHP client for the FactPulse API - French electronic invoicing.

Features

  • Factur-X: Generation and validation of electronic invoices (MINIMUM, BASIC, EN16931, EXTENDED profiles)
  • Chorus Pro: Integration with the French public invoicing platform
  • AFNOR PDP/PA: Submission of flows compliant with XP Z12-013 standard
  • Electronic signature: PDF signing (PAdES-B-B, PAdES-B-T, PAdES-B-LT)
  • Thin HTTP wrapper: Generic post() and get() methods with automatic JWT auth and polling

Installation

composer require factpulse/sdk

Quick Start

<?php
require_once 'vendor/autoload.php';

use FactPulse\SDK\FactPulseClient;

// Create the client
$client = new FactPulseClient(
    "your_email@example.com",
    "your_password",
    "your-client-uuid"  // From dashboard: Configuration > Clients
);

// Read your source PDF
$pdfB64 = base64_encode(file_get_contents("source_invoice.pdf"));

// Generate Factur-X and submit to PDP in one call
$result = $client->post("processing/invoices/submit-complete-async", [
    "invoiceData" => [
        "number" => "INV-2025-001",
        "supplier" => [
            "name" => "ACME Corporation",
            "siret" => "12345678901234",
            "iban" => "FR7630001007941234567890185",
            "routing_address" => "12345678901234",
        ],
        "recipient" => [
            "name" => "Client Company SA",
            "siret" => "98765432109876",
            "routing_address" => "98765432109876",
        ],
        "lines" => [
            [
                "description" => "Consulting services",
                "quantity" => 10,
                "unitPrice" => 100.0,
                "vatRate" => 20.0,
            ],
        ],
    ],
    "sourcePdf" => $pdfB64,
    "profile" => "EN16931",
    "destination" => ["type" => "afnor"],
]);

// PDF is in $result["content"] (auto-polled, auto-decoded from base64)
file_put_contents("facturx_invoice.pdf", $result["content"]);

echo "Flow ID: " . $result["afnorResult"]["flowId"] . "\n";

API Methods

The SDK provides two generic methods that map directly to API endpoints:

// POST /api/v1/{path}
$result = $client->post("path/to/endpoint", ["key1" => $value1, "key2" => $value2]);

// GET /api/v1/{path}
$result = $client->get("path/to/endpoint", ["param1" => $value1]);

Common Endpoints

Endpoint Method Description
processing/invoices/submit-complete-async POST Generate Factur-X + submit to PDP
processing/generate-invoice POST Generate Factur-X XML or PDF
processing/validate-xml POST Validate Factur-X XML
processing/validate-facturx-pdf POST Validate Factur-X PDF
processing/sign-pdf POST Sign PDF with certificate
afnor/flow/v1/flows POST Submit flow to AFNOR PDP
afnor/incoming-flows/{flow_id} GET Get incoming invoice
chorus-pro/factures/soumettre POST Submit to Chorus Pro

Webhooks

Instead of polling, you can receive results via webhook by adding callbackUrl:

// Submit with webhook - returns immediately
$result = $client->post("processing/invoices/submit-complete-async", [
    "invoiceData" => $invoiceData,
    "sourcePdf" => $pdfB64,
    "destination" => ["type" => "afnor"],
    "callbackUrl" => "https://your-server.com/webhook/factpulse",
    "webhookMode" => "INLINE",  // or "DOWNLOAD_URL"
]);

$taskId = $result["taskId"];
// Result will be POSTed to your webhook URL

Webhook Receiver Example

<?php
$webhookSecret = "your-shared-secret";

function verifySignature(string $payload, string $signature): bool {
    if (strpos($signature, "sha256=") !== 0) {
        return false;
    }
    $expected = hash_hmac("sha256", $payload, $GLOBALS["webhookSecret"]);
    return hash_equals($expected, substr($signature, 7));
}

// Get raw POST body
$payload = file_get_contents("php://input");
$signature = $_SERVER["HTTP_X_WEBHOOK_SIGNATURE"] ?? "";

if (!verifySignature($payload, $signature)) {
    http_response_code(401);
    echo json_encode(["error" => "Invalid signature"]);
    exit;
}

$event = json_decode($payload, true);
$eventType = $event["event_type"];
$data = $event["data"];

if ($eventType === "submission.completed") {
    $flowId = $data["afnorResult"]["flowId"] ?? null;
    error_log("Invoice submitted: $flowId");
} elseif ($eventType === "submission.failed") {
    error_log("Submission failed: " . ($data["error"] ?? "Unknown"));
}

header("Content-Type: application/json");
echo json_encode(["status" => "received"]);

Webhook Event Types

Event Description
generation.completed Factur-X generated successfully
generation.failed Generation failed
validation.completed Validation passed
validation.failed Validation failed
signature.completed PDF signed
submission.completed Submitted to PDP/Chorus
submission.failed Submission failed

Zero-Storage Mode

Pass PDP credentials directly in the request (no server-side storage):

$result = $client->post("processing/invoices/submit-complete-async", [
    "invoiceData" => $invoiceData,
    "sourcePdf" => $pdfB64,
    "destination" => [
        "type" => "afnor",
        "flowServiceUrl" => "https://api.pdp.example.com/flow/v1",
        "tokenUrl" => "https://auth.pdp.example.com/oauth/token",
        "clientId" => "your_pdp_client_id",
        "clientSecret" => "your_pdp_client_secret",
    ],
]);

Error Handling

use FactPulse\SDK\FactPulseClient;
use FactPulse\SDK\FactPulseError;

try {
    $result = $client->post("processing/validate-xml", ["xmlContent" => $xml]);
} catch (FactPulseError $e) {
    echo "Error: " . $e->getMessage() . "\n";
    echo "Status code: " . $e->getStatusCode() . "\n";
    echo "Details: " . print_r($e->getDetails(), true) . "\n";
}

Available Helpers

The SDK provides the following helper classes:

  • FactPulseClient: Main HTTP client with auto-auth and polling
  • FactPulseError: Base exception class
  • FactPulseAuthError: Authentication failure
  • FactPulseValidationError: Validation errors with details
  • FactPulsePollingTimeout: Task polling timeout

Resources

License

MIT License - Copyright (c) 2025 FactPulse

factpulse/sdk 适用场景与选型建议

factpulse/sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 61 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 11 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 61
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 37
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: unlicense
  • 更新时间: 2025-11-13