/**
  * calculates the sum of all payments in this collection
  *
  * @param mixed[] $paymentInfo needed keys: 'pmtId', 'instdAmt', 'mndtId', 'dtOfSgntr', 'bic',
  *                             'dbtr', 'iban';
  *                             optional keys: 'amdmntInd', 'orgnlMndtId', 'orgnlCdtrSchmeId_nm',
  *                             'orgnlCdtrSchmeId_id', 'orgnlDbtrAcct_iban', 'orgnlDbtrAgt',
  *                             'elctrncSgntr', 'ultmtDbtr', 'purp', 'rmtInf'
  * @throws SephpaInputException
  * @return void
  */
 public function addPayment(array $paymentInfo)
 {
     if (!SepaUtilities::checkRequiredPaymentKeys($paymentInfo, self::VERSION)) {
         throw new SephpaInputException('One of the required inputs \'pmtId\', \'instdAmt\', \'mndtId\', \'dtOfSgntr\', \'bic\', \'dbtr\', \'iban\' is missing.');
     }
     if ($this->checkAndSanitize) {
         $checkResult = SepaUtilities::checkAndSanitizeAll($paymentInfo, $this->sanitizeFlags, array('version' => self::VERSION));
         if ($checkResult !== true) {
             throw new SephpaInputException('The values of ' . $checkResult . ' are invalid.');
         }
         if (!empty($paymentInfo['amdmntInd']) && $paymentInfo['amdmntInd'] === 'true') {
             if (SepaUtilities::containsNotAnyKey($paymentInfo, array('orgnlMndtId', 'orgnlCdtrSchmeId_nm', 'orgnlCdtrSchmeId_id', 'orgnlDbtrAcct_iban', 'orgnlDbtrAgt'))) {
                 throw new SephpaInputException('You set \'amdmntInd\' to \'true\', so you have to set also at least one of the following inputs: \'orgnlMndtId\', \'orgnlCdtrSchmeId_nm\', \'orgnlCdtrSchmeId_id\', \'orgnlDbtrAcct_iban\', \'orgnlDbtrAgt\'.');
             }
             if (!empty($paymentInfo['orgnlDbtrAgt']) && $paymentInfo['orgnlDbtrAgt'] === 'SMNDA' && $this->debitInfo['seqTp'] !== SepaUtilities::SEQUENCE_TYPE_FIRST) {
                 throw new SephpaInputException('You set \'amdmntInd\' to \'true\' and \'orgnlDbtrAgt\' to \'SMNDA\', \'seqTp\' has to be \'' . SepaUtilities::SEQUENCE_TYPE_FIRST . '\'.');
             }
         }
         // IBAN and BIC can belong to each other?
         if (!SepaUtilities::crossCheckIbanBic($paymentInfo['iban'], $paymentInfo['bic'])) {
             throw new SephpaInputException('IBAN and BIC do not belong to each other.');
         }
     }
     $this->payments[] = $paymentInfo;
 }
 /**
  * Adds a payment to the payment collection
  *
  * @param mixed[] $paymentInfo needed keys: 'pmtId', 'instdAmt', 'iban', 'bic', 'cdtr';
  *                             optional keys: 'ultmtCdrt', 'purp', 'rmtInf'
  * @throws SephpaInputException
  * @return void
  */
 public function addPayment(array $paymentInfo)
 {
     if ($this->checkAndSanitize) {
         if (!SepaUtilities::checkRequiredPaymentKeys($paymentInfo, self::VERSION)) {
             throw new SephpaInputException('One of the required inputs \'pmtId\', \'instdAmt\', \'iban\', \'bic\', \'cdtr\' is missing.');
         }
         $checkResult = SepaUtilities::checkAndSanitizeAll($paymentInfo, $this->sanitizeFlags);
         if ($checkResult !== true) {
             throw new SephpaInputException('The values of ' . $checkResult . ' are invalid.');
         }
         // IBAN and BIC can belong to each other?
         if (!SepaUtilities::crossCheckIbanBic($paymentInfo['iban'], $paymentInfo['bic'])) {
             throw new SephpaInputException('IBAN and BIC do not belong to each other.');
         }
     }
     $this->payments[] = $paymentInfo;
 }
