Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postfinance modifications #202

Open
jk987 opened this issue Nov 25, 2024 · 5 comments
Open

Postfinance modifications #202

jk987 opened this issue Nov 25, 2024 · 5 comments

Comments

@jk987
Copy link

jk987 commented Nov 25, 2024

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.

@andrew-svirin
Copy link
Member

Hi, @jk987

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

@jk987
Copy link
Author

jk987 commented Nov 25, 2024

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.

@andrew-svirin
Copy link
Member

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
Copy link
Member

Added commit - 5680291
I am not sure that changes are successful, but here is main direction of changes.

@jk987
Copy link
Author

jk987 commented Nov 26, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants