public function execute() { $templateProcessor = SJB_System::getTemplateProcessor(); $errors = array(); $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null; $gateway_id = isset($_REQUEST['gateway']) ? $_REQUEST['gateway'] : null; $formSubmitted = SJB_Request::getVar('submit'); $gateway_sid = SJB_PaymentGatewayManager::getSIDByID($gateway_id); if ($_SERVER['REQUEST_METHOD'] == 'GET' && !empty($action)) { if ($action == 'deactivate') { SJB_PaymentGatewayManager::deactivateByID($gateway_id); } elseif ($action == 'activate') { SJB_PaymentGatewayManager::activateByID($gateway_id); } } if ($_SERVER['REQUEST_METHOD'] == 'POST') { $gateway = SJB_PaymentGatewayManager::createObjectByID($gateway_id, $_REQUEST); $gateway->dontSaveProperty('id'); $gateway->dontSaveProperty('caption'); $gateway->setSID($gateway_sid); if ($gateway->isValid()) { if (SJB_PaymentGatewayManager::saveGateway($gateway) !== false) { $templateProcessor->assign('gatewaySaved', true); if ($formSubmitted == 'save_gateway') { $siteUrl = SJB_System::getSystemsettings('SITE_URL') . '/system/payment/gateways/?gatewaySaved=1'; SJB_HelperFunctions::redirect($siteUrl); } } else { $errors['SETTINGS_SAVED_WITH_PROBLEMS'] = 1; } } else { $errors = $gateway->getErrors(); } } $gateway = SJB_PaymentGatewayManager::getObjectByID($gateway_id); $gateway_form = new SJB_Form($gateway); $gateway_form->registerTags($templateProcessor); $gateway_form->makeDisabled('id'); $gateway_form->makeDisabled('caption'); $countryCode = $gateway->getPropertyValue('country'); if (empty($countryCode)) { $countryValue = SJB_CountriesManager::getCountrySIDByCountryCode('US'); $gateway->setPropertyValue('country', $countryValue); } if (empty($gateway)) { $errors['GATEWAY_NOT_FOUND'] = 1; $templateProcessor->assign('errors', $errors); $templateProcessor->display('configure_gateway.tpl'); return; } $gateway_info = SJB_PaymentGatewayManager::getInfoBySID($gateway_sid); $form_fields = $gateway_form->getFormFieldsInfo(); $templateProcessor->assign('gateway', $gateway_info); $templateProcessor->assign('form_fields', $form_fields); $templateProcessor->assign('errors', $errors); $templateProcessor->display('configure_gateway.tpl'); }
public function execute() { $request_uri = $_SERVER['REQUEST_URI']; $template_processor = SJB_System::getTemplateProcessor(); $callback_page_uri = ''; preg_match('#.*/system/payment/callback/([^/?]+)#', $request_uri, $mm); if (!empty($mm)) { $gateway_id = $mm[1]; $redirectPage = $callback_page_uri . $gateway_id . "/"; preg_match("(.*{$redirectPage}([^/]*)/?)", $request_uri, $invoice_sid); $invoice_sid = !empty($invoice_sid[1]) ? $invoice_sid[1] : ''; $redirectPage = $callback_page_uri . $gateway_id . "/" . $invoice_sid; preg_match("(.*{$redirectPage}([^/]*)/?)", $request_uri, $tt); $redirectPage = !empty($tt[1]) ? $tt[1] : ''; $invoice = SJB_InvoiceManager::getObjectBySID($invoice_sid); if (!empty($invoice) && $invoice->getStatus() == SJB_Invoice::INVOICE_STATUS_PAID) { SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/payment-completed/"); } $gateway = SJB_PaymentGatewayManager::getObjectByID($gateway_id); $gateway_caption = $gateway->getPropertyValue('caption'); $invoice = $gateway->getPaymentFromCallbackData($_REQUEST); SJB_PaymentLogManager::recordPaymentLog($gateway->getPaymentStatusFromCallbackData($_REQUEST), $gateway_caption, $_REQUEST); if (is_null($invoice)) { $errors = $gateway->getErrors(); $template_processor->assign('errors', $errors); $template_processor->display('callback_payment_page.tpl'); } else { $status = $invoice->getStatus(); if ($status == SJB_Invoice::INVOICE_STATUS_VERIFIED) { SJB_Statistics::addStatisticsFromInvoice($invoice); $success_url = $invoice->getSuccessPageURL(); $page = empty($redirectPage) ? '' : '&' . $redirectPage; SJB_HelperFunctions::redirect($success_url . '?invoice_sid=' . $invoice->getSID() . $page); } elseif ($status == SJB_Invoice::INVOICE_STATUS_PENDING) { $template_processor->assign('message', 'INVOICE_WAITING'); $template_processor->display('callback_payment_page.tpl'); } else { SJB_InvoiceManager::markUnPaidInvoiceBySID($invoice_sid); $payment_error = 1; if ($gateway_id == 'paypal_pro') { $httpPostResponse = SJB_Request::getVar('http_post_response', false); if (!empty($httpPostResponse['L_SHORTMESSAGE0']) && urldecode($httpPostResponse['L_SHORTMESSAGE0']) == 'Authentication/Authorization Failed') { $payment_error = 2; } } SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . "/view-invoice/?sid=" . $invoice_sid . "&payment_error=" . $payment_error . "&payment_gateway=" . $gateway_id); } } } else { $errors['INVOICE_ID_IS_NOT_SET'] = 1; $template_processor->assign('errors', $errors); $template_processor->display('callback_payment_page.tpl'); } }
public static function getPaymentForms($invoice) { $activeGateways = SJB_PaymentGatewayManager::getActivePaymentGatewaysList(); $gatewaysFormInfo = array(); foreach ($activeGateways as $gatewayInfo) { if ($invoice->isRecurring() && empty($gatewayInfo['recurrable'])) { continue; } $gateway = SJB_PaymentGatewayManager::getObjectByID($gatewayInfo['id'], $invoice->isRecurring()); $gatewaysFormInfo[$gateway->getPropertyValue('id')] = $gateway->buildTransactionForm($invoice); } return $gatewaysFormInfo; }
public static function deleteAllContractsByUserSID($user_sid) { $userContracts = SJB_DB::query("SELECT `id`, `gateway_id`, `recurring_id` FROM `contracts` WHERE `user_sid` = ?n", $user_sid); foreach ($userContracts as $contract) { // 'paypal_standard' != $contract['gateway_id'] - redirect on paypal // cancel recurring if (!empty($contract['gateway_id']) && !empty($contract['recurring_id']) && 'paypal_standard' != $contract['gateway_id'] && ($gateway = SJB_PaymentGatewayManager::getObjectByID($contract['gateway_id'], true))) { $gateway->cancelSubscription($contract['recurring_id']); } SJB_ContractManager::deleteContractIDFromNotificationSended($contract['id']); } return SJB_DB::query("DELETE FROM `contracts` WHERE `user_sid`=?n", $user_sid); }
public function execute() { if (!preg_match("(.*/system/payment/notifications/([^/]+)/?)", $_SERVER['REQUEST_URI'], $matches)) { echo '<p class="error">Gateway parameter is missing</p>'; exit; } $gateway_id = $matches[1]; $gateway = SJB_PaymentGatewayManager::getObjectByID($gateway_id, true); if (!$gateway) { echo '<p class="error">Invalid gateway</p>'; exit; } $gateway->handleRecurringNotification($_REQUEST); $gateway_caption = $gateway->getPropertyValue('caption'); SJB_PaymentLogManager::recordPaymentLog($gateway->getPaymentStatusFromCallbackData($_REQUEST), $gateway_caption, $_REQUEST); }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $gateway = SJB_PaymentGatewayManager::getObjectByID(SJB_Request::getVar('gateway'), true); if (!empty($gateway)) { $invoiceID = SJB_Request::getVar('invoiceID', false); $cancelSubscriptionResult = $gateway->cancelSubscription(SJB_Request::getVar('subscriptionId'), $invoiceID); $errors = array(); if ($cancelSubscriptionResult !== true) { $errors = $cancelSubscriptionResult; } else { SJB_ContractManager::removeSubscriptionId(SJB_Request::getVar('subscriptionId')); SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/my-products/?cancelRecurringContract=' . SJB_Request::getVar('contractId')); } $tp->assign('errors', $errors); $tp->display('cancel_recurring.tpl'); } }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $errors = array(); $gatewayId = SJB_Request::getVar('gatewayId', 'cash_gateway'); $gateway = SJB_PaymentGatewayManager::getObjectByID($gatewayId); if (isset($gateway) && in_array($gatewayId, array('cash_gateway', 'wire_transfer'))) { $invoiceSid = SJB_Request::getVar('invoice_sid'); $invoice = SJB_InvoiceManager::getObjectBySID($invoiceSid); if (isset($invoice)) { $currentUser = SJB_UserManager::getCurrentUserInfo(); if ($currentUser['sid'] == $invoice->getPropertyValue('user_sid')) { if ($invoice->getStatus() == SJB_Invoice::INVOICE_STATUS_UNPAID) { $tp->assign('invoice_sid', $invoiceSid); $tp->assign('item_name', $invoice->getProductNames()); $tp->assign('amount', $invoice->getPropertyValue('total')); $tp->assign('user', $currentUser); SJB_InvoiceManager::saveInvoice($invoice); SJB_ShoppingCart::deleteItemsFromCartByUserSID($currentUser['sid']); } else { $errors['INVOICE_IS_NOT_UNPAID'] = true; } } else { $errors['NOT_OWNER'] = true; } } else { $errors['INVALID_INVOICE_ID'] = true; } $template = $gateway->getTemplate(); $tp->assign('errors', $errors); } else { $errors['INVALID_GATEWAY'] = true; $tp->assign('ERRORS', $errors); $template = 'errors.tpl'; } $tp->display($template); }
public function execute() { $invoiceSID = SJB_Request::getVar('invoice_sid', null, 'default', 'int'); $tp = SJB_System::getTemplateProcessor(); $action = SJB_Request::getVar('action', false); $checkPaymentErrors = array(); $currentUser = SJB_UserManager::getCurrentUser(); if ($action == 'pay_for_products') { $subscribe = SJB_Request::getVar('subscribe', false); $subTotalPrice = SJB_Request::getVar('sub_total_price', 0); $products = SJB_ShoppingCart::getAllProductsByUserSID($currentUser->getSID()); $codeInfo = array(); $index = 1; $items = array(); foreach ($products as $product) { $product_info = unserialize($product['product_info']); $items['products'][$index] = $product_info['sid']; $qty = !empty($product_info['number_of_listings']) ? $product_info['number_of_listings'] : null; if ($qty > 0) { $items['price'][$index] = round($product_info['price'] / $qty, 2); } else { $items['price'][$index] = round($product_info['price'], 2); } $items['amount'][$index] = $product_info['price']; $items['custom_item'][$index] = ""; $items['qty'][$index] = $qty; $items['custom_info'][$index]['shoppingCartRecord'] = $product['sid']; if ($product_info['product_type'] == 'banners' && !empty($product_info['banner_info'])) { $items['custom_info'][$index]['banner_info'] = $product_info['banner_info']; } $index++; SJB_PromotionsManager::preparePromoCodeInfoByProductPromoCodeInfo($product_info, $codeInfo); } $userSID = $currentUser->getSID(); $invoiceSID = SJB_InvoiceManager::generateInvoice($items, $userSID, $subTotalPrice, SJB_System::getSystemSettings('SITE_URL') . "/create-contract/", (bool) $subscribe); SJB_PromotionsManager::addCodeToHistory($codeInfo, $invoiceSID, $userSID); } $gatewayId = SJB_Request::getVar('gw', false); if (SJB_Request::$method == SJB_Request::METHOD_POST && !$action && $gatewayId == 'authnet_sim') { if (isset($_REQUEST['submit'])) { $gateway = SJB_PaymentGatewayManager::getObjectByID($gatewayId, true); $subscriptionResult = $gateway->createSubscription($_REQUEST); if ($subscriptionResult !== true) { $tp->assign('form_submit_url', $_SERVER['REQUEST_URI']); $tp->assign('form_data_source', $_REQUEST); $tp->assign('errors', $subscriptionResult); $tp->display('recurring_payment_page.tpl'); } else { SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/my-products/?subscriptionComplete=true'); } } else { $tp->assign('form_submit_url', $_SERVER['REQUEST_URI']); $tp->assign('form_data_source', $_REQUEST); $tp->display('recurring_payment_page.tpl'); } } else { if (!is_null($invoiceSID)) { $invoice_info = SJB_InvoiceManager::getInvoiceInfoBySID($invoiceSID); $invoice = new SJB_Invoice($invoice_info); if (SJB_PromotionsManager::isPromoCodeExpired($invoiceSID)) { $checkPaymentErrors['PROMOTION_TOO_MANY_USES'] = true; } else { $invoice->setSID($invoiceSID); if (count($invoice->isValid($invoiceSID)) == 0) { $invoiceUserSID = $invoice->getPropertyValue('user_sid'); $currentUserSID = SJB_UserManager::getCurrentUserSID(); if ($invoiceUserSID === $currentUserSID) { $payment_gateway_forms = SJB_InvoiceManager::getPaymentForms($invoice); $tp->assign('productsNames', $invoice->getProductNames()); $tp->assign('gateways', $payment_gateway_forms); $tp->assign('invoice_info', $invoice_info); } else { $checkPaymentErrors['NOT_OWNER'] = true; } } else { $checkPaymentErrors['WRONG_INVOICE_PARAMETERS'] = true; } } $tp->assign('checkPaymentErrors', $checkPaymentErrors); $tp->display('invoice_payment_page.tpl'); } else { $tp->display('recurring_payment_page.tpl'); } } }
private function assignIcons() { $payPalPro = SJB_PaymentGatewayManager::getObjectByID(self::GATEWAY_ID, false); $countrySID = $payPalPro->getPropertyValue('country'); $country = SJB_CountriesManager::getCountryInfoBySID($countrySID); $creditCards = array(); if ($country) { switch ($country['country_code']) { case 'US': $creditCards = array("visa", "mastercard", "discovery", "amex"); break; case 'CA': $creditCards = array("visa", "mastercard"); break; case 'UK': $creditCards = array("visa", "mastercard", "maestro"); break; } $this->getTemplateProcessor()->assign('creditCards', $creditCards); } }