Exemple #1
0
 public function init()
 {
     parent::init();
     $this->j_payment->hasOne('transfer_document_id', new self());
     // only used to create / destroy trasfer legs
     if (!$this->detached) {
         $this->addCondition('transfer_document_id', 'not', null);
     }
     $this->addField('destination_account_id', ['never_persist' => true]);
     $this->addHook('beforeSave', function ($m) {
         // only for new records and when destination_account_id is set
         if ($m['destination_account_id'] && !$m->id) {
             /**/
             // In this section we test if "clone" works ok
             $this->other_leg_creation = $m2 = clone $m;
             $m2['account_id'] = $m2['destination_account_id'];
             $m2['amount'] = -$m2['amount'];
             unset($m2['destination_account_id']);
             /*/
             
                             // If clone is not working, then this is a current work-around
             
                             $this->other_leg_creation = $m2 = new Transfer($this->persistence);
                             $m2->set($m->get());
                             $m2->unset('destination_account_id');
                             $m2['account_id'] = $m['destination_account_id'];
                             $m2['amount'] = -$m2['amount']; // neagtive amount
             
                             // **/
             $m2->reload_after_save = false;
             // avoid check
             $m['transfer_document_id'] = $m2->save()->id;
         }
     });
     $this->addHook('afterSave', function ($m) {
         if ($m->other_leg_creation) {
             $m->other_leg_creation->set('transfer_document_id', $m->id)->save();
         }
         $m->other_leg_creation = null;
     });
 }
 public function display()
 {
     if (isset($_POST['next'])) {
         unset($_POST['next']);
         // To prevent unwarranted use of browser back button.
         if (!isset($_SESSION['payAccountID'])) {
             header('Location: New-Bill-Payment');
         }
         // Process on submission of password.
         if (isset($_POST['password'])) {
             $validate = new Validation();
             // Validate the password.
             try {
                 $validate->password($_POST['password']);
             } catch (ValidationException $e) {
                 $_SESSION['error'] = $e->getError();
             }
             if (isset($_SESSION['error'])) {
                 unset($_POST['password']);
                 header('Location: Bill-Payment-Amount');
             } else {
                 $user = new Users();
                 $user->userID = $_SESSION['userID'];
                 $user->password = $_POST['password'];
                 unset($_POST['password']);
                 // Check for a password match.
                 try {
                     $user->confirmPassword();
                 } catch (ValidationException $e) {
                     $_SESSION['error'] = $e->getError();
                 }
                 if (isset($_SESSION['error'])) {
                     header('Location: Bill-Payment-Amount');
                 } else {
                     // Process the payment.
                     $account = new Account();
                     $account->accountID = $_SESSION['payAccountID'];
                     if ($account->processPayment()) {
                         // Display the Acknowledgement Page.
                         $paymentack = new Paymentack();
                         $paymentack->init();
                         include 'view/layout/paymentack.php';
                         unset($_SESSION['payCreated']);
                         unset($_SESSION['payDate']);
                         unset($_SESSION['payAccountID']);
                         unset($_SESSION['payAmount']);
                         unset($_SESSION['payStatus']);
                         unset($_SESSION['payConf']);
                         unset($_SESSION['payAccount']);
                         unset($_SESSION['payBillerCode']);
                         unset($_SESSION['payBillerName']);
                         unset($_SESSION['payBillerNickname']);
                         unset($_SESSION['payCustomerRef']);
                     } else {
                         // Display the Payment Confirmation Page.
                         $paymentconf = new Paymentconf();
                         $paymentconf->init();
                         include 'view/layout/paymentconf.php';
                     }
                 }
             }
         }
         // Cancel the Payment
     } else {
         if (isset($_POST['cancel'])) {
             unset($_POST['cancel']);
             $payment = new Payment();
             $payment->cancelSessions();
             // Return to the Payment Page.
             $payment->init();
             include 'view/layout/payment.php';
         } else {
             // For any other reason, return to the Payment page.
             $payment = new Payment();
             $payment->init();
             include 'view/layout/payment.php';
         }
     }
 }
 public function display()
 {
     $validate = new Validation();
     // Add a Biller if a request is submitted.
     if (isset($_POST['addBiller'])) {
         $biller = new Billers();
         $biller->userID = $_SESSION['userID'];
         if (isset($_POST['addBillerName'])) {
             // Validate the biller name.
             try {
                 $validate->billerName($_POST['addBillerName']);
             } catch (ValidationException $e) {
                 $_SESSION['error'] = $e->getError();
             }
             if (isset($_SESSION['error'])) {
                 unset($_POST['addBillerName']);
                 header('Location: Biller-Add');
             } else {
                 $biller->billerName = strtoupper($_POST['addBillerName']);
                 unset($_POST['addBillerName']);
                 // Validate the nickname.
                 try {
                     $validate->billerNickname($_POST['addBillerNickname']);
                 } catch (ValidationException $e) {
                     $_SESSION['error'] = $e->getError();
                 }
                 if (isset($_SESSION['error'])) {
                     unset($_POST['addBillerNickname']);
                     header('Location: Biller-Add');
                 } else {
                     $biller->billerNickname = strtoupper($_POST['addBillerNickname']);
                     unset($_POST['addBillerNickname']);
                     // Validate the biller code.
                     try {
                         $validate->billerCode($_POST['addBillerCode']);
                     } catch (ValidationException $e) {
                         $_SESSION['error'] = $e->getError();
                     }
                     if (isset($_SESSION['error'])) {
                         unset($_POST['addBillerCode']);
                         header('Location: Biller-Add');
                     } else {
                         $biller->billerCode = $_POST['addBillerCode'];
                         unset($_POST['addBillerCode']);
                         // Validate the customer reference.
                         try {
                             $validate->billerCustomerRef($_POST['addBillerCustomerRefNumber']);
                         } catch (ValidationException $e) {
                             $_SESSION['error'] = $e->getError();
                         }
                         if (isset($_SESSION['error'])) {
                             unset($_POST['addBillerCustomerRefNumber']);
                             header('Location: Biller-Add');
                         } else {
                             // If all is ok, add the biller.
                             $biller->customerReference = $_POST['addBillerCustomerRefNumber'];
                             unset($_POST['addBillerCustomerRefNumber']);
                             $biller->set();
                         }
                     }
                 }
             }
         }
     }
     // Display the New Bill Payment Page.
     $payment = new Payment();
     $payment->init();
     include 'view/layout/payment.php';
 }
 public function display()
 {
     // Process if posted to from the Payment Amount Page.
     if (isset($_POST['next'])) {
         unset($_POST['next']);
         // In the event the back button is hit on the browser
         // after the transaction has been processed.
         if (!isset($_SESSION['payBillerCode']) || !isset($_SESSION['payBillerName']) || !isset($_SESSION['payBillerNickname'])) {
             header("Location: New-Bill-Payment");
         }
         if (isset($_POST['account'])) {
             $_SESSION['payAccountID'] = $_POST['account'];
             unset($_POST['account']);
         }
         $validate = new Validation();
         if (isset($_POST['custref'])) {
             // Validate the customer reference.
             try {
                 $custref = $_POST['custref'];
                 unset($_POST['custref']);
                 $validate->custref($custref);
             } catch (ValidationException $e) {
                 $_SESSION['error'] = $e->getError();
             }
             if (isset($_SESSION['error'])) {
                 $custref = null;
                 unset($_POST['next']);
                 header('Location: Bill-Payment-Amount');
             } else {
                 $_SESSION['payCustomerRef'] = $custref;
                 if (isset($_POST['amount'])) {
                     // Validate the amount.
                     try {
                         $amount = $_POST['amount'];
                         unset($_POST['amount']);
                         $validate->payAmount($amount);
                     } catch (ValidationException $e) {
                         $_SESSION['error'] = $e->getError();
                     }
                     if (isset($_SESSION['error'])) {
                         $amount = null;
                         unset($_POST['next']);
                         header('Location: Bill-Payment-Amount');
                     } else {
                         $_SESSION['payAmount'] = $amount;
                         if (isset($_POST['paymentDate'])) {
                             // Validate the date.
                             try {
                                 $paymentDate = $_POST['paymentDate'];
                                 unset($_POST['paymentDate']);
                                 $validate->payDate($paymentDate);
                             } catch (ValidationException $e) {
                                 $_SESSION['error'] = $e->getError();
                             }
                             if (isset($_SESSION['error'])) {
                                 $paymentDate = null;
                                 unset($_POST['next']);
                                 header('Location: Bill-Payment-Amount');
                             } else {
                                 // If all is OK, display the Payment Confirmation Page.
                                 $_SESSION['payDate'] = $paymentDate;
                                 $paymentconf = new Paymentconf();
                                 $paymentconf->init();
                                 include 'view/layout/paymentconf.php';
                             }
                         }
                     }
                 }
             }
         }
         // Cancel the Payment
     } else {
         if (isset($_POST['cancel'])) {
             unset($_POST['cancel']);
             $payment = new Payment();
             $payment->cancelSessions();
             $payment->init();
             include 'view/layout/payment.php';
         } else {
             // For any other reason, display the Payment Page.
             $payment = new Payment();
             $payment->cancelSessions();
             $payment->init();
         }
     }
 }
