public function index(array $params) { if (!($goalId = $params['goalId'])) { throw new Redirect404Exception(); } $fundraisingService = OCSFUNDRAISING_BOL_Service::getInstance(); $billingService = BOL_BillingService::getInstance(); $this->assign('currency', $billingService->getActiveCurrency()); if (!($goal = $fundraisingService->getGoalById($goalId))) { throw new Redirect404Exception(); } $this->assign('goal', $goal); $lang = OW::getLanguage(); $userId = OW::getUser()->getId(); $this->assign('userId', $userId); $form = new DonateForm($userId); $this->addForm($form); $form->getElement('amount')->setValue(floatval($goal['dto']->amountMin)); if (OW::getRequest()->isPost() && $form->isValid($_POST)) { $values = $form->getValues(); if (empty($values['gateway']['url']) || empty($values['gateway']['key']) || !($gateway = $billingService->findGatewayByKey($values['gateway']['key']) || !$gateway->active)) { OW::getFeedback()->error($lang->text('base', 'billing_gateway_not_found')); $this->redirectToAction('index'); } // create donation product adapter object $productAdapter = new OCSFUNDRAISING_CLASS_DonationProductAdapter(); // sale object $sale = new BOL_BillingSale(); $sale->pluginKey = 'ocsfundraising'; $sale->entityDescription = $goal['dto']->name; $sale->entityKey = $productAdapter->getProductKey(); $sale->entityId = $goalId; $sale->price = floatval($values['amount']); $sale->userId = $userId ? $userId : 0; $sale->recurring = false; if (!$userId && !empty($values['username'])) { $sale->setExtraData(array('username' => $values['username'])); } $saleId = $billingService->initSale($sale, $values['gateway']['key']); if ($saleId) { // sale Id is temporarily stored in session $billingService->storeSaleInSession($saleId); $billingService->setSessionBackUrl(OW::getRouter()->urlForRoute(OCSFUNDRAISING_CLASS_DonationProductAdapter::RETURN_ROUTE, array('goalId' => $goalId))); // redirect to gateway form page $this->redirect($values['gateway']['url']); } } $this->setPageHeading($goal['dto']->name); $this->setPageHeadingIconClass('ow_ic_user'); }
public function deliverSale(BOL_BillingSale $sale) { $goalId = $sale->entityId; $service = OCSFUNDRAISING_BOL_Service::getInstance(); $goal = $service->getGoalById($goalId); if (!$goal) { return false; } $extra = $sale->getExtraData(); $donation = new OCSFUNDRAISING_BOL_Donation(); $donation->amount = $sale->totalAmount; $donation->userId = !empty($sale->userId) ? $sale->userId : null; $donation->donationStamp = time(); $donation->goalId = $sale->entityId; $donation->username = !empty($extra['username']) ? $extra['username'] : null; $service->registerDonation($donation); $goal['dto']->amountCurrent += $donation->amount; $service->update($goal['dto']); return true; }
public function deliverSale(BOL_BillingSale $sale) { $extraData = $sale->getExtraData(); $sponsor = new SPONSORS_BOL_Sponsor(); $sponsor->name = $extraData->sponsorName; $sponsor->email = $extraData->sponsorEmail; $sponsor->website = $extraData->sponsorWebsite; $sponsor->image = $extraData->sponsorImage; $sponsor->price = $extraData->sponsorAmount; $sponsor->userId = $sale->userId; $sponsor->status = $extraData->status; $sponsor->validity = $extraData->validity; $sponsor->timestamp = time(); if (SPONSORS_BOL_Service::getInstance()->addSponsor($sponsor)) { if ($extraData->status == '1') { OW::getFeedback()->info(OW::getLanguage()->text('sponsors', 'sponsor_live_notification')); } else { OW::getFeedback()->info(OW::getLanguage()->text('sponsors', 'sponsor_live_notification_after_approval')); } return true; } return false; }
public function sponsor() { $language = OW::getLanguage(); $config = OW::getConfig(); $sponsorForm = new Form('sponsorForm'); $sponsorForm->setEnctype('multipart/form-data'); $element = new TextField('sponsorName'); $element->setRequired(true); $element->setLabel($language->text('sponsors', 'sponsor_name')); $element->setInvitation($language->text('sponsors', 'sponsor_name_desc')); $element->setHasInvitation(true); $sponsorForm->addElement($element); $element = new TextField('sponsorEmail'); $element->setRequired(true); $validator = new EmailValidator(); $validator->setErrorMessage($language->text('sponsors', 'invalid_email_format')); $element->addValidator($validator); $element->setLabel($language->text('sponsors', 'sponsor_email')); $element->setInvitation($language->text('sponsors', 'sponsor_email_desc')); $element->setHasInvitation(true); $sponsorForm->addElement($element); $element = new TextField('sponsorWebsite'); $element->setRequired(true); $validator = new UrlValidator(); $validator->setErrorMessage($language->text('sponsors', 'invalid_url_format')); $element->addValidator($validator); $element->setLabel($language->text('sponsors', 'sponsor_website')); $element->setInvitation($language->text('sponsors', 'sponsor_website_desc')); $element->setHasInvitation(true); $sponsorForm->addElement($element); if ($config->getValue('sponsors', 'minimumPayment') > 0) { $element = new TextField('sponsorAmount'); $element->setRequired(true); $element->setValue($config->getValue('sponsors', 'minimumPayment')); $minAmount = $config->getValue('sponsors', 'minimumPayment'); $validator = new FloatValidator($minAmount); $validator->setErrorMessage($language->text('sponsors', 'invalid_sponsor_amount', array('minAmount' => $minAmount))); $element->addValidator($validator); $element->setLabel($language->text('sponsors', 'sponsor_payment_amount')); $element->setInvitation($language->text('sponsors', 'sponsor_payment_amount_desc', array('minAmount' => $minAmount))); $element->setHasInvitation(true); $sponsorForm->addElement($element); } $element = new FileField('sponsorImage'); $element->setLabel($language->text('sponsors', 'sponsorsh_image_file')); $sponsorForm->addElement($element); if ($config->getValue('sponsors', 'minimumPayment') > 0) { $element = new BillingGatewaySelectionField('gateway'); $element->setRequired(true); $element->setLabel($language->text('sponsors', 'payment_gatway_selection')); $sponsorForm->addElement($element); } $element = new Submit('becomeSponsor'); $element->setValue(OW::getLanguage()->text('sponsors', 'become_sponsor_btn')); $sponsorForm->addElement($element); if (OW::getRequest()->isPost()) { if ($sponsorForm->isValid($_POST)) { $values = $sponsorForm->getValues(); if (isset($_FILES['sponsorImage']) && in_array(UTIL_File::getExtension($_FILES['sponsorImage']['name']), $this->allowedImageExtensions)) { $backupPath = OW::getPluginManager()->getPlugin('sponsors')->getUserFilesDir() . $_FILES['sponsorImage']['name']; move_uploaded_file($_FILES['sponsorImage']['tmp_name'], $backupPath); $sponsorImageFile = $_FILES['sponsorImage']['name']; } else { $sponsorImageFile = "defaultSponsor.jpg"; } if (isset($values['sponsorAmount']) && $values['gateway']) { $billingService = BOL_BillingService::getInstance(); if (empty($values['gateway']['url']) || empty($values['gateway']['key']) || !($gateway = $billingService->findGatewayByKey($values['gateway']['key']) || !$gateway->active)) { OW::getFeedback()->error($language->text('base', 'billing_gateway_not_found')); $this->redirect(); } $productAdapter = new SPONSORS_CLASS_SponsorProductAdapter(); $sale = new BOL_BillingSale(); $sale->pluginKey = 'sponsors'; $sale->entityDescription = $language->text('sponsors', 'sponsor_payment_gateway_text'); $sale->entityKey = $productAdapter->getProductKey(); $sale->entityId = time(); $sale->price = floatval($values['sponsorAmount']); $sale->period = null; $sale->userId = OW::getUser()->getId() ? OW::getUser()->getId() : 0; $sale->recurring = 0; $extraData = array(); $extraData['sponsorName'] = $values['sponsorName']; $extraData['sponsorEmail'] = $values['sponsorEmail']; $extraData['sponsorWebsite'] = $values['sponsorWebsite']; $extraData['sponsorAmount'] = $values['sponsorAmount']; $extraData['sponsorImage'] = $sponsorImageFile; $extraData['status'] = $config->getValue('sponsors', 'autoApprove') == '1' ? 1 : 0; $extraData['validity'] = $config->getValue('sponsors', 'sponsorValidity'); $sale->setExtraData($extraData); $saleId = $billingService->initSale($sale, $values['gateway']['key']); if ($saleId) { $billingService->storeSaleInSession($saleId); $billingService->setSessionBackUrl($productAdapter->getProductOrderUrl()); OW::getApplication()->redirect($values['gateway']['url']); } } else { $sponsor = new SPONSORS_BOL_Sponsor(); $sponsor->name = $values['sponsorName']; $sponsor->email = $values['sponsorEmail']; $sponsor->website = $values['sponsorWebsite']; $sponsor->price = 0; $sponsor->image = $sponsorImageFile; $sponsor->userId = OW::getUser()->getId() ? OW::getUser()->getId() : 0; $sponsor->status = $config->getValue('sponsors', 'autoApprove') == '1' ? 1 : 0; $sponsor->validity = $config->getValue('sponsors', 'sponsorValidity'); $sponsor->timestamp = time(); if (SPONSORS_BOL_Service::getInstance()->addSponsor($sponsor)) { if ($sponsor->status == 1) { OW::getFeedback()->info(OW::getLanguage()->text('sponsors', 'sponsor_live_notification')); } else { OW::getFeedback()->info(OW::getLanguage()->text('sponsors', 'sponsor_live_notification_after_approval')); } } else { OW::getFeedback()->error(OW::getLanguage()->text('sponsors', 'sponsor_add_error')); } } } } $this->addForm($sponsorForm); $fields = array(); foreach ($sponsorForm->getElements() as $element) { if (!$element instanceof HiddenField) { $fields[$element->getName()] = $element->getName(); } } $this->assign('formData', $fields); $this->setPageHeading(OW::getLanguage()->text('sponsors', 'become_sponsor_heading')); $this->setPageTitle(OW::getLanguage()->text('sponsors', 'become_sponsor_title')); $this->setPageHeadingIconClass('ow_ic_gear_wheel'); }