cvs: pear /Payment_Clieop clieop.php clieop_transaction.php /Payment_Clieop/Samples creditor.php debtor.php

From: Date: Sat, 29 Mar 2008 00:52:29 +0000
Subject: cvs: pear /Payment_Clieop clieop.php clieop_transaction.php /Payment_Clieop/Samples creditor.php debtor.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-51730@lists.php.net to get a copy of this message
walter Sat Mar 29 00:52:29 2008 UTC Modified files: /pear/Payment_Clieop clieop.php clieop_transaction.php /pear/Payment_Clieop/Samples creditor.php debtor.php Log: Fixed Bug #12402 Amount for transaction may not be negative

http://cvs.php.net/viewvc.cgi/pear/Payment_Clieop/clieop.php?r1=1.17&r2=1.18&diff_format=u Index: pear/Payment_Clieop/clieop.php diff -u pear/Payment_Clieop/clieop.php:1.17 pear/Payment_Clieop/clieop.php:1.18 --- pear/Payment_Clieop/clieop.php:1.17 Sat Mar 29 00:21:13 2008 +++ pear/Payment_Clieop/clieop.php Sat Mar 29 00:52:29 2008 @@ -16,20 +16,29 @@ // | Authors: Dave Mertens <dmertens@zyprexia.com> | // +----------------------------------------------------------------------+ // -// $Id: clieop.php,v 1.17 2008/03/29 00:21:13 walter Exp $ +// $Id: clieop.php,v 1.18 2008/03/29 00:52:29 walter Exp $ /* Please note that public function names are partly in Dutch. This is because also the clieop data strings has dutch names. (batchvoorloopinfo, transactieinfo, etc). */ + /** -* Main clieop class -* -* @version $Revision: 1.17 $ -* @access public -* @author Dave Mertens <dmertens@zyprexia.com> -* @package Payment_Clieop -*/ + * require PEAR + * + * This package depends on PEAR to raise errors. + */ +require_once 'PEAR.php'; + + +/** + * Main clieop class + * + * @version $Revision: 1.18 $ + * @access public + * @author Dave Mertens <dmertens@zyprexia.com> + * @package Payment_Clieop + */ class ClieopPayment extends clieop_baseobject { /** @@ -78,12 +87,6 @@ * @var integer * @access private */ - var $_TransactionCount; - - /** - * @var integer - * @access private - */ var $_TotalAmount; /** @@ -140,65 +143,87 @@ * Adds a payment record to the clieop file * @param object paymentObject - Instance of transactionPayment * @access public - * @return void + * @return mixed true on success or PEAR_Error object */ function addPayment($paymentObject) { + if (is_null($paymentObject)) + { + return PEAR::raiseError('Payment object cannot be null'); + } + //Only one type of transaction is allowed in a clieop - if ($this->_TransactionType == $paymentObject->getPaymentType()) + if ($this->_TransactionType != $paymentObject->getPaymentType()) { - //transactieinfo (0100) - $text = $this->writeTransactieInfo($paymentObject->getTransactionType(), - $paymentObject->getAmount(), - $paymentObject->getAccountNumberSource(), - $paymentObject->getAccountNumberDest()); - - // Debtor name ans city - if (strtoupper($this->_TransactionType) == "DEBTOR") - { - //name of debtor (0110) - $text .= $this->writeNaambetalerInfo($paymentObject->getName()); - - //city of debtor (0113) - $text .= $this->writeWoonplaatsbetalerInfo($paymentObject->getCity()); - } - - //betalings kenmerk (0150) - $text .= $this->writeBetalingskenmerkInfo($paymentObject->getInvoiceReference()); - - //maximum 4 description lines (0160) - $descArray = $paymentObject->getDescription(); - while(list($id,$desc) = each($descArray)) - { - $text .= $this->writeOmschrijvingInfo($desc); - } - - //routine splits here into creditor and debtor - if (strtoupper($this->_TransactionType) == "CREDITOR") - { - //name of creditor (0170) - $text .= $this->writeNaambegunstigdeInfo($paymentObject->getName()); - - //city of creditor (0173) - $text .= $this->writeWoonplaatsbegunstigdeInfo($paymentObject->getCity()); - } + return PEAR::raiseError('Payment transaction type does not match Clieop transaction type'); + } + + //Check if amount in transaction is valid (must be > 0) + $paymentAmount = $paymentObject->getAmount(); + if ($paymentAmount < 0) { + return PEAR::raiseError('Payment amount cannot be negative: ' . $paymentAmount); + } elseif ($paymentAmount == 0) { + return PEAR::raiseError('Payment amount must be nonzero: ' . $paymentAmount); + } + + //transactieinfo (0100) + $text = $this->writeTransactieInfo($paymentObject->getTransactionType(), + $paymentObject->getAmount(), + $paymentObject->getAccountNumberSource(), + $paymentObject->getAccountNumberDest()); - //do some calculations - $this->_NumberOfTransactions++; - //accoutnumber checksum - $this->_AccountChecksum += (int)$paymentObject->getAccountNumberSource() + (int)$paymentObject->getAccountNumberDest(); - $this->_TotalAmount += $paymentObject->getAmount(); + // Debtor name and city + if (strtoupper($this->_TransactionType) == "DEBTOR") + { + // name of debtor (0110) + $text .= $this->writeNaambetalerInfo($paymentObject->getName()); + // city of debtor (0113) + $text .= $this->writeWoonplaatsbetalerInfo($paymentObject->getCity()); + } + + // betalingskenmerk (0150) + $text .= $this->writeBetalingskenmerkInfo($paymentObject->getInvoiceReference()); + + // maximum 4 description lines (0160) + $descArray = $paymentObject->getDescription(); + while(list($id,$desc) = each($descArray)) + { + $text .= $this->writeOmschrijvingInfo($desc); } + + //routine splits here into creditor and debtor + if (strtoupper($this->_TransactionType) == "CREDITOR") + { + //name of creditor (0170) + $text .= $this->writeNaambegunstigdeInfo($paymentObject->getName()); + + //city of creditor (0173) + $text .= $this->writeWoonplaatsbegunstigdeInfo($paymentObject->getCity()); + } + + //do some calculations + $this->_NumberOfTransactions++; + //accoutnumber checksum + $this->_AccountChecksum += (int)$paymentObject->getAccountNumberSource() + (int)$paymentObject->getAccountNumberDest(); + $this->_TotalAmount += $paymentObject->getAmount(); $this->_TransactionText .= $text; + + //successful + return true; } /** * Writes complete clieop file * @access public - * @return string + * @return mixed string containing clieop batch, or PEAR_Error object */ function writeClieop() { + if ($this->_NumberOfTransactions == 0) + { + return PEAR::raiseError('No transactions have been added to this Clieop batch'); + } + $text = $this->writeBestandsvoorloopInfo($this->_SenderIdent, $this->_BatchNumber); $text .= $this->writeBatchvoorloopInfo($this->_PrincipalAccountNumber, $this->_BatchNumber); $text .= $this->writeVasteomschrijvingInfo($this->_FixedDescription); @@ -601,7 +626,7 @@ /** * master object for clieop objects * -* @version $Revision: 1.17 $ +* @version $Revision: 1.18 $ * @access private * @author Dave Mertens <dmertens@zyprexia.com> * @package Payment_Clieop http://cvs.php.net/viewvc.cgi/pear/Payment_Clieop/clieop_transaction.php?r1=1.7&r2=1.8&diff_format=u Index: pear/Payment_Clieop/clieop_transaction.php diff -u pear/Payment_Clieop/clieop_transaction.php:1.7 pear/Payment_Clieop/clieop_transaction.php:1.8 --- pear/Payment_Clieop/clieop_transaction.php:1.7 Sat Jan 4 11:56:14 2003 +++ pear/Payment_Clieop/clieop_transaction.php Sat Mar 29 00:52:29 2008 @@ -16,7 +16,7 @@ // | Authors: Dave Mertens <dmertens@zyprexia.com> | // +----------------------------------------------------------------------+ // -// $Id: clieop_transaction.php,v 1.7 2003/01/04 11:56:14 mj Exp $ +// $Id: clieop_transaction.php,v 1.8 2008/03/29 00:52:29 walter Exp $ //Define some constants for easy programming ;-) @@ -40,7 +40,7 @@ * * The TransactionPayment class is a data-holder for the main clieop class. * -* @version $Revision: 1.7 $ +* @version $Revision: 1.8 $ * @access public * @package Payment_Clieop * @author Dave Mertens <dmertens@zyprexia.com> @@ -154,7 +154,7 @@ /** * Property amount (in Eurocents) - * @param integer Value - Payment amount in euro cents (Rounded on 2 digits) + * @param integer Value - Payment amount in euro cents (Rounded on 2 digits). Must be a positive number. * @return integer * @access public */ @@ -164,7 +164,7 @@ } function setAmount($Value) { - $this->_Amount = $Value; + $this->_Amount = $Value; } /** http://cvs.php.net/viewvc.cgi/pear/Payment_Clieop/Samples/creditor.php?r1=1.2&r2=1.3&diff_format=u Index: pear/Payment_Clieop/Samples/creditor.php diff -u pear/Payment_Clieop/Samples/creditor.php:1.2 pear/Payment_Clieop/Samples/creditor.php:1.3 --- pear/Payment_Clieop/Samples/creditor.php:1.2 Sun Apr 21 00:20:57 2002 +++ pear/Payment_Clieop/Samples/creditor.php Sat Mar 29 00:52:29 2008 @@ -2,7 +2,7 @@ /** * Clieop CREDITOR sample * -* $Revision: 1.2 $ +* $Revision: 1.3 $ */ include_once("Payment_Clieop/clieop.php"); include_once("Payment_Clieop/clieop_transaction.php"); @@ -30,8 +30,19 @@ $creditor->setDescription("Like we promised, your money"); // Just some info //assign creditor record to clieop -$clieopFile->addPayment($creditor); +$result = $clieopFile->addPayment($creditor); +if (PEAR::isError($result)) +{ + echo "Error from addPayment: ".$result->getMessage()."\n"; +} //Create clieop file -echo $clieopFile->writeClieop(); +$result = $clieopFile->writeClieop(); +if (PEAR::isError($result)) +{ + echo "Error from writeClieop: ".$result->getMessage()."\n"; +} + +echo $result; + ?> \ No newline at end of file http://cvs.php.net/viewvc.cgi/pear/Payment_Clieop/Samples/debtor.php?r1=1.4&r2=1.5&diff_format=u Index: pear/Payment_Clieop/Samples/debtor.php diff -u pear/Payment_Clieop/Samples/debtor.php:1.4 pear/Payment_Clieop/Samples/debtor.php:1.5 --- pear/Payment_Clieop/Samples/debtor.php:1.4 Sun Apr 21 00:20:57 2002 +++ pear/Payment_Clieop/Samples/debtor.php Sat Mar 29 00:52:29 2008 @@ -2,7 +2,7 @@ /** * Clieop DEBTOR sample * -* $Revision: 1.4 $ +* $Revision: 1.5 $ */ include_once("Payment_Clieop/clieop.php"); include_once("Payment_Clieop/clieop_transaction.php"); @@ -31,8 +31,18 @@ $debtor->setDescription("Customernumber: 17863"); // about the transaction //assign debtor record to clieop -$clieopFile->addPayment($debtor); +$result = $clieopFile->addPayment($debtor); +if (PEAR::isError($result)) { + echo "Error from addPayment: ".$result->getMessage()."\n"; +} + //Create clieop file -echo $clieopFile->writeClieop(); +$result = $clieopFile->writeClieop(); +if (PEAR::isError($result)) { + echo "Error from writeClieop: ".$result->getMessage()."\n"; +} + +echo $result; + ?> \ No newline at end of file
« previous php.pear.cvs (#51730) next »