81665767dec92bfd5394a466a489b27156f26bbb
[atutor.git] / mods / ecomm / payment.php
1 <?php
2 /************************************************************************/
3 /* ATutor                                                                                                                               */
4 /************************************************************************/
5 /* Copyright (c) 2002-2010                                              */
6 /* Inclusive Design Institute                                           */
7 /* http://atutor.ca                                                     */
8 /* This program is free software. You can redistribute it and/or        */
9 /* modify it under the terms of the GNU General Public License          */
10 /* as published by the Free Software Foundation.                        */
11 /************************************************************************/
12
13 $_user_location = 'users';
14 define('AT_INCLUDE_PATH', '../../include/');
15 require(AT_INCLUDE_PATH.'vitals.inc.php');
16 require('include/payments.lib.php');
17
18 if ($_POST['cancel']) {
19         header('location: index.php');
20         exit;
21 }
22
23 ///Get the fee for the current course
24 $course_id = intval($_GET['course_id']);
25
26 $sql = "SELECT course_fee FROM ".TABLE_PREFIX."ec_course_fees WHERE course_id=$course_id";
27 $result = mysql_query($sql, $db);
28 if ($this_course_fee = mysql_fetch_assoc($result)) {
29         $this_course_fee = $this_course_fee['course_fee'];
30 } else {
31         header('location: index.php');
32         exit;
33 }
34 $course_id = intval($_REQUEST['course_id']);
35 $member_id = intval($_SESSION['member_id']);
36 require (AT_INCLUDE_PATH.'header.inc.php');
37
38 ///Check if a partial payment has already been made so the balance can be calculated
39 $sql4 = "SELECT SUM(amount) AS total_amount FROM ".TABLE_PREFIX."payments WHERE course_id='$course_id' AND approved=1 AND member_id=$member_id";
40 $result4 = mysql_query($sql4, $db);
41 while ($row4 = mysql_fetch_assoc($result4)) {
42         if($row4['total_amount'] > 0){
43                 $amount_paid = $row4['total_amount'];
44         } else {
45                 $amount_paid = 0.00;
46         }
47 }
48 $balance_course_fee = $this_course_fee - $amount_paid;
49 $this_course_fee = $balance_course_fee;
50
51 $sql = "INSERT INTO ".TABLE_PREFIX."payments VALUES (NULL, NULL, 0, '', '{$_SESSION['member_id']}', '$course_id', '$balance_course_fee')";
52 $result = mysql_query($sql, $db);
53
54 $payment_id = mysql_insert_id($db);
55 ?>
56 <div class="input-form">
57         <div class="row">
58                 <h3><?php echo _AT('confirm'); ?></h3>
59
60                 <p><?php echo _AT('ec_confirm_info'); ?></p>
61
62                 <dl>
63                         <dt><?php echo _AT('ec_course');?></dt>
64                         <dd><?php echo $system_courses[$course_id]['title']; ?></dd>
65
66                         <dt><?php echo _AT('ec_this_course_fee');?></dt>
67                         <dd><?php echo $_config['ec_currency_symbol'].$this_course_fee.' '.$_config['ec_currency'];?></dd>
68
69                         <dt><?php echo _AT('ec_amount_recieved');?></dt>
70                         <dd><?php echo $_config['ec_currency_symbol'].$amount_paid;?></dd>
71
72                         <dt><?php echo _AT('ec_balance_due');?></dt>
73                         <dd><?php echo $_config['ec_currency_symbol'].number_format($balance_course_fee, 2).' '.$_config['ec_currency'];;?></dd>
74                 </dl>
75                         
76                 <h4><?php echo _AT('ec_requirements'); ?></h4>
77                 <ul>
78                         <li><?php echo _AT('ec_requirements_ssl'); ?></li>
79                         <li><?php echo _AT('ec_requirements_cookies'); ?></li>
80                         <li><?php echo _AT('ec_requirements_javascript'); ?></li>
81                         <li><?php echo _AT('ec_requirements_comments'); ?></li>
82                 </ul>
83         </div>
84
85         <?php
86                 /*
87                  * these payment forms below can be replaced by any other payment gateway.
88                  * when the gateway sends back the response then it is authenticated and if
89                  * the amounts match then the `payments` transaction is updated and approved.
90                 */
91         ?>
92
93         <div class="row buttons">
94                 <?php beanstream_print_form($payment_id, $balance_course_fee, $course_id); ?>
95                 <?php paypal_print_form($payment_id, $balance_course_fee, $course_id); ?>
96                 <?php mirapay_print_form($payment_id, $balance_course_fee, $course_id); ?>
97                 <?php check_payment_print_form($payment_id, $balance_course_fee, $course_id); ?>
98
99         </div>
100 </div>
101                 
102 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>