hairacless/sephpa

为信用转账(pain.001.001.03, pain.001.002.03, pain.001.003.03)和直接借记(pain.008.001.02, pain.008.002.02, pain.008.003.02)生成 Sepa 文件

2.0.0-beta1 2018-04-22 00:42 UTC

This package is not auto-updated.

Last update: 2024-09-20 07:28:59 UTC


README

Build Status Latest Stable Version Total Downloads License Gitter

通用

Sephpa [sefa] 是一个 PHP 类,用于创建 SEPA XML 文件。生成的 XML 文件符合电子银行互联网通信标准(EBICS)的规范。

支持的文件版本

  • SEPA 信用转账
    • pain.001.001.03
    • pain.001.002.03
    • pain.001.003.03
  • SEPA 直接借记
    • pain.008.001.02
    • pain.008.001.02.austrian.003
    • pain.008.002.02
    • pain.008.003.02

要求

Sephpa 为 PHP 5.6, 7.0, 7.1, 7.2 和 HHVM 创建,并需要 SepaUtilities 1.2.4+SimpleXML。Sephpa 也应该在 PHP <5.6 下工作,但由于这些版本非常旧且不再获得任何安全更新,强烈建议不要使用低于 5.6 的 PHP。

如果您想下载正确排序的文件,还需要 zip 库,对于文档文件,您需要 SepaDocumentor

安装

Composer

只需将

{
    "require": {
        "abcaeffchen/sephpa": "~2.0.0"
    }
}

添加到您的 composer.json,并将 Composer 自动加载器包含到您的脚本中。

直接下载

您可以从这个 GitHub 页面下载 Sephpa。确保您还下载了 SepaUtilities。您应该将文件存储在一个类似以下结构的目录中

your project root
├── your_code
│   └── ...
└── vendor
    ├── Sephpa          (the Sephpa project go here)
    ├── SepaUtilities   (the SepaUtilities files go here)
    └── ...

在您的代码中,您可以通过包含以下文件来包含 Sephpa 自动加载器

vendor/Sephpa/src/autoloader.php

您还需要包含 SepaUtilities 文件,该文件应该是

vendor/SepaUtilities/src/SepaUtilities.php

总的来说,您的代码应该类似于以下内容

require PROJECT_ROOT . '/vendor/Sephpa/src/autoloader.php';
require PROJECT_ROOT . '/vendor/abcaeffchen/sepa-utilities/src/SepaUtilities.php';

您需要自行定义 PROJECT_ROOT

文档模块

Sephpa 使用 SepaDocumentor 创建文件路由单和清单。如果您对文件感兴趣,您需要在您的 composer 文件中添加

{
    "require": {
        "abcaeffchen/sepa-documentor": "~1.0.0"
    }
}

或从网站上下载它,并将其提供给 Sephpa。

创建新的 SEPA 文件

注意:这并不是为了教您 SEPA。如果您想了解更多关于 SEPA 或 SEPA 文件的信息,请向您的银行寻求帮助。您使用此库自行承担风险,并且如果出现问题,我概不负责。您应该在将文件交给您的银行之前检查文件。

信用转账

您可以使用以下方式创建新的 Sephpa 对象

$creditTransferFile = new SephpaCreditTransfer('Initiator Name',
                                               'MessageID-1234', 
                                               SephpaCreditTransfer::SEPA_PAIN_001_002_03);

您必须输入发起人名称、唯一消息 ID 和文件版本。消息 ID 必须对您提交给银行的全部 SEPA 文件都是唯一的。这是 Sephpa 不会为您检查的事情之一。目前支持的信用转账版本有

  • SEPA_PAIN_001_002_03:信用转账版本 pain.001.002.03
  • SEPA_PAIN_001_003_03:信用转账版本 pain.001.003.03

如果您不知道选择哪个版本,请咨询您的银行他们接受哪些版本。通常银行不是最快的,所以他们很可能会接受较旧的版本。

默认情况下,checkAndSanitize 设置为 true,这意味着 Sephpa 将会自动检查并净化所有输入,如果发现无法净化的情况将抛出异常。这听起来很麻烦,但如果您关闭这些检查并忽略异常,您的银行将不会接受这些文件。但强烈建议在输入时(使用 SepaUtilities)检查所有输入,然后只添加有效的数据。这样您就可以关闭 checkAndSanitize 以防止重复检查。

一旦创建了 SephpaCreditTransfer 对象,您就可以添加一个付款集合。您可以根据需要添加任意数量的付款集合。

$creditTransferCollection = $creditTransferFile->addCollection([
// required information about the debtor
    'pmtInfId'      => 'PaymentID-1234',        // ID of the payment collection
    'dbtr'          => 'Name of Debtor',        // (max 70 characters)
    'iban'          => 'DE21500500001234567897',// IBAN of the Debtor
    'bic'           => 'SPUEDE2UXXX',           // BIC of the Debtor
// optional
    'ccy'           => 'EUR',                   // Currency. Default is 'EUR'
    'btchBookg'     => 'true',                  // BatchBooking, only 'true' or 'false'
    //'ctgyPurp'      => ,                      // Category Purpose. Do not use this if you do not know how. For further information read the SEPA documentation
    'reqdExctnDt'   => '2013-11-25',            // Requested Execution Date: YYYY-MM-DD
    'ultmtDebtr'    => 'Ultimate Debtor Name'   // just an information, this do not affect the payment (max 70 characters)
]);

