Exemple #1
0
 function test_humanized_amount()
 {
     $payment = new Payment(12.35, 'Inscripcio', '29292929');
     $this->assertEqual(12.35, $payment->getHumanizedAmount());
     $payment->setAmount(12);
     $this->assertEqual(12.0, $payment->getHumanizedAmount());
     $payment->setAmount(120);
     $this->assertEqual(120.0, $payment->getHumanizedAmount());
     $payment->setAmount(120.3);
     $this->assertEqual(120.3, $payment->getHumanizedAmount());
     $payment->setAmount(120.21);
     $this->assertEqual(120.21, $payment->getHumanizedAmount());
     $payment->setAmount('12.35');
     $this->assertEqual(12.35, $payment->getHumanizedAmount());
     $payment->setAmount('12');
     $this->assertEqual(12.0, $payment->getHumanizedAmount());
     $payment->setAmount('120');
     $this->assertEqual(120.0, $payment->getHumanizedAmount());
     $payment->setAmount('120.3');
     $this->assertEqual(120.3, $payment->getHumanizedAmount());
     $payment->setAmount('120.21');
     $this->assertEqual(120.21, $payment->getHumanizedAmount());
 }
Exemple #2
0
 /**
  * Initialize the object with raw data
  *
  * @param $data
  * @return Payment
  */
 public static function initializeWithRawData($data)
 {
     $item = new Payment();
     if (isset($data['amount'])) {
         $item->setAmount($data['amount']);
     }
     if (isset($data['paid_at'])) {
         $item->setPaidAt(new \DateTime('@' . strtotime($data['paid_at'])));
     }
     if (isset($data['identifier'])) {
         $item->setIdentifier($data['identifier']);
     }
     return $item;
 }
 protected function generatePayments()
 {
     // Payments
     $date1 = sfDate::getInstance($this->inv->getIssueDate());
     $date2 = sfDate::getInstance($this->inv->getDueDate());
     $total = $this->inv->setAmounts()->getGrossAmount();
     if (mt_rand(1, 10) == 1) {
         $q = mt_rand(1, 5);
         $paid = 0;
         for ($k = 0; $k < $q && $paid < $total; $k++) {
             $payment = new Payment();
             $payment_date = sfDate::getInstance($date2->get() - mt_rand(1, $date2->diff($date1)));
             $payment->setDate($payment_date->format('Y-m-d'));
             $payment->setNotes($this->items[array_rand($this->items)]);
             $rest = $total - $paid;
             $sum = round($rest * (0.25 * mt_rand(1, 3)), 2);
             $paid += $sum;
             $payment->setAmount($sum);
             $this->inv->Payments[] = $payment;
         }
     } else {
         $payment = new Payment();
         $payment_date = sfDate::getInstance($date2->get() - mt_rand(1, $date2->diff($date1)));
         $payment->setDate($payment_date->format('Y-m-d'));
         $payment->setNotes($this->items[array_rand($this->items)]);
         $payment->setAmount($total);
         $this->inv->Payments[] = $payment;
     }
 }
