get('culqi_enable'); $action = isset($_GET['a']) ? $_GET['a'] : null; $em = Database::getManager(); switch ($action) { case 'verifyPaypal': if (api_is_anonymous()) { break; } $userId = isset($_POST['id']) ? (int) $_POST['id'] : ''; $isUserHavePaypalAccount = $plugin->verifyPaypalAccountByBeneficiary($userId); if ($isUserHavePaypalAccount) { echo ''; } else { echo '* '.$plugin->get_lang('NoPayPalAccountDetected').''; } break; case 'saleInfo': if (api_is_anonymous()) { break; } $saleId = isset($_POST['id']) ? (int) $_POST['id'] : ''; $sale = $plugin->getSale($saleId); $productType = $sale['product_type'] == 1 ? get_lang('Course') : get_lang('Session'); $paymentType = $sale['payment_type'] == 1 ? 'Paypal' : $plugin->get_lang('BankTransfer'); $productInfo = $sale['product_type'] == 1 ? api_get_course_info_by_id($sale['product_id']) : api_get_session_info($sale['product_id']); $currency = $plugin->getSelectedCurrency(); if ($sale['product_type'] == 1) { $productImage = $productInfo['course_image_large']; } else { $productImage = ($productInfo['image']) ? $productInfo['image'] : Template::get_icon_path('session_default.png'); } $userInfo = api_get_user_info($sale['user_id']); $html = '

'.$sale['product_name'].'

'; $html .= '
'; $html .= '
'; $html .= ''; $html .= '
'; $html .= '
'; $html .= ''; $html .= '
'; $html .= '
'; echo $html; break; case 'stats': if (api_is_anonymous()) { break; } $stats = []; $stats['completed_count'] = 0; $stats['completed_total_amount'] = 0; $stats['pending_count'] = 0; $stats['pending_total_amount'] = 0; $stats['canceled_count'] = 0; $stats['canceled_total_amount'] = 0; $completedPayouts = $plugin->getPayouts(BuyCoursesPlugin::PAYOUT_STATUS_COMPLETED); $pendingPayouts = $plugin->getPayouts(BuyCoursesPlugin::PAYOUT_STATUS_PENDING); $canceledPayouts = $plugin->getPayouts(BuyCoursesPlugin::PAYOUT_STATUS_CANCELED); $currency = $plugin->getSelectedCurrency(); foreach ($completedPayouts as $completed) { $stats['completed_count'] = count($completedPayouts); $stats['completed_total_amount'] += $completed['commission']; $stats['completed_total_amount'] = number_format($stats['completed_total_amount'], 2); } foreach ($pendingPayouts as $pending) { $stats['pending_count'] = count($pendingPayouts); $stats['pending_total_amount'] += $pending['commission']; $stats['pending_total_amount'] = number_format($stats['pending_total_amount'], 2); } foreach ($canceledPayouts as $canceled) { $stats['canceled_count'] = count($canceledPayouts); $stats['canceled_total_amount'] += $canceled['commission']; $stats['canceled_total_amount'] = number_format($stats['canceled_total_amount'], 2); } $html = '
' .'

' .'

' .'

'; $html .= '
'; echo $html; break; case 'processPayout': if (api_is_anonymous()) { break; } $html = ''; $allPays = []; $totalAccounts = 0; $totalPayout = 0; $payouts = isset($_POST['payouts']) ? $_POST['payouts'] : ''; if (!$payouts) { echo Display::return_message( get_plugin_lang("SelectOptionToProceed", "BuyCoursesPlugin"), 'error', false ); break; } foreach ($payouts as $index => $id) { $allPays[] = $plugin->getPayouts(BuyCoursesPlugin::PAYOUT_STATUS_PENDING, $id); } foreach ($allPays as $payout) { $totalPayout += number_format($payout['commission'], 2); $totalAccounts++; } $currentCurrency = $plugin->getSelectedCurrency(); $isoCode = $currentCurrency['iso_code']; $html .= '

'.get_plugin_lang("VerifyTotalAmountToProceedPayout", "BuyCoursesPlugin").'

'; $html .= '' .'

' .'

' .'

'; $html .= '

'.get_plugin_lang("CautionThisProcessCantBeCanceled", "BuyCoursesPlugin").'

'; $html .= '

'; $html .= '
'; echo $html; break; case 'proceedPayout': if (api_is_anonymous()) { break; } $paypalParams = $plugin->getPaypalParams(); $pruebas = $paypalParams['sandbox'] == 1; $paypalUsername = $paypalParams['username']; $paypalPassword = $paypalParams['password']; $paypalSignature = $paypalParams['signature']; require_once "paypalfunctions.php"; $allPayouts = []; $totalAccounts = 0; $totalPayout = 0; $payouts = isset($_POST['payouts']) ? $_POST['payouts'] : ''; if (!$payouts) { echo Display::return_message( get_plugin_lang("SelectOptionToProceed", "BuyCoursesPlugin"), 'error', false ); break; } foreach ($payouts as $index => $id) { $allPayouts[] = $plugin->getPayouts( BuyCoursesPlugin::PAYOUT_STATUS_PENDING, $id ); } $currentCurrency = $plugin->getSelectedCurrency(); $isoCode = $currentCurrency['iso_code']; $result = MassPayment($allPayouts, $isoCode); if ($result['ACK'] === 'Success') { foreach ($allPayouts as $payout) { $plugin->setStatusPayouts( $payout['id'], BuyCoursesPlugin::PAYOUT_STATUS_COMPLETED ); if ($plugin->get('invoicing_enable') === 'true') { $plugin->setInvoice($payout['id']); } } echo Display::return_message( get_plugin_lang("PayoutSuccess", "BuyCoursesPlugin"), 'success', false ); } else { echo Display::return_message( ''.$result['L_SEVERITYCODE0'].' '.$result['L_ERRORCODE0'].' - '.$result['L_SHORTMESSAGE0'] .'
', 'error', false ); } break; case 'cancelPayout': if (api_is_anonymous()) { break; } // $payoutId only gets used in setStatusPayout(), where it is filtered $payoutId = isset($_POST['id']) ? $_POST['id'] : ''; $plugin->setStatusPayouts( $payoutId, BuyCoursesPlugin::PAYOUT_STATUS_CANCELED ); echo ''; break; case 'culqi_cargo': if (!$culqiEnable) { break; } $tokenId = $_REQUEST['token_id']; $saleId = $_REQUEST['sale_id']; if (!$tokenId || !$saleId) { break; } $sale = $plugin->getSale($saleId); if (!$sale) { break; } require_once 'Requests.php'; Requests::register_autoloader(); require_once 'culqi.php'; $culqiParams = $plugin->getCulqiParams(); // API Key y autenticación $SECRET_API_KEY = $culqiParams['api_key']; $culqi = new Culqi\Culqi(['api_key' => $SECRET_API_KEY]); $environment = $culqiParams['integration']; $environment = $environment ? BuyCoursesPlugin::CULQI_INTEGRATION_TYPE : BuyCoursesPlugin::CULQI_PRODUCTION_TYPE; $culqi->setEnv($environment); $user = api_get_user_info(); $currency = $plugin->getSelectedCurrency(); try { $cargo = $culqi->Cargos->create([ "moneda" => $currency['iso_code'], "monto" => intval(floatval($sale['price']) * 100), "usuario" => $user['username'], "descripcion" => $sale['product_name'], "pedido" => $sale['reference'], "codigo_pais" => "PE", "direccion" => get_lang('None'), "ciudad" => get_lang('None'), "telefono" => 0, "nombres" => $user['firstname'], "apellidos" => $user['lastname'], "correo_electronico" => $user['email'], "token" => $tokenId, ]); if (is_object($cargo)) { $saleIsCompleted = $plugin->completeSale($sale['id']); if ($saleIsCompleted) { Display::addFlash( $plugin->getSubscriptionSuccessMessage($sale) ); } } echo json_encode($cargo); } catch (Exception $e) { $cargo = json_decode($e->getMessage(), true); $plugin->cancelSale($sale['id']); unset($_SESSION['bc_sale_id']); if (is_array($cargo)) { Display::addFlash( Display::return_message( sprintf($plugin->get_lang('ErrorOccurred'), $cargo['codigo'], $cargo['mensaje']), 'error', false ) ); } else { Display::addFlash( Display::return_message( $plugin->get_lang('ErrorContactPlatformAdmin'), 'error', false ) ); } } break; case 'culqi_cargo_service': if (!$culqiEnable) { break; } $tokenId = $_REQUEST['token_id']; $serviceSaleId = $_REQUEST['service_sale_id']; if (!$tokenId || !$serviceSaleId) { break; } $serviceSale = $plugin->getServiceSale($serviceSaleId); if (!$serviceSale) { break; } require_once 'Requests.php'; Requests::register_autoloader(); require_once 'culqi.php'; $culqiParams = $plugin->getCulqiParams(); // API Key y autenticación $SECRET_API_KEY = $culqiParams['api_key']; $culqi = new Culqi\Culqi(['api_key' => $SECRET_API_KEY]); $environment = $culqiParams['integration']; $environment = $environment ? BuyCoursesPlugin::CULQI_INTEGRATION_TYPE : BuyCoursesPlugin::CULQI_PRODUCTION_TYPE; $culqi->setEnv($environment); $user = api_get_user_info(); try { $cargo = $culqi->Cargos->create([ "moneda" => $serviceSale['currency'], "monto" => intval(floatval($serviceSale['price']) * 100), "usuario" => $user['username'], "descripcion" => $serviceSale['service']['name'], "pedido" => $serviceSale['reference'], "codigo_pais" => "PE", "direccion" => get_lang('None'), "ciudad" => get_lang('None'), "telefono" => 0, "nombres" => $user['firstname'], "apellidos" => $user['lastname'], "correo_electronico" => $user['email'], "token" => $tokenId, ]); if (is_object($cargo)) { $saleIsCompleted = $plugin->completeServiceSale($serviceSale['id']); if ($saleIsCompleted) { Display::addFlash( Display::return_message( sprintf( $plugin->get_lang('SubscriptionToCourseXSuccessful'), $serviceSale['service']['name'] ), 'success' ) ); } } echo json_encode($cargo); } catch (Exception $e) { $cargo = json_decode($e->getMessage(), true); $plugin->cancelServiceSale($serviceSale['id']); unset($_SESSION['bc_sale_id']); if (is_array($cargo)) { Display::addFlash( Display::return_message( sprintf($plugin->get_lang('ErrorOccurred'), $cargo['codigo'], $cargo['mensaje']), 'error', false ) ); } else { Display::addFlash( Display::return_message( $plugin->get_lang('ErrorContactPlatformAdmin'), 'error', false ) ); } } break; case 'service_sale_info': $id = isset($_POST['id']) ? (int) $_POST['id'] : 0; $serviceSale = $plugin->getServiceSale($id); $isAdmin = api_is_platform_admin(); if (!$serviceSale) { break; } $ajaxCallFile = $plugin->getPath('SRC').'buycourses.ajax.php'; $serviceImg = $plugin->getPath('SERVICE_IMAGES').$serviceSale['service']['image']; $html = ""; $html .= "
"; $html .= "{$plugin->get_lang('ServiceInformation')}"; $html .= ""; $html .= "{$plugin->get_lang('SaleInfo')}"; $html .= ""; $html .= "
"; $html .= "
"; $html .= "
"; $html .= "
"; $html .= "
"; $html .= $buttons; $html .= "
"; $html .= "
"; $html .= "
"; $html .= ""; echo $html; break; case 'service_sale_confirm': $id = isset($_POST['id']) ? (int) $_POST['id'] : 0; $serviceSale = $plugin->getServiceSale($id); $response = $plugin->completeServiceSale($id); $html = "
"; if ($response) { $html .= Display::return_message( sprintf($plugin->get_lang('SubscriptionToServiceXSuccessful'), $serviceSale['service']['name']), 'success' ); } else { $html .= Display::return_message('Error - '.$plugin->get_lang('ErrorContactPlatformAdmin'), 'error'); } $html .= "".$plugin->get_lang('ClickHereToFinish').""; $html .= "
"; $html .= ""; echo $html; break; case 'service_sale_cancel': $id = isset($_POST['id']) ? (int) $_POST['id'] : 0; $response = $plugin->cancelServiceSale($id); $html = ''; $html .= "
"; if ($response) { $html .= Display::return_message( $plugin->get_lang('OrderCancelled'), 'warning' ); } else { $html .= Display::return_message('Error - '.$plugin->get_lang('ErrorContactPlatformAdmin'), 'error'); } $html .= "".$plugin->get_lang('ClickHereToFinish').""; $html .= "
"; $html .= ""; echo $html; break; }