Exemple #5
0
 function handler_payment($page, $ref = -1)
 {
     $page->changeTpl('payment/payment.tpl');
     $page->setTitle('Télépaiement');
     $this->load('money.inc.php');
     $meth = new PayMethod(Env::i('methode', -1));
     $pay = new Payment($ref);
     if (!$pay->flags->hasflag('public') && (!S::user() || !S::logged())) {
         $page->kill("Vous n'avez pas les permissions nécessaires pour accéder à cette page.");
     } else {
         $page->assign('public', true);
     }
     if ($pay->flags->hasflag('old')) {
         $page->kill('La transaction selectionnée est périmée.');
     }
     if (Env::has('montant')) {
         $pay->amount_def = Env::v('montant');
     }
     $val = Post::v('amount') != 0 ? Post::v('amount') : $pay->amount_def;
     if (($error = $pay->check($val)) !== true) {
         $page->trigError($error);
     }
     if (Post::has('op') && Post::v('op', 'select') == 'submit') {
         if (S::logged()) {
             $user = S::user();
         } else {
             $user = User::getSilent(Post::t('login'));
         }
         if (is_null($user)) {
             $page->trigError("L'identifiant est erroné.");
             $page->assign('login_error', true);
             $page->assign('login', Post::t('login'));
         } else {
             $pay->init($val, $meth);
             $pay->prepareform($user);
             $page->assign('full_name', $user->fullName(true));
             $page->assign('sex', $user->isFemale());
         }
     } elseif (S::logged()) {
         $res = XDB::iterator('SELECT  ts_confirmed, amount
                                 FROM  payment_transactions
                                WHERE  uid = {?} AND ref = {?}
                             ORDER BY  ts_confirmed DESC', S::v('uid', -1), $pay->id);
         if ($res->total()) {
             $page->assign('transactions', $res);
         }
         // Only if $id = -1, meaning only for donation the site's association
         if ($ref == -1) {
             $biggest_donations = XDB::fetchAllAssoc('SELECT  IF(p.display,
                                                                 IF(ap.pid IS NOT NULL, CONCAT(a.full_name, \' (\', pd.promo, \')\'), a.full_name),
                                                                 \'XXXX\') AS name, p.amount, p.ts_confirmed
                                                        FROM  payment_transactions AS p
                                                  INNER JOIN  accounts             AS a  ON (a.uid = p.uid)
                                                   LEFT JOIN  account_profiles     AS ap ON (a.uid = ap.uid AND FIND_IN_SET(\'owner\', ap.perms))
                                                   LEFT JOIN  profile_display      AS pd ON (ap.pid = pd.pid)
                                                       WHERE  p.ref = {?}
                                                    ORDER BY  LENGTH(p.amount) DESC, p.amount DESC, name
                                                       LIMIT  10', $pay->id);
             $donations = XDB::fetchAllAssoc('(SELECT  SUM(amount) AS amount, YEAR(ts_confirmed) AS year, MONTH(ts_confirmed) AS month, ts_confirmed
                                                 FROM  payment_transactions
                                                WHERE  ref = {?} AND YEAR(ts_confirmed) = YEAR(CURDATE())
                                             GROUP BY  month)
                                              UNION
                                              (SELECT  SUM(amount) AS amount, YEAR(ts_confirmed) AS year, 0 AS month, ts_confirmed
                                                 FROM  payment_transactions
                                                WHERE  ref = {?} AND YEAR(ts_confirmed) < YEAR(CURDATE())
                                             GROUP BY  year)
                                             ORDER BY  year DESC, month DESC', $pay->id, $pay->id);
             $page->assign('biggest_donations', $biggest_donations);
             $page->assign('donations', $donations);
             $page->assign('donation', true);
         }
     }
     $val = floor($val * 100) / 100;
     $page->assign('amount', $val);
     $page->assign('comment', Env::v('comment'));
     $page->assign('meth', $meth);
     $page->assign('pay', $pay);
     $page->assign('evtlink', $pay->event());
 }