ebics-client-php icon indicating copy to clipboard operation
ebics-client-php copied to clipboard

Postfinance modifications

Open jk987 opened this issue 1 year ago • 6 comments

Hello, I'm testing your awesome library with Swiss Postfinance and I've following modifications. Please don't ask me to do some pull requests, because I'm not very familiar with git.

file CustomerSwissCreditTransferBuilder.php public function createInstance:

        $xmlReqdExctnDtDt = $this->instance->createElement('Dt');
        $xmlReqdExctnDtDt->nodeValue = $now->format('Y-m-d');

        $xmlReqdExctnDt = $this->instance->createElement('ReqdExctnDt');
        //$xmlReqdExctnDt->nodeValue = $now->format('Y-m-d');
        $xmlReqdExctnDt->appendChild($xmlReqdExctnDtDt);
...
        //$xmlBIC = $this->instance->createElement('BIC');
        $xmlBIC = $this->instance->createElement('BICFI');

Otherwise Postfinance didn't accept the file.

private function createCreditTransferTransactionElement:

    //private function createCreditTransferTransactionElement(float $amount): DOMElement
    private function createCreditTransferTransactionElement(float $amount, string $instrId = null): DOMElement
...
        if (!is_null($instrId)) {
            $xmlInstrId = $this->instance->createElement('InstrId');
            $xmlInstrId->nodeValue = $instrId;
            $xmlPmtId->appendChild($xmlInstrId);
        }

I put there customer id.

file DocumentFactory.php public function createMultiple:

            if (substr($key, -4) == ".xml")
                $documents[$key] = $this->create($content);
            else
                $documents[$key] = $content;

I get zip file with xml files and txt file inside from Postfinance. (Actually I get more zip files merged together but it is another story.)

file RequestFactoryV3.php

    public function createXTD(
        DateTimeInterface $dateTime,
        DateTimeInterface $startDateTime = null,
        DateTimeInterface $endDateTime = null
    ): Request {
        $btfContext = new BTDContext();
        $btfContext->setServiceName('OTH');
        $btfContext->setScope('BIL');
        $btfContext->setMsgName('msc');
        //$btfContext->setMsgNameVersion('04');
        $btfContext->setContainerType('ZIP');
        $btfContext->setServiceOption('CH002LME');
        return $this->createBTD($dateTime, $btfContext, $startDateTime, $endDateTime);
    }

It is a special Postfinance command supposed for testing. (Z52/Z54 doesn't work for me. XTD should be similar.)

    public function createXE2(DateTimeInterface $dateTime, UploadTransaction $transaction, bool $withES): Request
    {
        //throw new LogicException('Method not implemented yet for EBICS 3.0');
        $btfContext = new BTUContext();
        $btfContext->setServiceName('MCT');
        $btfContext->setScope('CH');
        $btfContext->setMsgName('pain.001');
        $btfContext->setMsgNameVersion('09');
        $btfContext->setFileName('xe2.pain001.xml');
        return $this->createBTU($btfContext, $dateTime, $transaction);
    }

Taken from XE3 and bit modified according to Postfinance documentation.

file EbicsClient.php:

    public function XTD(
        DateTimeInterface $dateTime = null,
        DateTimeInterface $startDateTime = null,
        DateTimeInterface $endDateTime = null
    ): DownloadOrderResult {
        if (null === $dateTime) {
            $dateTime = new DateTime();
        }

        $transaction = $this->downloadTransaction(
            function () use ($dateTime, $startDateTime, $endDateTime) {
                return $this->requestFactory->createXTD(
                    $dateTime,
                    $startDateTime,
                    $endDateTime
                );
            }
        );

        return $this->createDownloadOrderResult($transaction, self::FILE_PARSER_FORMAT_ZIP_FILES);
    }

I don't know if you accept these changes, I only wanted to help a little.

jk987 avatar Nov 25 '24 14:11 jk987

Hi, @jk987

Thanks for your comment. Please tell what version of the library do you use.

andrew-svirin avatar Nov 25 '24 15:11 andrew-svirin

I'm not sure. I tried to use composer, but that's a new thing for me. In installed.jsonj I can see v2.2.1.

jk987 avatar Nov 25 '24 15:11 jk987

I think that will do next updates in library for next release:

  1. Make CustomerSwissCreditTransferBuilder deprecated. Instead use CustomerCreditTransferBuilder with different options. And CustomerCreditTransferBuilder should be refactored to support CustomerSwissCreditTransferBuilder.
  2. And will remove createMultiple and response just keyed content without transforming to Document object. It is really necessary to fix.
  3. With new order types is a lot of work to support, so I am adding only when it really needed or prepared MR with tests.

andrew-svirin avatar Nov 25 '24 15:11 andrew-svirin

Added commit - https://github.com/andrew-svirin/ebics-client-php/commit/5680291121b98c64a80d419096b5b0608f4ebe78 I am not sure that changes are successful, but here is main direction of changes.

andrew-svirin avatar Nov 25 '24 16:11 andrew-svirin

Well, I'm too dumb to judge your commit and too lazy to test it right now.

Meanwhile I'll use this place to leave a note (because this is the best open source library I've found) that for Credit Suisse in the XTD command there must be ServiceOption = 'CH002LMF' instead of 'CH002LME' which was for Postfinance.

XE2 works without any change for Credit Suisse.

I also implemented Z01 which works for both Postfinance and Credit Suisse.

    public function createZ01(
        DateTimeInterface $dateTime,
        DateTimeInterface $startDateTime = null,
        DateTimeInterface $endDateTime = null
    ): Request {
        $btfContext = new BTDContext();
        $btfContext->setServiceName('PSR');
        $btfContext->setScope('CH');
        $btfContext->setMsgName('pain.002');
        $btfContext->setMsgNameVersion('10');
        $btfContext->setContainerType('ZIP');
        return $this->createBTD($dateTime, $btfContext, $startDateTime, $endDateTime);
    }

Difference between XTD and Z01 is that Z01 returns single zip full of short xml files, while XTD returns one file containing multiple zips glued/merged/appended together.

jk987 avatar Nov 26 '24 14:11 jk987

I will use this old thread for other notes.

Current observations with Raiffeisenbank: Vertrags-ID is PartnerID Teilnehmer-ID is UserID My colleague used also some SystemID in his library which didn't mind in Postfinance, but in Raiffeisen it did. Luckilly there is not such "SystemID" in your library.

jk987 avatar Mar 25 '25 12:03 jk987

SystemId will be a part of release 3.0.2

andrew-svirin avatar Aug 13 '25 18:08 andrew-svirin