示例#3
0
文件: Sephpa.php 项目: KoenLav/Sephpa
 /**
  * Generates the XML file from the given data
  *
  * @param string $creDtTm You should not use this
  * @throws SephpaInputException
  * @return string Just the xml code of the file
  */
 public function generateXml($creDtTm = '')
 {
     if (empty($creDtTm) || SepaUtilities::checkCreateDateTime($creDtTm) === false) {
         $now = new \DateTime();
         $creDtTm = $now->format('Y-m-d\\TH:i:s');
     }
     $totalNumberOfTransaction = $this->getNumberOfTransactions();
     if ($totalNumberOfTransaction === 0) {
         throw new SephpaInputException('No Payments provided.');
     }
     $fileHead = $this->xml->addChild($this->xmlType);
     $grpHdr = $fileHead->addChild('GrpHdr');
     $grpHdr->addChild('MsgId', $this->msgId);
     $grpHdr->addChild('CreDtTm', $creDtTm);
     $grpHdr->addChild('NbOfTxs', $totalNumberOfTransaction);
     $grpHdr->addChild('CtrlSum', sprintf("%01.2f", $this->getCtrlSum()));
     $grpHdr->addChild('InitgPty')->addChild('Nm', $this->initgPty);
     foreach ($this->paymentCollections as $paymentCollection) {
         // ignore empty collections
         if ($paymentCollection->getNumberOfTransactions() === 0) {
             continue;
         }
         $pmtInf = $fileHead->addChild('PmtInf');
         $paymentCollection->generateCollectionXml($pmtInf);
     }
     return $this->xml->asXML();
 }
 /**
  * calculates the sum of all payments in this collection
  *
  * @param mixed[] $paymentInfo needed keys: 'pmtId', 'instdAmt', 'mndtId', 'dtOfSgntr', 'bic',
  *                             'dbtr', 'iban';
  *                             optional keys: 'amdmntInd', 'orgnlMndtId', 'orgnlCdtrSchmeId_nm',
  *                             'orgnlCdtrSchmeId_id', 'orgnlDbtrAcct_iban', 'orgnlDbtrAgt',
  *                             'elctrncSgntr', 'ultmtDbtr', 'purp', 'rmtInf'
  * @throws SephpaInputException
  * @return void
  */
 public function addPayment(array $paymentInfo)
 {
     if ($this->checkAndSanitize) {
         if (!SepaUtilities::checkRequiredPaymentKeys($paymentInfo, self::VERSION)) {
             throw new SephpaInputException('One of the required inputs \'pmtId\', \'instdAmt\', \'mndtId\', \'dtOfSgntr\', \'dbtr\', \'iban\' is missing.');
         }
         $bicRequired = !SepaUtilities::isEEATransaction($this->cdtrIban, $paymentInfo['iban']);
         $checkResult = SepaUtilities::checkAndSanitizeAll($paymentInfo, $this->sanitizeFlags, array('allowEmptyBic' => $bicRequired, 'version' => self::VERSION));
         if ($checkResult !== true) {
             throw new SephpaInputException('The values of ' . $checkResult . ' are invalid.');
         }
         if (!empty($paymentInfo['amdmntInd']) && $paymentInfo['amdmntInd'] === 'true') {
             if (SepaUtilities::containsNotAnyKey($paymentInfo, array('orgnlMndtId', 'orgnlCdtrSchmeId_nm', 'orgnlCdtrSchmeId_id', 'orgnlDbtrAcct_iban', 'orgnlDbtrAgt'))) {
                 throw new SephpaInputException('You set \'amdmntInd\' to \'true\', so you have to set also at least one of the following inputs: \'orgnlMndtId\', \'orgnlCdtrSchmeId_nm\', \'orgnlCdtrSchmeId_id\', \'orgnlDbtrAcct_iban\', \'orgnlDbtrAgt\'.');
             }
             if (!empty($paymentInfo['orgnlDbtrAgt']) && $paymentInfo['orgnlDbtrAgt'] === 'SMNDA' && $this->debitInfo['seqTp'] !== SepaUtilities::SEQUENCE_TYPE_RECURRING && $this->debitInfo['seqTp'] !== SepaUtilities::SEQUENCE_TYPE_FIRST) {
                 throw new SephpaInputException('You set \'amdmntInd\' to \'true\' and \'orgnlDbtrAgt\' to \'SMNDA\', \'seqTp\' has to be \'' . SepaUtilities::SEQUENCE_TYPE_FIRST . '\' or \'' . SepaUtilities::SEQUENCE_TYPE_RECURRING . '\'.');
             }
         }
         // IBAN and BIC can belong to each other?
         if (!empty($paymentInfo['bic']) && !SepaUtilities::crossCheckIbanBic($paymentInfo['iban'], $paymentInfo['bic'])) {
             throw new SephpaInputException('IBAN and BIC do not belong to each other.');
         }
     }
     // adjustments
     // local instrument COR1 got included into CORE.
     if ($this->debitInfo['lclInstrm'] === SepaUtilities::LOCAL_INSTRUMENT_CORE_DIRECT_DEBIT_D_1) {
         $this->debitInfo['lclInstrm'] = SepaUtilities::LOCAL_INSTRUMENT_CORE_DIRECT_DEBIT;
     }
     // it is no longer required to use FRST as sequence type for the first direct debit
     // instead it is recommended to use RCUR
     if ($this->debitInfo['seqTp'] === SepaUtilities::SEQUENCE_TYPE_FIRST) {
         $this->debitInfo['seqTp'] = SepaUtilities::SEQUENCE_TYPE_RECURRING;
     }
     $this->payments[] = $paymentInfo;
 }
 /**
  * Adds a payment to the payment collection
  *
  * @param mixed[] $paymentInfo needed keys: 'pmtId', 'instdAmt', 'iban', 'bic', 'cdtr';
  *                             optional keys: 'ultmtCdrt', 'purp', 'rmtInf'
  * @throws SephpaInputException
  * @return void
  */
 public function addPayment(array $paymentInfo)
 {
     if ($this->checkAndSanitize) {
         if (!SepaUtilities::checkRequiredPaymentKeys($paymentInfo, self::VERSION)) {
             throw new SephpaInputException('One of the required inputs \'pmtId\', \'instdAmt\', \'iban\', \'cdtr\' is missing.');
         }
         $bicRequired = !SepaUtilities::isNationalTransaction($this->dbtrIban, $paymentInfo['iban']) && $this->today <= SepaUtilities::BIC_REQUIRED_THRESHOLD;
         $checkResult = SepaUtilities::checkAndSanitizeAll($paymentInfo, $this->sanitizeFlags, array('allowEmptyBic' => $bicRequired));
         if ($checkResult !== true) {
             throw new SephpaInputException('The values of ' . $checkResult . ' are invalid.');
         }
         // IBAN and BIC can belong to each other?
         if (!empty($paymentInfo['bic']) && !SepaUtilities::crossCheckIbanBic($paymentInfo['iban'], $paymentInfo['bic'])) {
             throw new SephpaInputException('IBAN and BIC do not belong to each other.');
         }
     }
     $this->payments[] = $paymentInfo;
 }
