function test_payment_amount() { $payment = new Payment(12.35, 'Inscripcio', '29292929'); $this->assertEqual('1235', $payment->getAmount()); $payment->setAmount(12); $this->assertEqual('1200', $payment->getAmount()); $payment->setAmount(120); $this->assertEqual('12000', $payment->getAmount()); $payment->setAmount(120.3); $this->assertEqual('12030', $payment->getAmount()); $payment->setAmount(120.21); $this->assertEqual('12021', $payment->getAmount()); $payment->setAmount('12.35'); $this->assertEqual('1235', $payment->getAmount()); $payment->setAmount('12'); $this->assertEqual('1200', $payment->getAmount()); $payment->setAmount('120'); $this->assertEqual('12000', $payment->getAmount()); $payment->setAmount('120.3'); $this->assertEqual('12030', $payment->getAmount()); $payment->setAmount('120.21'); $this->assertEqual('12021', $payment->getAmount()); }
<?php include dirname(__FILE__) . '/../../bootstrap/Doctrine.php'; include dirname(__FILE__) . '/../../testTools.php'; $t = new lime_test(2, new lime_output_color()); PropertyTable::set('currency_decimals', 3); $p = new Payment(); $p->setAmount(2.1215); $t->is($p->getAmount(), 2.122, 'rounds amount to 3 decimals'); PropertyTable::set('currency_decimals', 2); $p->setAmount(2.123); $t->is($p->getAmount(), 2.12, 'rounds amount to 2 decimals');
/** * Add the payment * * @param \Cx\Modules\Order\Model\Entity\Payment $payment */ public function addPayment(Payment $payment) { $payment->setInvoice($this); $this->payments[] = $payment; if ($payment->getAmount() == $this->getAmount()) { $this->paid = true; } if ($payment->getAmount() > $this->getAmount()) { throw new InvoiceException('Amount of payment must not be greater than invoice amount'); } }
include_once 'include/common.php'; include_once 'include/ServiceRequest.php'; include_once 'include/AccessRights/SuperadminAdminClient.php'; $serviceRequestId = isset($_REQUEST["id"]) ? $_REQUEST["id"] : NULL; $mode = isset($_REQUEST["paymentmode"]) ? $_REQUEST["paymentmode"] : NULL; $isBank = $mode == "bank"; $isPaypal = $mode == "paypal"; $currentUser = $_SESSION["user"]; $serviceRequest = new ServiceRequest(); $serviceRequestDetails = $serviceRequest->getServiceRequest(array("service_no" => "DESC"), array("service_no" => array($serviceRequestId, Equal))); $serviceRequestDetails = $serviceRequestDetails[0]; $payment = new Payment(); $payments = $payment->getPayments(array("payment_no" => "DESC"), array("service_no" => array($serviceRequestId, Equal))); $totalPayments = 0; foreach ($payments as $payment) { $totalPayments += $payment->getAmount(); } if ($isPaypal && isset($_REQUEST["PaypalSubmit"])) { $paypal = new Paypal($_POST); if ($result = $paypal->DoPayment()) { $packageAmount = $serviceRequestDetails->getPackageDetails()[0]->getPrice(); $paymenstatus = $totalPayments + $result["amount"] >= $packageAmount ? "complete" : "partial"; $payment->setOr_id($result["transactionID"]); $payment->setMode("paypal"); $payment->setAmount($result["amount"]); $payment->setService_no($serviceRequestId); $payment->setStat($paymenstatus); $payment->save(); header("Location:ViewPayments.php?id=" . $serviceRequestId); } else { header("Location:" . $_SERVER["PHP_SELF"] . "?message=Failed");