release held packages when automatically unsuspending, RT#83847
[freeside.git] / ng_selfservice / prepaid.php
1 <? $title ='Prepaid Card Account Recharge'; include('elements/header.php'); ?>
2 <? $current_menu = 'prepaid.php'; include('elements/menu.php'); ?>
3
4 <?
5 // This page is currently only designed for packages that use prepaid pricing.
6 // Usage limits should be in seconds, and you currently cannot mix packages that have 
7 // usage limits with packages that don't.  Payments must be made by prepaid card.
8 // The account service must be flagged as primary service of package.
9 //
10 // You can't change packages if you have a positive balance, but you CAN use 
11 // this form to only change package or only use a prepaid card--doing both isn't
12 // required.
13
14 $prepaid_cardnum = isset($_POST['prepaid_cardnum']) ? $_POST['prepaid_cardnum'] : '';
15 $pkgpart = isset($_POST['pkgpart']) ? $_POST['pkgpart'] : '';
16 $pkgnum  = isset($_POST['pkgnum']) ? $_POST['pkgnum'] : '';
17 $success = '';
18 $error   = '';
19
20 if ($pkgnum || $pkgpart) {
21   if ($pkgnum && $pkgpart) {
22     $change_results = $freeside->change_pkg(array(
23       'session_id'      => $_COOKIE['session_id'],
24       'pkgpart'         => $pkgpart,
25       'pkgnum'          => $pkgnum,
26     ));
27     if ( isset($change_results['error']) && $change_results['error'] ) {
28       $error = $change_results['error'];
29     } else {
30       $success .= ' Package applied to your account.';
31       $pkgnum = '';
32       $pkgpart = '';
33     }
34   } else if ($pkgnum) {
35     $error = 'No account selected';
36   } else if ($pkgpart) {
37     $error = 'No package selected';
38   }
39 }
40
41 if ($prepaid_cardnum) {
42   $payment_results = $freeside->process_prepay(array(
43     'session_id'      => $_COOKIE['session_id'],
44     'prepaid_cardnum' => $prepaid_cardnum,
45   ));
46   if ( isset($payment_results['error']) && $payment_results['error'] ) {
47     $error = $payment_results['error'];
48   } else {
49     $success .= ' Prepaid card applied to your account.';
50     $prepaid_cardnum = '';
51   }
52 }
53
54 $customer_info = $freeside->customer_info_short( array(
55   'session_id' => $_COOKIE['session_id'],
56 ) );
57 if ( isset($customer_info['error']) && $customer_info['error'] ) {
58   $error = $customer_info['error'];
59 }
60
61 $signup_info = $freeside->signup_info( array('customer_session_id' => $_COOKIE['session_id'], 'keys' => ['part_pkg']) );
62 if (isset($signup_info['error']) && $signup_info['error']) {
63   $error = $signup_info['error'];
64 }
65
66 $list_pkgs = $freeside->list_pkgs( array(
67   'session_id' => $_COOKIE['session_id'],
68 ) );
69 if ( isset($list_pkgs['error']) && $list_pkgs['error'] ) {
70   $error = $list_pkgs['error'];
71 }
72
73 extract($customer_info);
74 extract($signup_info);
75 extract($list_pkgs);
76
77 $actsvcs = array();
78 $expsvcs = array();
79 foreach ($cust_pkg as $pkg) {
80   $thissvc = array();
81   $thissvc['svcnum']    = $pkg['primary_cust_svc']['svcnum'];
82   $thissvc['overlimit'] = $pkg['primary_cust_svc']['overlimit'];
83   $thissvc['label']     = $pkg['primary_cust_svc']['label'][1];
84   $thissvc['pkgnum'] = $pkg['pkgnum'];
85   $thissvc['status'] = $pkg['status'];
86   $actsvcs[$thissvc['svcnum']] = $thissvc;
87   if ($thissvc['overlimit'] or ($thissvc['status'] != 'active')) {
88     $expsvcs[$thissvc['svcnum']] = $thissvc;
89   }
90 }
91
92 if (count($actsvcs) > 0) {
93   $list_svcs = $freeside->list_svcs( array(
94     'session_id' => $_COOKIE['session_id'],
95   ) );
96   if ( isset($list_svcs['error']) && $list_svcs['error'] ) {
97     $error = $list_svcs['error'];
98   }
99   extract($list_svcs);
100   foreach ($svcs as $svc) {
101     if (isset($actsvcs[$svc['svcnum']])) {
102       $actsvcs[$svc['svcnum']]['seconds'] = strlen($svc['seconds']) ? $svc['seconds'] : 'Unlimited';
103     }
104   }
105 }
106
107 if ($success) {
108   echo '<P><B>' . $success . '</B></P>';
109 }
110 include('elements/error.php');
111
112 if (count($actsvcs) > 0) {
113 ?>
114 <TABLE STYLE="text-align: left;">
115 <TR><TH>Account</TH><TH STYLE="text-align: right;">Seconds Remaining</TH></TR>
116 <? 
117   foreach ($actsvcs as $svc) {
118     if ($svc['status'] == 'active') {
119       $slabel = $svc['seconds'];
120     } else {
121       $slabel = '<I>' . ucfirst($svc['status']) . '</I>';
122     }  
123 ?>
124 <TR>
125 <TD><? echo $svc['label'] ?></TD>
126 <TD STYLE="text-align: right;"><? echo $slabel ?></TD>
127 </TR>
128 <?
129   }
130 ?>
131 </TABLE>
132 <?
133 }
134 if ($balance != 0) {
135   $blabel = ($balance < 0) ? 'Credit' : 'Balance';
136 ?>
137
138 <P><B><? echo $blabel ?>:</B> <? echo $money_char . abs($balance) ?></P>
139
140 <?
141 }
142 ?>
143
144 <FORM NAME="OneTrueForm" METHOD="POST" ACTION="prepaid.php" onSubmit="document.OneTrueForm.process.disabled=true">
145
146 <?
147 if ($balance <= 0) {
148   if (count($expsvcs) > 0) {
149 ?>
150
151 <P>
152 <B>Select an account to recharge:</B><BR>
153 <SELECT NAME="pkgnum">
154 <OPTION VALUE=""></OPTION>
155 <? foreach ($expsvcs as $svc) { ?>
156 <OPTION VALUE="<? echo $svc['pkgnum'] ?>"<? echo $pkgnum == $svc['pkgnum'] ? ' CHECKED' : ''  ?>>
157 <?   echo $svc['label'] ?>
158 </OPTION>
159 <? } ?>
160 </SELECT>
161 </P>
162
163 <P>
164 <B>Select a package to add to account</B><BR>
165 <SELECT NAME="pkgpart">
166 <OPTION VALUE=""></OPTION>
167 <? foreach ($part_pkg as $pkg) { ?>
168 <OPTION VALUE="<? echo $pkg['pkgpart'] ?>"<? echo $pkgpart == $pkg['pkgpart'] ? ' CHECKED' : ''  ?>>
169 <?   echo $pkg['pkg'] . ' - ' . $money_char . $pkg['options']['recur_fee'] ?>
170 </OPTION>
171 <? } ?>
172 </SELECT>
173 </P>
174
175 <?
176   } else {
177 ?>
178
179 <P>You have no services to recharge at this time.</P>
180
181 <?
182   }
183 }
184 if (($balance > 0) or (count($expsvcs) > 0)) {
185 ?>
186
187 <P>
188 <B>Enter prepaid card number:</B><BR>
189 <INPUT TYPE="text" NAME="prepaid_cardnum" VALUE="<? echo $prepaid_cardnum ?>">
190 </P>
191
192 <INPUT TYPE="submit" NAME="submit" VALUE="Submit">
193
194 <?
195 }
196 ?>
197
198 </FORM>
199
200 <? include('elements/menu_footer.php'); ?>
201 <? include('elements/footer.php'); ?>
202