您可以为每个集合添加任意数量的付款。

$creditTransferCollection->addPayment([
// required information about the creditor
    'pmtId'     => 'TransferID-1234-1',     // ID of the payment (EndToEndId)
    'instdAmt'  => 0.42,                    // amount,
    'iban'      => 'DE21500500009876543210',// IBAN of the Creditor
    'bic'       => 'SPUEDE2UXXX',           // BIC of the Creditor (only required for pain.001.002.03)
    'cdtr'      => 'Name of Creditor',      // (max 70 characters)
// optional
    'ultmtCdrt' => 'Ultimate Creditor Name',// just an information, this do not affect the payment (max 70 characters)
    //'purp'      => ,                      // Do not use this if you do not know how. For further information read the SEPA documentation
    'rmtInf'    => 'Remittance Information' // unstructured information about the remittance (max 140 characters)
]);

直接借记

直接借记与信用转帐的工作方式相同,但它们的输入略有不同。

$directDebitFile = new SephpaDirectDebit('Initiator Name', 
                                         'MessageID-1235', 
                                         SephpaDirectDebit::SEPA_PAIN_008_002_02);

$directDebitCollection = $directDebitFile->addCollection([
// required information about the creditor
    'pmtInfId'      => 'PaymentID-1235',        // ID of the payment collection
    'lclInstrm'     => SepaUtilities::LOCAL_INSTRUMENT_CORE_DIRECT_DEBIT,
    'seqTp'         => SepaUtilities::SEQUENCE_TYPE_RECURRING,
    'cdtr'          => 'Name of Creditor',      // (max 70 characters)
    'iban'          => 'DE87200500001234567890',// IBAN of the Creditor
    'bic'           => 'BELADEBEXXX',           // BIC of the Creditor
    'ci'            => 'DE98ZZZ09999999999',    // Creditor-Identifier
// optional
    'ccy'           => 'EUR',                   // Currency. Default is 'EUR'
    'btchBookg'     => 'true',                  // BatchBooking, only 'true' or 'false'
    //'ctgyPurp'      => ,                      // Do not use this if you not know how. For further information read the SEPA documentation
    'ultmtCdtr'     => 'Ultimate Creditor Name',// just an information, this do not affect the payment (max 70 characters)
    'reqdColltnDt'  => '2013-11-25'             // Requested Collection Date: YYYY-MM-DD
]);
                    
$directDebitCollection->addPayment([
// required information about the debtor
    'pmtId'         => 'TransferID-1235-1',     // ID of the payment (EndToEndId)
    'instdAmt'      => 2.34,                    // amount
    'mndtId'        => 'Mandate-Id',            // Mandate ID
    'dtOfSgntr'     => '2010-04-12',            // Date of signature
    'bic'           => 'BELADEBEXXX',           // BIC of the Debtor
    'dbtr'          => 'Name of Debtor',        // (max 70 characters)
    'iban'          => 'DE87200500001234567890',// IBAN of the Debtor
// optional
    'amdmntInd'     => 'false',                 // Did the mandate change
    'elctrncSgntr'  => 'test',                  // do not use this if there is a paper-based mandate
    'ultmtDbtr'     => 'Ultimate Debtor Name',  // just an information, this do not affect the payment (max 70 characters)
    //'purp'        => ,                        // Do not use this if you not know how. For further information read the SEPA documentation
    'rmtInf'        => 'Remittance Information',// unstructured information about the remittance (max 140 characters)
    // only use this if 'amdmntInd' is 'true'. at least one must be used
    'orgnlMndtId'           => 'Original-Mandat-ID',
    'orgnlCdtrSchmeId_nm'   => 'Creditor-Identifier Name',
    'orgnlCdtrSchmeId_id'   => 'DE98AAA09999999999',
    'orgnlDbtrAcct_iban'    => 'DE87200500001234567890',// Original Debtor Account
    'orgnlDbtrAgt'          => 'SMNDA'          // only 'SMNDA' allowed if used
]);

注意:在使用 pain.008.001.02 时,键 orgnlDbtrAgt 已不再可用。它被 orgnlDbtrAgt_bic 取代,您可以输入旧的 BIC。但一般来说,您似乎可以省略 orgnlDbtrAcct_ibanorgnlDbtrAgt_bic 这两个字段,应该也能正常工作。

获取 SEPA 和文档文件

在您向付款集合添加了一些付款后,您可以通过以下方式保存完成的文件:

$creditTransferFile->store();

或直接获取,而不在服务器上保存它:

$creditTransferFile->download();

请注意,您可以传递您喜欢的文件名,但您应该仅使用文件扩展名
.xml。您还可以使用选项数组来包含文件路由条和清单。

如果您想要一次性存储或下载多个文件,则需要安装 libzip。

信贷

感谢 Hermann Herz 在调试和提供改进 Sephpa 和 SepaUtilities 的出色想法方面给予我的支持。

许可协议

根据 LGPL v3.0 许可协议授权。