| 1 | <?php
|
|---|
| 2 |
|
|---|
| 3 | /***************************************************************************
|
|---|
| 4 | * Dolphin Smart Community Builder
|
|---|
| 5 | * -----------------
|
|---|
| 6 | * begin : Mon Mar 23 2006
|
|---|
| 7 | * copyright : (C) 2006 BoonEx Group
|
|---|
| 8 | * website : http://www.boonex.com/
|
|---|
| 9 | * This file is part of Dolphin - Smart Community Builder
|
|---|
| 10 | *
|
|---|
| 11 | * Dolphin is free software. This work is licensed under a Creative Commons Attribution 3.0 License.
|
|---|
| 12 | * http://creativecommons.org/licenses/by/3.0/
|
|---|
| 13 | *
|
|---|
| 14 | * Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|---|
| 15 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|---|
| 16 | * See the Creative Commons Attribution 3.0 License for more details.
|
|---|
| 17 | * You should have received a copy of the Creative Commons Attribution 3.0 License along with Dolphin,
|
|---|
| 18 | * see license.txt file; if not, write to marketing@boonex.com
|
|---|
| 19 | ***************************************************************************/
|
|---|
| 20 |
|
|---|
| 21 | require_once( 'inc/header.inc.php' );
|
|---|
| 22 | require_once( BX_DIRECTORY_PATH_INC . 'design.inc.php' );
|
|---|
| 23 | require_once( BX_DIRECTORY_PATH_INC . 'profiles.inc.php' );
|
|---|
| 24 | require_once( BX_DIRECTORY_PATH_INC . 'checkout.inc.php' );
|
|---|
| 25 |
|
|---|
| 26 | // --------------- page variables and login
|
|---|
| 27 |
|
|---|
| 28 | $_page['name_index'] = 56;
|
|---|
| 29 | $_page['css_name'] = 'checkout.css';
|
|---|
| 30 |
|
|---|
| 31 | $logged['member'] = member_auth( 0 );
|
|---|
| 32 |
|
|---|
| 33 | $_page['header'] = _t('_CHECKOUT_H');
|
|---|
| 34 | $_page['header_text'] = _t('_CHECKOUT_H');
|
|---|
| 35 |
|
|---|
| 36 | define( 'PAYMENT_MODULE_AS_HEADER', 'on' );
|
|---|
| 37 |
|
|---|
| 38 | $collectDataArr = array(); // array with collected data
|
|---|
| 39 | $collectDataInputs = ''; // string with inputs for data resending
|
|---|
| 40 |
|
|---|
| 41 | // --------------- page components
|
|---|
| 42 |
|
|---|
| 43 | $_ni = $_page['name_index'];
|
|---|
| 44 |
|
|---|
| 45 | switch ( $_REQUEST['action'] )
|
|---|
| 46 | {
|
|---|
| 47 | case 'calculate':
|
|---|
| 48 | $calculateArr = CalculateCheckoutInfo( $_REQUEST );
|
|---|
| 49 | if ( $calculateArr === false )
|
|---|
| 50 | {
|
|---|
| 51 | PageCompErrorMessage( _t('_no data given') );
|
|---|
| 52 | }
|
|---|
| 53 | $res = CollectCheckoutInfo( $calculateArr );
|
|---|
| 54 | if ( !$res )
|
|---|
| 55 | {
|
|---|
| 56 | PageCompErrorMessage( _t('_no data given') );
|
|---|
| 57 | }
|
|---|
| 58 | else
|
|---|
| 59 | {
|
|---|
| 60 | $_page_cont[$_ni]['checkout_info'] = DesignBoxContent( _t('_Payment info'), PageCompCheckoutInfo(), $oTemplConfig -> PageCompCheckoutInfo_db_num );
|
|---|
| 61 | $_page_cont[$_ni]['provider_list'] = DesignBoxContent( _t('_Payment methods'), PageCompProviderList(), $oTemplConfig -> PageCompProviderList_db_num );
|
|---|
| 62 | }
|
|---|
| 63 | break;
|
|---|
| 64 |
|
|---|
| 65 | case 'collect':
|
|---|
| 66 | $res = CollectCheckoutInfo( $_REQUEST );
|
|---|
| 67 | if ( !$res )
|
|---|
| 68 | {
|
|---|
| 69 | PageCompErrorMessage( _t('_no data given') );
|
|---|
| 70 | }
|
|---|
| 71 | else
|
|---|
| 72 | {
|
|---|
| 73 | $_page_cont[$_ni]['checkout_info'] = DesignBoxContent( _t('_Payment info'), PageCompCheckoutInfo(), $oTemplConfig -> PageCompCheckoutInfo_db_num );
|
|---|
| 74 | $_page_cont[$_ni]['provider_list'] = DesignBoxContent( _t('_Payment methods'), PageCompProviderList(), $oTemplConfig -> PageCompProviderList_db_num );
|
|---|
| 75 | }
|
|---|
| 76 | break;
|
|---|
| 77 |
|
|---|
| 78 | case 'start_checkout':
|
|---|
| 79 | $res = CollectCheckoutInfo( $_REQUEST );
|
|---|
| 80 | if ( !$res )
|
|---|
| 81 | {
|
|---|
| 82 | PageCompErrorMessage( _t('_no data given') );
|
|---|
| 83 | }
|
|---|
| 84 | else
|
|---|
| 85 | {
|
|---|
| 86 | $res = StartCheckout( $errorMessage );
|
|---|
| 87 | if ( !$res )
|
|---|
| 88 | {
|
|---|
| 89 | PageCompErrorMessage( $errorMessage );
|
|---|
| 90 | }
|
|---|
| 91 | }
|
|---|
| 92 | break;
|
|---|
| 93 |
|
|---|
| 94 | default:
|
|---|
| 95 | PageCompErrorMessage( _t('_no data given') );
|
|---|
| 96 | break;
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | // --------------- [END] page components
|
|---|
| 100 |
|
|---|
| 101 | PageCode();
|
|---|
| 102 |
|
|---|
| 103 | // --------------- page components functions
|
|---|
| 104 |
|
|---|
| 105 | /**
|
|---|
| 106 | * calculate checkout info
|
|---|
| 107 | */
|
|---|
| 108 | function CalculateCheckoutInfo( $source )
|
|---|
| 109 | {
|
|---|
| 110 | if ( !isset($source['checkout_action']) || strlen($source['data']) == 0 )
|
|---|
| 111 | return false;
|
|---|
| 112 |
|
|---|
| 113 | $res = array();
|
|---|
| 114 |
|
|---|
| 115 | $res['checkout_action'] = $source['checkout_action'];
|
|---|
| 116 | $res['data'] = $source['data'];
|
|---|
| 117 | if ( isset($source['allow_subscribe']) )
|
|---|
| 118 | {
|
|---|
| 119 | $res['allow_subscribe'] = $source['allow_subscribe'];
|
|---|
| 120 | }
|
|---|
| 121 | if ( isset($source['subscribe_days']) )
|
|---|
| 122 | {
|
|---|
| 123 | $res['subscribe_days'] = $source['subscribe_days'];
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | switch ( $source['checkout_action'] )
|
|---|
| 127 | {
|
|---|
| 128 | case 'membership':
|
|---|
| 129 | $res['amount'] = $source['amount'];
|
|---|
| 130 | $prices = getMembershipPrices( $res['data'] );
|
|---|
| 131 | $pricingOptionExists = false;
|
|---|
| 132 | foreach ($prices as $days => $price)
|
|---|
| 133 | {
|
|---|
| 134 | if ( $res['amount'] == $price )
|
|---|
| 135 | {
|
|---|
| 136 | if ( $days == 0 )
|
|---|
| 137 | {
|
|---|
| 138 | $res['allow_subscribe'] = '';
|
|---|
| 139 | $res['subscribe_days'] = 0;
|
|---|
| 140 | }
|
|---|
| 141 | else
|
|---|
| 142 | {
|
|---|
| 143 | $res['allow_subscribe'] = 'on';
|
|---|
| 144 | $res['subscribe_days'] = $days;
|
|---|
| 145 | }
|
|---|
| 146 | $pricingOptionExists = true;
|
|---|
| 147 | break;
|
|---|
| 148 | }
|
|---|
| 149 | }
|
|---|
| 150 | if ( !$pricingOptionExists )
|
|---|
| 151 | return false;
|
|---|
| 152 | else
|
|---|
| 153 | return $res;
|
|---|
| 154 |
|
|---|
| 155 | case 'speeddating':
|
|---|
| 156 | return $res;
|
|---|
| 157 |
|
|---|
| 158 | case 'profiles':
|
|---|
| 159 | return $res;
|
|---|
| 160 |
|
|---|
| 161 | default:
|
|---|
| 162 | return false;
|
|---|
| 163 | }
|
|---|
| 164 | }
|
|---|
| 165 |
|
|---|
| 166 | /**
|
|---|
| 167 | * collect data from source
|
|---|
| 168 | */
|
|---|
| 169 | function CollectCheckoutInfo( $source )
|
|---|
| 170 | {
|
|---|
| 171 | global $collectDataArr;
|
|---|
| 172 | global $collectDataInputs;
|
|---|
| 173 |
|
|---|
| 174 | if ( !isset($source['checkout_action']) || strlen($source['data']) == 0 )
|
|---|
| 175 | return false;
|
|---|
| 176 |
|
|---|
| 177 | $collectDataArr['checkout_action'] = process_pass_data( $source['checkout_action'] );
|
|---|
| 178 | $collectDataArr['amount'] = process_pass_data( $source['amount'] );
|
|---|
| 179 | $collectDataArr['data'] = process_pass_data( $source['data'] );
|
|---|
| 180 | if ( isset($source['allow_subscribe']) )
|
|---|
| 181 | {
|
|---|
| 182 | $collectDataArr['allow_subscribe'] = process_pass_data( $source['allow_subscribe'] );
|
|---|
| 183 | }
|
|---|
| 184 | if ( isset($source['subscribe_days']) )
|
|---|
| 185 | {
|
|---|
| 186 | $collectDataArr['subscribe_days'] = process_pass_data( $source['subscribe_days'] );
|
|---|
| 187 | }
|
|---|
| 188 |
|
|---|
| 189 | $collectDataArr['description'] = returnDescByAction( $collectDataArr['checkout_action'], $collectDataArr['data'], true );
|
|---|
| 190 | if ( strlen($collectDataArr['description']) == 0 )
|
|---|
| 191 | return false;
|
|---|
| 192 |
|
|---|
| 193 | $collectDataInputs = '';
|
|---|
| 194 | $collectDataInputs .= "<input type=\"hidden\" name=\"checkout_action\" value=\"{$collectDataArr['checkout_action']}\" />\n";
|
|---|
| 195 | $collectDataInputs .= "<input type=\"hidden\" name=\"amount\" value=\"{$collectDataArr['amount']}\" />\n";
|
|---|
| 196 | $collectDataInputs .= "<input type=\"hidden\" name=\"data\" value=\"{$collectDataArr['data']}\" />\n";
|
|---|
| 197 | if ( isset($source['allow_subscribe']) )
|
|---|
| 198 | {
|
|---|
| 199 | $collectDataInputs .= "<input type=\"hidden\" name=\"allow_subscribe\" value=\"{$collectDataArr['allow_subscribe']}\" />\n";
|
|---|
| 200 | }
|
|---|
| 201 | if ( isset($source['subscribe_days']) )
|
|---|
| 202 | {
|
|---|
| 203 | $collectDataInputs .= "<input type=\"hidden\" name=\"subscribe_days\" value=\"{$collectDataArr['subscribe_days']}\" />\n";
|
|---|
| 204 | }
|
|---|
| 205 |
|
|---|
| 206 | return true;
|
|---|
| 207 | }
|
|---|
| 208 |
|
|---|
| 209 | /**
|
|---|
| 210 | * start checkout process
|
|---|
| 211 | */
|
|---|
| 212 | function StartCheckout( &$errorMessage )
|
|---|
| 213 | {
|
|---|
| 214 | global $dir;
|
|---|
| 215 | global $memberID; // defined in checkout.inc.php
|
|---|
| 216 | global $collectDataArr;
|
|---|
| 217 | global $enable_recurring;
|
|---|
| 218 | // these globals for module require call
|
|---|
| 219 | global $site;
|
|---|
| 220 | global $providerConf;
|
|---|
| 221 | global $checkoutFilename;
|
|---|
| 222 | global $checkoutURL;
|
|---|
| 223 | global $debugFilename;
|
|---|
| 224 |
|
|---|
| 225 | $providerID = (int)$_REQUEST['prov_id'];
|
|---|
| 226 | $providerRes = db_res( "SELECT `Name`, `CheckoutFilename` FROM `PaymentProviders` WHERE `ID` = {$providerID} AND `Active`" );
|
|---|
| 227 | if ( !$providerRes || mysql_num_rows($providerRes) == 0 )
|
|---|
| 228 | {
|
|---|
| 229 | $errorMessage = 'Wrong payment provider specified';
|
|---|
| 230 | return false;
|
|---|
| 231 | }
|
|---|
| 232 | $providerArr = mysql_fetch_assoc( $providerRes );
|
|---|
| 233 | if ( strlen(trim($providerArr['CheckoutFilename'])) )
|
|---|
| 234 | $checkoutFilename = $providerArr['CheckoutFilename'];
|
|---|
| 235 | else
|
|---|
| 236 | $checkoutFilename = $dir['checkout'] . $providerArr['Name'] . '.php';
|
|---|
| 237 | if ( !file_exists( $checkoutFilename ) )
|
|---|
| 238 | {
|
|---|
| 239 | $errorMessage = 'Checkout file not found';
|
|---|
| 240 | return false;
|
|---|
| 241 | }
|
|---|
| 242 |
|
|---|
| 243 | require_once( $checkoutFilename );
|
|---|
| 244 |
|
|---|
| 245 | $validateRes = moduleValidateConfiguration( $errorMessage );
|
|---|
| 246 | if ( !$validateRes )
|
|---|
| 247 | {
|
|---|
| 248 | return false;
|
|---|
| 249 | }
|
|---|
| 250 |
|
|---|
| 251 | $localTranID = initiateTransaction( $collectDataArr, $memberID, $providerID );
|
|---|
| 252 | if ( $localTranID === false )
|
|---|
| 253 | {
|
|---|
| 254 | $errorMessage = 'Transaction initiating error';
|
|---|
| 255 | return false;
|
|---|
| 256 | }
|
|---|
| 257 | $subscriptionalPayment = $enable_recurring && $collectDataArr['allow_subscribe'] == 'on'
|
|---|
| 258 | && $_REQUEST['prov_recurring'] == 'on';
|
|---|
| 259 |
|
|---|
| 260 | if ( $subscriptionalPayment )
|
|---|
| 261 | {
|
|---|
| 262 | $subsRes = initiateSubscription( $localTranID, $collectDataArr['subscribe_days'] );
|
|---|
| 263 | if ( !$subsRes )
|
|---|
| 264 | {
|
|---|
| 265 | $errorMessage = 'Subscription initiating error';
|
|---|
| 266 | return false;
|
|---|
| 267 | }
|
|---|
| 268 | }
|
|---|
| 269 |
|
|---|
| 270 | $startRes = moduleStartTransaction( $localTranID, $subscriptionalPayment, $collectDataArr['subscribe_days'] );
|
|---|
| 271 | if ( !$startRes )
|
|---|
| 272 | {
|
|---|
| 273 | $errorMessage = 'Transaction starting error';
|
|---|
| 274 | return false;
|
|---|
| 275 | }
|
|---|
| 276 |
|
|---|
| 277 | return true;
|
|---|
| 278 | }
|
|---|
| 279 |
|
|---|
| 280 | /**
|
|---|
| 281 | * prints errom message in checkout info box end empty provider list box
|
|---|
| 282 | */
|
|---|
| 283 | function PageCompErrorMessage( $message )
|
|---|
| 284 | {
|
|---|
| 285 | global $_page_cont;
|
|---|
| 286 | global $_ni;
|
|---|
| 287 | global $oTemplConfig;
|
|---|
| 288 |
|
|---|
| 289 | $designBox = DesignBoxContentBorder( _t('_Error'), '<center>'. $message .'</center>' );
|
|---|
| 290 | $content = "<div class=\"error_box\">\n{$designBox}\n</div>\n";
|
|---|
| 291 | $_page_cont[$_ni]['checkout_info'] = DesignBoxContent( _t('_Payment info'), $content, $oTemplConfig -> PageCompErrorMessage_db_num );
|
|---|
| 292 | $_page_cont[$_ni]['provider_list'] = '';
|
|---|
| 293 | }
|
|---|
| 294 |
|
|---|
| 295 | /**
|
|---|
| 296 | * common checkout info
|
|---|
| 297 | */
|
|---|
| 298 | function PageCompCheckoutInfo()
|
|---|
| 299 | {
|
|---|
| 300 | global $collectDataArr;
|
|---|
| 301 | global $doll;
|
|---|
| 302 |
|
|---|
| 303 | ob_start();
|
|---|
| 304 |
|
|---|
| 305 | ?>
|
|---|
| 306 | <table cellpadding="2" cellspacing="0" border="0" width="100%">
|
|---|
| 307 | <tr>
|
|---|
| 308 | <td class="field_caption" align="right" width="50%"><?= _t('_Payment description') ?>:</td>
|
|---|
| 309 | <td class="field_value" align="left" width="50%"><?= $collectDataArr['description'] ?></td>
|
|---|
| 310 | </tr>
|
|---|
| 311 | <tr>
|
|---|
| 312 | <td class="field_caption" align="right" width="50%"><?= _t('_Payment amount') ?>:</td>
|
|---|
| 313 | <td class="field_value" align="left" width="50%"><?= $doll . $collectDataArr['amount'] ?></td>
|
|---|
| 314 | </tr>
|
|---|
| 315 | <?
|
|---|
| 316 | if ( $collectDataArr['allow_subscribe'] == 'on' && (int)$collectDataArr['subscribe_days'] > 0 )
|
|---|
| 317 | {
|
|---|
| 318 | ?>
|
|---|
| 319 | <tr>
|
|---|
| 320 | <td class="field_caption" align="right" width="50%"><?= _t('_Possible subscription period') ?>:</td>
|
|---|
| 321 | <td class="field_value" align="left" width="50%"><?= $collectDataArr['subscribe_days'] . _t('_days') ?></td>
|
|---|
| 322 | </tr>
|
|---|
| 323 | <?
|
|---|
| 324 | }
|
|---|
| 325 | ?>
|
|---|
| 326 | </table>
|
|---|
| 327 | <?
|
|---|
| 328 |
|
|---|
| 329 | $content = ob_get_contents();
|
|---|
| 330 | ob_end_clean();
|
|---|
| 331 |
|
|---|
| 332 | $designBox = DesignBoxContentBorder( _t('_Payment info'), $content );
|
|---|
| 333 |
|
|---|
| 334 | $content = "<div class=\"checkout_info\">\n{$designBox}\n</div>\n";
|
|---|
| 335 |
|
|---|
| 336 | return $content;
|
|---|
| 337 | }
|
|---|
| 338 |
|
|---|
| 339 | /**
|
|---|
| 340 | * list of all active payment providers
|
|---|
| 341 | */
|
|---|
| 342 | function PageCompProviderList()
|
|---|
| 343 | {
|
|---|
| 344 | global $dir;
|
|---|
| 345 | global $site;
|
|---|
| 346 | global $enable_recurring;
|
|---|
| 347 | global $memberID; // defined in checkout.inc.php
|
|---|
| 348 | global $collectDataArr;
|
|---|
| 349 | global $collectDataInputs;
|
|---|
| 350 |
|
|---|
| 351 | $ret = '';
|
|---|
| 352 |
|
|---|
| 353 | $res = db_res( "SELECT `ID`, `Name`, `Caption`, `SupportsRecurring`, `LogoFilename` FROM `PaymentProviders` WHERE `Active`" );
|
|---|
| 354 |
|
|---|
| 355 | while ( $arr = mysql_fetch_assoc($res) )
|
|---|
| 356 | {
|
|---|
| 357 | if ( $enable_recurring && $collectDataArr['allow_subscribe'] == 'on' )
|
|---|
| 358 | {
|
|---|
| 359 | if ( $arr['SupportsRecurring'] )
|
|---|
| 360 | {
|
|---|
| 361 | $recurringField = "<input type=\"checkbox\" name=\"prov_recurring\" id=\"prov{$arr['ID']}_recurring_id\" style=\"vertical-align: middle;\" onclick=\"javascript: document.getElementById('subscribe{$arr['ID']}_days_id').disabled = !this.checked;\" /> <label for=\"prov{$arr['ID']}_recurring_id\">". _t('_recurring payment') ."</label>";
|
|---|
| 362 | if ( (int)$collectDataArr['subscribe_days'] == 0 )
|
|---|
| 363 | {
|
|---|
| 364 | $daysVariants = array( 10, 20, 30, 60, 180 );
|
|---|
| 365 | $recurringField .= " <select name=\"subscribe_days\" id=\"subscribe{$arr['ID']}_days_id\" disabled=\"disabled\" style=\"vertical-align: middle;\">\n";
|
|---|
| 366 | foreach ( $daysVariants as $days )
|
|---|
| 367 | {
|
|---|
| 368 | $recurringField .= "<option value=\"{$days}\">{$days} ". _t('_days') ."</option>";
|
|---|
| 369 | }
|
|---|
| 370 | $recurringField .= "</select>\n";
|
|---|
| 371 | }
|
|---|
| 372 | }
|
|---|
| 373 | else
|
|---|
| 374 | {
|
|---|
| 375 | $recurringField = _t('_recurring not supported');
|
|---|
| 376 | }
|
|---|
| 377 | }
|
|---|
| 378 | else
|
|---|
| 379 | {
|
|---|
| 380 | $recurringField = _t('_recurring not allowed');
|
|---|
| 381 | }
|
|---|
| 382 |
|
|---|
| 383 | ob_start();
|
|---|
| 384 | ?>
|
|---|
| 385 | <form id="f<?= $arr['Name'] ?>ProviderForm" action="<?= $_SERVER['PHP_SELF'] ?>" method="post" style="margin: 10px;">
|
|---|
| 386 | <input type="hidden" name="action" value="start_checkout" />
|
|---|
| 387 | <?= $collectDataInputs ?>
|
|---|
| 388 | <input type="hidden" name="prov_id" value="<?= $arr['ID'] ?>" />
|
|---|
| 389 | <table cellpadding="4" cellspacing="0" border="0" width="100%">
|
|---|
| 390 | <tr>
|
|---|
| 391 | <td align="left" width="35%" rowspan="2"><?= strlen($arr['LogoFilename']) > 0 && file_exists($dir['checkout'] . 'images/' . $arr['LogoFilename']) ? "<img src=\"{$site['checkout']}images/{$arr['LogoFilename']}\" alt=\"". process_line_output($arr['Caption']) ."\" />" : ' ' ?></td>
|
|---|
| 392 | <td class="field_caption" align="right" width="65%"><?= $recurringField ?></td>
|
|---|
| 393 | </tr>
|
|---|
| 394 | <tr>
|
|---|
| 395 | <td align="right" width="65%">
|
|---|
| 396 | <input type="submit" class="no" value="<?= _t('_Check Out') ?>" style="width: 100px; vertical-align: middle" />
|
|---|
| 397 | </td>
|
|---|
| 398 | </tr>
|
|---|
| 399 | </table>
|
|---|
| 400 | </form>
|
|---|
| 401 | <?
|
|---|
| 402 | $content = ob_get_contents();
|
|---|
| 403 | ob_end_clean();
|
|---|
| 404 |
|
|---|
| 405 | $designBox = DesignBoxContentBorder( $arr['Caption'], $content );
|
|---|
| 406 |
|
|---|
| 407 | $ret .= "<div class=\"provider_box\">\n{$designBox}\n</div>\n";
|
|---|
| 408 | }
|
|---|
| 409 |
|
|---|
| 410 | return $ret;
|
|---|
| 411 | }
|
|---|
| 412 |
|
|---|
| 413 | ?> |
|---|