Exemple #4
0
<?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');
$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");
    }
} elseif ($isBank && isset($_REQUEST["BankSubmit"])) {
    $packageAmount = $serviceRequestDetails->getPackageDetails()[0]->getPrice();
    $paymenstatus = $totalPayments + $result["amount"] >= $packageAmount ? "complete" : "partial";
    $payment->setOr_id($_POST["depositCode"]);
    $payment->setMode("bank");
    $payment->setAmount($_POST["depositAmount"]);
    $payment->setService_no($serviceRequestId);
    $payment->setStat($paymenstatus);
 public function executeBuy($request)
 {
     $this->user = $this->getUser()->getSubscriber();
     $this->step = 1;
     $this->form = new BuyStep1Form();
     if ($request->isMethod('post') || $request->getParameter('jotag')) {
         // if direct access, stop on step 1
         if (!$request->isMethod('post')) {
             $request->setParameter('step', 1);
         }
         $this->form->bind(array('jotag' => strtolower($request->getParameter('jotag'))));
         if ($this->form->isValid()) {
             // step 1 OK
             $this->jotag_object = $this->form->getValue('jotag_object');
             $this->step = 2;
             if ($this->user->getCredits() || $this->isWebserviceCall()) {
                 if (!$this->user->getCredits()) {
                     // ok, webservice call, but we don't have credits
                     $this->form = null;
                     return sfView::ERROR;
                 }
                 // REDEEM FORK
                 $this->setTemplate('redeem');
                 $this->form = new RedeemStep2Form(array('jotag' => strtolower($this->form->getValue('jotag'))));
                 if ($request->getParameter('step') > 1) {
                     $this->form->bind(array('jotag' => strtolower($request->getParameter('jotag')), 'confirm_jotag' => strtolower($request->getParameter('confirm_jotag'))));
                     if ($this->form->isValid()) {
                         // step 2 OK, here we create new jotag
                         $this->step = 3;
                         if ($this->jotag_object) {
                             $jotag = $this->jotag_object;
                             $ptype = PaymentPeer::PT_RENEW;
                         } else {
                             $jotag = new Tag();
                             $jotag->setJotag(strtolower($this->form->getValue('jotag')));
                             $jotag->setStatus(TagPeer::ST_NEW);
                             $jotag->setUser($this->getUser()->getSubscriber());
                             $jotag->setIsPrimary(false);
                             $ptype = PaymentPeer::PT_NEW;
                         }
                         // mark this jotag as FREE, so we can automatically give credits
                         $jotag->setIsCredit(true);
                         // calculate new expiration date
                         $jotag->setValidUntil($jotag->calcNewDate($this->user->getCredits() * OptionPeer::retrieveOption('BONUS_DAYS_PER_CREDIT'), true));
                         $jotag->setStatus(TagPeer::ST_ACTIVE);
                         // create payment
                         $payment = new Payment();
                         $payment->setTag($jotag);
                         $payment->setMethod(PaymentPeer::PT_CREDITS);
                         $payment->setAmount(0);
                         $payment->setDuration($this->user->getCredits() * OptionPeer::retrieveOption('BONUS_DAYS_PER_CREDIT'));
                         $payment->setCredits($this->user->getCredits());
                         $payment->setUser($this->getUser()->getSubscriber());
                         $payment->setStatus(PaymentPeer::ST_PAID);
                         $payment->setType($ptype);
                         // save
                         $jotag->save();
                         $payment->save();
                         // remove credits from user account
                         $this->user->setCredits(0);
                         $this->user->save();
                         // remove from interest list
                         $this->user->delInterest($jotag->getJotag());
                         $this->payment = $payment;
                         $this->jotag = $jotag;
                         // send receipt to the user
                         Mailer::sendEmail($payment->getUser()->getPrimaryEmail(), 'paymentConfirmation', array('payment' => $payment), $this->getUser()->getSubscriber()->getPreferedLanguage());
                     }
                 }
             } else {
                 // BUY FORK
                 $this->form = new BuyStep2Form(array('jotag' => strtolower($this->form->getValue('jotag'))));
                 if ($request->getParameter('step') > 1) {
                     $this->form->bind(array('jotag' => strtolower($request->getParameter('jotag')), 'confirm_jotag' => strtolower($request->getParameter('confirm_jotag')), 'duration' => $request->getParameter('duration')));
                     if ($this->form->isValid()) {
                         // step 2 OK, create payment
                         $payment = new Payment();
                         if ($this->jotag_object) {
                             $payment->setTag($this->jotag_object);
                             $payment->setType(PaymentPeer::PT_RENEW);
                         } else {
                             $payment->setJotag(strtolower($this->form->getValue('jotag')));
                             $payment->setType(PaymentPeer::PT_NEW);
                         }
                         $payment->setMethod(PaymentPeer::PT_PAYPAL);
                         $payment->setAmount((double) sprintf("%0.2f", $this->form->getValue('duration') * OptionPeer::retrieveOption('BUY_PRICE')));
                         $payment->setDuration($this->form->getValue('duration'));
                         $payment->setUser($this->getUser()->getSubscriber());
                         $payment->setCredits(0);
                         $payment->setStatus(PaymentPeer::ST_NEW);
                         $payment->save();
                         $this->payment = $payment;
                         $this->getUser()->setPaymentId($payment->getId());
                         $this->step = 3;
                         $this->form = new BuyStep3Form(array('jotag' => strtolower($this->form->getValue('jotag')), 'confirm_jotag' => strtolower($this->form->getValue('confirm_jotag')), 'duration' => $this->form->getValue('duration')));
                     }
                 }
             }
         } else {
             if (get_class($this->form["jotag"]->getError()->getValidator()) == "buyJotagValidator") {
                 $this->already_exists = $this->form["jotag"]->getError()->getValidator()->getAlreadyExists();
             }
         }
         $this->suggestions = $this->user->getSuggestions($request->getParameter('jotag'));
     } else {
         $this->suggestions = $this->user->getSuggestions();
     }
 }