public function testDirectDebit00800302() { // generate a SepaDirectDebit object (pain.008.002.02). $directDebitFile = new SephpaDirectDebit('Initiator Name', 'MessageID-1235', SephpaDirectDebit::SEPA_PAIN_008_003_02); // at least one in every SEPA file. No limit. $directDebitCollection = $directDebitFile->addCollection(array('pmtInfId' => 'PaymentID-1235', 'lclInstrm' => SepaUtilities::LOCAL_INSTRUMENT_CORE_DIRECT_DEBIT, 'seqTp' => SepaUtilities::SEQUENCE_TYPE_RECURRING, 'cdtr' => 'Name of Creditor', 'iban' => 'DE87200500001234567890', 'bic' => 'BELADEBEXXX', 'ci' => 'DE98ZZZ09999999999', 'ccy' => 'EUR', 'btchBookg' => 'true', 'ultmtCdtr' => 'Ultimate Creditor Name', 'reqdColltnDt' => '2013-11-25')); // at least one in every DirectDebitCollection. No limit. $directDebitCollection->addPayment(array('pmtId' => 'TransferID-1235-1', 'instdAmt' => 2.34, 'mndtId' => 'Mandate-Id', 'dtOfSgntr' => '2010-04-12', 'bic' => 'BELADEBEXXX', 'dbtr' => 'Name of Debtor', 'iban' => 'DE87200500001234567890', 'amdmntInd' => 'false', 'ultmtDbtr' => 'Ultimate Debtor Name', 'rmtInf' => 'Remittance Information', 'orgnlMndtId' => 'Original-Mandat-ID', 'orgnlCdtrSchmeId_nm' => 'Creditor-Identifier Name', 'orgnlCdtrSchmeId_id' => 'DE98AAA09999999999', 'orgnlDbtrAcct_iban' => 'DE87200500001234567890', 'orgnlDbtrAgt' => 'SMNDA')); $this->assertXmlStringEqualsXmlFile(__DIR__ . '/directDebitValid00800302.xsd', $directDebitFile->generateXml('2014-10-19T00:38:44')); }
private function download() { $this->template = FALSE; // ID único de la remesa: id de remesa + fecha de generación $paymentInfoId = $this->empresa->cifnif . '-' . date('dmy-H:i', strtotime($this->remesa->fecha)); // Formato de documento a utilizar $sepaPAIN = SephpaDirectDebit::SEPA_PAIN_008_001_02; // Comprobar y sanear valores, permite evitar validación de IBAN, útil para pruebas con IBANs falsos $checkAndSanitize = FALSE; /** * normal direct debit : LOCAL_INSTRUMENT_CORE_DIRECT_DEBIT = 'CORE'; * urgent direct debit : LOCAL_INSTRUMENT_CORE_DIRECT_DEBIT_D_1 = 'COR1'; * business direct debit : LOCAL_INSTRUMENT_BUSINESS_2_BUSINESS = 'B2B'; */ $localInstrument = SepaUtilities::LOCAL_INSTRUMENT_CORE_DIRECT_DEBIT; /** * first direct debit : SEQUENCE_TYPE_FIRST = 'FRST'; * recurring direct debit : SEQUENCE_TYPE_RECURRING = 'RCUR'; * one time direct debit : SEQUENCE_TYPE_ONCE = 'OOFF'; * final direct debit : SEQUENCE_TYPE_FINAL = 'FNAL'; */ $sequenceType = SepaUtilities::SEQUENCE_TYPE_RECURRING; $directDebitFile = new SephpaDirectDebit($this->empresa->nombre, $paymentInfoId, $sepaPAIN, $checkAndSanitize); $creationDateTime = date('Y-m-d\\TH:i:s', strtotime($this->remesa->fecha)); // at least one in every SEPA file. No limit. $directDebitCollection = $directDebitFile->addCollection(array('pmtInfId' => $paymentInfoId, 'lclInstrm' => $localInstrument, 'seqTp' => $sequenceType, 'cdtr' => substr($this->empresa->nombre, 0, 70), 'iban' => $this->remesa->iban, 'bic' => $this->remesa->swift, 'ci' => $this->empresa->cifnif, 'ccy' => $this->remesa->coddivisa, 'reqdColltnDt' => date('Y-m-d', strtotime($this->remesa->fechacargo)))); // at least one in every DirectDebitCollection. No limit. foreach ($this->resultados as $recibo) { if (TRUE) { $directDebitCollection->addPayment(array('pmtId' => $recibo->codigo, 'instdAmt' => $recibo->importe, 'mndtId' => $recibo->codigo, 'dtOfSgntr' => date('Y-m-d', strtotime($recibo->fecha)), 'dbtr' => substr($recibo->nombrecliente, 0, 70), 'bic' => $recibo->swift, 'iban' => $recibo->iban, 'rmtInf' => $recibo->codigo)); } } $this->remesa->estado = "En trámite"; if (!$this->remesa->save()) { $this->new_error_msg("¡Imposible modificar la remesa!"); } $directDebitFile->downloadSepaFile('Remesa_' . $this->remesa->idremesa . '_' . $this->remesa->fecha . '_SEPA_' . $localInstrument . '' . '.xml', $creationDateTime, $this->empresa->cifnif); }
<?php /* * This is just an example. Please read the documentation * of the SEPA file format to learn more about using SEPA files. */ use AbcAeffchen\Sephpa\SephpaCreditTransfer; use AbcAeffchen\SepaUtilities\SepaUtilities; use AbcAeffchen\Sephpa\SephpaDirectDebit; require_once '../src/Sephpa.php'; // generate a SepaCreditTransfer object (pain.001.002.03). $creditTransferFile = new SephpaCreditTransfer('Initiator Name', 'MessageID-1234', SephpaCreditTransfer::SEPA_PAIN_001_003_03); // at least one in every SEPA file $creditTransferCollection = $creditTransferFile->addCollection(array('pmtInfId' => 'PaymentID-1234', 'dbtr' => 'Name of Debtor2', 'iban' => 'DE21500500001234567897', 'bic' => 'BELADEBEXXX', 'ccy' => 'EUR', 'btchBookg' => 'true', 'reqdExctnDt' => '2013-11-25', 'ultmtDebtr' => 'Ultimate Debtor Name')); // at least one in every CreditTransferCollection $creditTransferCollection->addPayment(array('pmtId' => 'TransferID-1234-1', 'instdAmt' => 1.14, 'iban' => 'DE21500500009876543210', 'bic' => 'SPUEDE2UXXX', 'cdtr' => 'Name of Creditor', 'ultmtCdrt' => 'Ultimate Creditor Name', 'rmtInf' => 'Remittance Information')); $creditTransferFile->storeSepaFile(); // generate a SepaDirectDebit object (pain.008.002.02). $directDebitFile = new SephpaDirectDebit('Initiator Name', 'MessageID-1235', SephpaDirectDebit::SEPA_PAIN_008_003_02); // at least one in every SEPA file. No limit. $directDebitCollection = $directDebitFile->addCollection(array('pmtInfId' => 'PaymentID-1235', 'lclInstrm' => SepaUtilities::LOCAL_INSTRUMENT_CORE_DIRECT_DEBIT, 'seqTp' => SepaUtilities::SEQUENCE_TYPE_RECURRING, 'cdtr' => 'Name of Creditor', 'iban' => 'DE87200500001234567890', 'bic' => 'BELADEBEXXX', 'ci' => 'DE98ZZZ09999999999', 'ccy' => 'EUR', 'btchBookg' => 'true', 'ultmtCdtr' => 'Ultimate Creditor Name', 'reqdColltnDt' => '2013-11-25')); // at least one in every DirectDebitCollection. No limit. $directDebitCollection->addPayment(array('pmtId' => 'TransferID-1235-1', 'instdAmt' => 2.34, 'mndtId' => 'Mandate-Id', 'dtOfSgntr' => '2010-04-12', 'bic' => 'BELADEBEXXX', 'dbtr' => 'Name of Debtor', 'iban' => 'DE87200500001234567890', 'amdmntInd' => 'false', 'ultmtDbtr' => 'Ultimate Debtor Name', 'rmtInf' => 'Remittance Information', 'orgnlMndtId' => 'Original-Mandat-ID', 'orgnlCdtrSchmeId_nm' => 'Creditor-Identifier Name', 'orgnlCdtrSchmeId_id' => 'DE98AAA09999999999', 'orgnlDbtrAcct_iban' => 'DE87200500001234567890', 'orgnlDbtrAgt' => 'SMNDA')); $directDebitFile->storeSepaFile();
/** * @param int $version Use SephpaDirectDebit::SEPA_PAIN_008_* constants * @param bool $addBIC * @param bool $addOptionalData * @param bool $checkAndSanitize * @return DOMDocument */ private function getDirectDebitFile($version, $addBIC, $addOptionalData, $checkAndSanitize) { $collectionData = array('pmtInfId' => 'PaymentID-1235', 'lclInstrm' => SepaUtilities::LOCAL_INSTRUMENT_CORE_DIRECT_DEBIT, 'seqTp' => SepaUtilities::SEQUENCE_TYPE_FIRST, 'cdtr' => 'Name of Creditor', 'iban' => 'DE87200500001234567890', 'ci' => 'DE98ZZZ09999999999'); if ($addBIC) { $collectionData['bic'] = 'BELADEBEXXX'; } if ($addOptionalData) { $collectionData['ccy'] = 'EUR'; // Currency. Default is 'EUR' $collectionData['btchBookg'] = 'true'; // BatchBooking, only 'true' or 'false' $collectionData['ultmtCdtr'] = 'Ultimate Creditor Name'; // just an information, this do not affect the payment (max 70 characters) $collectionData['reqdColltnDt'] = '2013-11-25'; // Date: YYYY-MM-DD } $paymentData = array('pmtId' => 'TransferID-1235-1', 'instdAmt' => 2.34, 'mndtId' => 'Mandate-Id', 'dtOfSgntr' => '2010-04-12', 'dbtr' => 'Name of Debtor', 'iban' => 'DE87200500001234567890'); if ($addBIC) { $paymentData['bic'] = 'BELADEBEXXX'; } if ($addOptionalData) { $paymentData['amdmntInd'] = 'true'; // Did the mandate change $paymentData['ultmtDbtr'] = 'Ultimate Debtor Name'; // just an information, this do not affect the payment (max 70 characters) $paymentData['rmtInf'] = 'Remittance Information'; // unstructured information about the remittance (max 140 characters) // only use this if 'amdmntInd' is 'true'. at least one must be used $paymentData['orgnlMndtId'] = 'Original-Mandat-ID'; $paymentData['orgnlCdtrSchmeId_nm'] = 'Creditor-Identifier Name'; $paymentData['orgnlCdtrSchmeId_id'] = 'DE98AAA09999999999'; $paymentData['orgnlDbtrAcct_iban'] = 'DE87200500001234567890'; // Original Debtor Account $paymentData['orgnlDbtrAgt'] = 'SMNDA'; // only 'SMNDA' allowed if used } // generate a SepaDirectDebit object (pain.008.002.02). $directDebitFile = new SephpaDirectDebit('Initiator Name', 'MessageID-1235', $version, $checkAndSanitize); $directDebitCollection = $directDebitFile->addCollection($collectionData); $directDebitCollection->addPayment($paymentData); $domDoc = new DOMDocument(); $domDoc->loadXML($directDebitFile->generateXml('2014-10-19T00:38:44')); return $domDoc; }