require_once '../src/SepaUtilities.php';
$results = array();
if (isset($_POST['check'])) {
    foreach ($_POST as $field => $input) {
        if (!in_array($field, array('pmtinfid', 'dbtr', 'iban', 'bic', 'ccy', 'btchbookg', 'ultmtdebtr', 'pmtid', 'instdamt', 'cdtr', 'ultmtcdrt', 'rmtinf', 'ci'))) {
            continue;
        }
        $results[$field] = SepaUtilities::check($field, $input);
    }
}
if (isset($_POST['sanitize'])) {
    foreach ($_POST as $field => $input) {
        if (!in_array($field, array('cdtr', 'dbtr', 'rmtinf', 'ultmtcdrt', 'ultmtdebtr'))) {
            continue;
        }
        $results[$field] = SepaUtilities::sanitize($field, $input);
    }
}
?>

<!doctype html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Document</title>
    <style>
        input[type=text]
        {
            width: 20em;
            padding: 3px;
            margin: 3px;
 public function testCheckAmountFormat()
 {
     $this->assertSame(1234.56, SepaUtilities::check('instdamt', '1,234.56'));
     $this->assertSame(1234.56, SepaUtilities::check('instdamt', '1234.56'));
     $this->assertSame(1234.56, SepaUtilities::check('instdamt', '1234,56'));
     $this->assertSame(1234.56, SepaUtilities::check('instdamt', '1.234,56'));
     $this->assertFalse(SepaUtilities::check('instdamt', '0.005'));
     $this->assertFalse(SepaUtilities::check('instdamt', '9999999999999.99'));
     $this->assertFalse(SepaUtilities::check('instdamt', 0.008999999999999999));
 }