/**
  * Fetch the HTML contents of the form.
  * @param $request PKPRequest
  * return string
  */
 function fetch($request)
 {
     $monograph = $this->getMonograph();
     $press = $request->getPress();
     $templateMgr = TemplateManager::getManager($request);
     $templateMgr->assign('submissionId', $monograph->getId());
     $templateMgr->assign('representationId', (int) $this->getPublicationFormatId());
     $templateMgr->assign('isPhysicalFormat', (bool) $this->getPhysicalFormat());
     // included to load format-specific template
     $templateMgr->assign('stageId', $this->getStageId());
     $templateMgr->assign('formParams', $this->getFormParams());
     $templateMgr->assign('submissionApproved', $monograph->getDatePublished());
     $onixCodelistItemDao = DAORegistry::getDAO('ONIXCodelistItemDAO');
     // Check if e-commerce is available
     import('classes.payment.omp.OMPPaymentManager');
     $ompPaymentManager = new OMPPaymentManager($request);
     if ($ompPaymentManager->isConfigured()) {
         $templateMgr->assign('paymentConfigured', true);
         $templateMgr->assign('currency', $press->getSetting('currency'));
     }
     // get the lists associated with the select elements on these publication format forms.
     $codes = array('productCompositionCodes' => 'List2', 'measurementUnitCodes' => 'List50', 'weightUnitCodes' => 'List95', 'measurementTypeCodes' => 'List48', 'productFormDetailCodes' => 'List175', 'productAvailabilityCodes' => 'List65', 'technicalProtectionCodes' => 'List144', 'returnableIndicatorCodes' => 'List66', 'countriesIncludedCodes' => 'List91');
     foreach ($codes as $templateVarName => $list) {
         $templateMgr->assign_by_ref($templateVarName, $onixCodelistItemDao->getCodes($list));
     }
     // consider public identifiers
     $pubIdPlugins = PluginRegistry::loadCategory('pubIds', true);
     $templateMgr->assign('pubIdPlugins', $pubIdPlugins);
     // Notification options.
     $notificationRequestOptions = array(NOTIFICATION_LEVEL_NORMAL => array(NOTIFICATION_TYPE_CONFIGURE_PAYMENT_METHOD => array(ASSOC_TYPE_PRESS, $press->getId()), NOTIFICATION_TYPE_FORMAT_NEEDS_APPROVED_SUBMISSION => array(ASSOC_TYPE_MONOGRAPH, $monograph->getId())), NOTIFICATION_LEVEL_TRIVIAL => array());
     $templateMgr->assign('notificationRequestOptions', $notificationRequestOptions);
     return parent::fetch($request);
 }
 /**
  * Handle incoming requests/notifications
  * @param $args array
  * @param $request PKPRequest
  */
 function handle($args, $request)
 {
     $press = $request->getPress();
     $templateMgr = TemplateManager::getManager($request);
     $user = $request->getUser();
     $op = isset($args[0]) ? $args[0] : null;
     $queuedPaymentId = isset($args[1]) ? (int) $args[1] : 0;
     import('classes.payment.omp.OMPPaymentManager');
     $ompPaymentManager = new OMPPaymentManager($request);
     $queuedPayment =& $ompPaymentManager->getQueuedPayment($queuedPaymentId);
     // if the queued payment doesn't exist, redirect away from payments
     if (!$queuedPayment) {
         return $request->redirect(null, 'index');
     }
     switch ($op) {
         case 'notify':
             import('lib.pkp.classes.mail.MailTemplate');
             AppLocale::requireComponents(LOCALE_COMPONENT_APP_COMMON);
             $contactName = $press->getSetting('contactName');
             $contactEmail = $press->getSetting('contactEmail');
             $mail = new MailTemplate('MANUAL_PAYMENT_NOTIFICATION');
             $mail->setReplyTo($contactEmail, $contactName);
             $mail->addRecipient($contactEmail, $contactName);
             $mail->assignParams(array('pressName' => $press->getLocalizedName(), 'userFullName' => $user ? $user->getFullName() : '(' . __('common.none') . ')', 'userName' => $user ? $user->getUsername() : '(' . __('common.none') . ')', 'itemName' => $queuedPayment->getName(), 'itemCost' => $queuedPayment->getAmount(), 'itemCurrencyCode' => $queuedPayment->getCurrencyCode()));
             $mail->send();
             $templateMgr->assign(array('currentUrl' => $request->url(null, null, 'payment', 'plugin', array('notify', $queuedPaymentId)), 'pageTitle' => 'plugins.paymethod.manual.paymentNotification', 'message' => 'plugins.paymethod.manual.notificationSent', 'backLink' => $queuedPayment->getRequestUrl(), 'backLinkLabel' => 'common.continue'));
             return $templateMgr->display('frontend/pages/message.tpl');
     }
     return parent::handle($args, $request);
     // Don't know what to do with it
 }
 /**
  * Handle incoming requests/notifications
  * @param $args array
  * @param $request PKPRequest
  */
 function handle($args, $request)
 {
     $templateMgr = TemplateManager::getManager($request);
     $press = $request->getPress();
     if (!$press) {
         return parent::handle($args, $request);
     }
     // Just in case we need to contact someone
     import('lib.pkp.classes.mail.MailTemplate');
     // Prefer technical support contact
     $contactName = $press->getSetting('supportName');
     $contactEmail = $press->getSetting('supportEmail');
     if (!$contactEmail) {
         // Fall back on primary contact
         $contactName = $press->getSetting('contactName');
         $contactEmail = $press->getSetting('contactEmail');
     }
     $mail = new MailTemplate('PAYPAL_INVESTIGATE_PAYMENT');
     $mail->setReplyTo($contactEmail, $contactName);
     $mail->addRecipient($contactEmail, $contactName);
     $paymentStatus = $request->getUserVar('payment_status');
     switch (array_shift($args)) {
         case 'ipn':
             // Build a confirmation transaction.
             $req = 'cmd=_notify-validate';
             if (get_magic_quotes_gpc()) {
                 foreach ($_POST as $key => $value) {
                     $req .= '&' . urlencode(stripslashes($key)) . '=' . urlencode(stripslashes($value));
                 }
             } else {
                 foreach ($_POST as $key => $value) {
                     $req .= '&' . urlencode($key) . '=' . urlencode($value);
                 }
             }
             // Create POST response
             $ch = curl_init();
             curl_setopt($ch, CURLOPT_URL, $this->getSetting($press->getId(), 'paypalurl'));
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
             curl_setopt($ch, CURLOPT_POST, 1);
             curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded', 'Content-Length: ' . strlen($req)));
             curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
             $ret = curl_exec($ch);
             curl_close($ch);
             // Check the confirmation response and handle as necessary.
             if (strcmp($ret, 'VERIFIED') == 0) {
                 switch ($paymentStatus) {
                     case 'Completed':
                         $payPalDao = DAORegistry::getDAO('PayPalDAO');
                         $transactionId = $request->getUserVar('txn_id');
                         if ($payPalDao->transactionExists($transactionId)) {
                             // A duplicate transaction was received; notify someone.
                             $mail->assignParams(array('pressName' => $press->getLocalizedName(), 'postInfo' => print_r($_POST, true), 'additionalInfo' => "Duplicate transaction ID: {$transactionId}", 'serverVars' => print_r($_SERVER, true)));
                             $mail->send();
                             exit;
                         } else {
                             // New transaction succeeded. Record it.
                             $payPalDao->insertTransaction($transactionId, $request->getUserVar('txn_type'), $request->getUserVar('payer_email'), $request->getUserVar('receiver_email'), $request->getUserVar('item_number'), $request->getUserVar('payment_date'), $request->getUserVar('payer_id'), $request->getUserVar('receiver_id'));
                             $queuedPaymentId = $request->getUserVar('custom');
                             import('classes.payment.omp.OMPPaymentManager');
                             $ompPaymentManager = new OMPPaymentManager($request);
                             // Verify the cost and user details as per PayPal spec.
                             $queuedPayment =& $ompPaymentManager->getQueuedPayment($queuedPaymentId);
                             if (!$queuedPayment) {
                                 // The queued payment entry is missing. Complain.
                                 $mail->assignParams(array('pressName' => $press->getLocalizedName(), 'postInfo' => print_r($_POST, true), 'additionalInfo' => "Missing queued payment ID: {$queuedPaymentId}", 'serverVars' => print_r($_SERVER, true)));
                                 $mail->send();
                                 exit;
                             }
                             //NB: if/when paypal subscriptions are enabled, these checks will have to be adjusted
                             // because subscription prices may change over time
                             if (($queuedAmount = $queuedPayment->getAmount()) != ($grantedAmount = $request->getUserVar('mc_gross')) && $queuedAmount > 0 || ($queuedCurrency = $queuedPayment->getCurrencyCode()) != ($grantedCurrency = $request->getUserVar('mc_currency')) || ($grantedEmail = $request->getUserVar('receiver_email')) != ($queuedEmail = $this->getSetting($press->getId(), 'selleraccount'))) {
                                 // The integrity checks for the transaction failed. Complain.
                                 $mail->assignParams(array('pressName' => $press->getLocalizedName(), 'postInfo' => print_r($_POST, true), 'additionalInfo' => "Granted amount: {$grantedAmount}\n" . "Queued amount: {$queuedAmount}\n" . "Granted currency: {$grantedCurrency}\n" . "Queued currency: {$queuedCurrency}\n" . "Granted to PayPal account: {$grantedEmail}\n" . "Configured PayPal account: {$queuedEmail}", 'serverVars' => print_r($_SERVER, true)));
                                 $mail->send();
                                 exit;
                             }
                             // Update queued amount if amount set by user (e.g. donation)
                             if ($queuedAmount == 0 && $grantedAmount > 0) {
                                 $queuedPaymentDao = DAORegistry::getDAO('QueuedPaymentDAO');
                                 $queuedPayment->setAmount($grantedAmount);
                                 $queuedPayment->setCurrencyCode($grantedCurrency);
                                 $queuedPaymentDao->updateQueuedPayment($queuedPaymentId, $queuedPayment);
                             }
                             // Fulfill the queued payment.
                             if ($ompPaymentManager->fulfillQueuedPayment($request, $queuedPayment, $this->getName())) {
                                 exit;
                             }
                             // If we're still here, it means the payment couldn't be fulfilled.
                             $mail->assignParams(array('pressName' => $press->getLocalizedName(), 'postInfo' => print_r($_POST, true), 'additionalInfo' => "Queued payment ID {$queuedPaymentId} could not be fulfilled.", 'serverVars' => print_r($_SERVER, true)));
                             $mail->send();
                         }
                         exit;
                     case 'Pending':
                         // Ignore.
                         exit;
                     default:
                         // An unhandled payment status was received; notify someone.
                         $mail->assignParams(array('pressName' => $press->getLocalizedName(), 'postInfo' => print_r($_POST, true), 'additionalInfo' => "Payment status: {$paymentStatus}", 'serverVars' => print_r($_SERVER, true)));
                         $mail->send();
                         exit;
                 }
             } else {
                 // An unknown confirmation response was received; notify someone.
                 $mail->assignParams(array('pressName' => $press->getLocalizedName(), 'postInfo' => print_r($_POST, true), 'additionalInfo' => "Confirmation return: {$ret}", 'serverVars' => print_r($_SERVER, true)));
                 $mail->send();
                 exit;
             }
             break;
         case 'cancel':
             $templateMgr->assign(array('currentUrl' => $request->url(null, 'index'), 'pageTitle' => 'plugins.paymethod.paypal.purchase.cancelled.title', 'message' => 'plugins.paymethod.paypal.purchase.cancelled', 'backLink' => $request->getUserVar('ompReturnUrl'), 'backLinkLabel' => 'common.continue'));
             $templateMgr->display('frontend/pages/message.tpl');
             exit;
             break;
     }
     parent::handle($args);
     // Don't know what to do with it
 }
Beispiel #4
0
 /**
  * Download a published monograph publication format file.
  * @param $args array
  * @param $request PKPRequest
  * @param $view boolean True iff inline viewer should be used, if available
  */
 function download($args, $request, $view = false)
 {
     $dispatcher = $request->getDispatcher();
     $publishedMonograph = $this->getAuthorizedContextObject(ASSOC_TYPE_PUBLISHED_MONOGRAPH);
     $this->setupTemplate($request, $publishedMonograph);
     $press = $request->getPress();
     $monographId = array_shift($args);
     // Validated thru auth
     $representationId = array_shift($args);
     $bestFileId = array_shift($args);
     $publicationFormatDao = DAORegistry::getDAO('PublicationFormatDAO');
     $publicationFormat = $publicationFormatDao->getByBestId($representationId, $publishedMonograph->getId());
     if (!$publicationFormat || !$publicationFormat->getIsApproved() || !$publicationFormat->getIsAvailable() || ($remoteURL = $publicationFormat->getRemoteURL())) {
         fatalError('Invalid publication format specified.');
     }
     $submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO');
     import('lib.pkp.classes.submission.SubmissionFile');
     // File constants
     $submissionFile = $submissionFileDao->getByBestId($bestFileId, $publishedMonograph->getId());
     if (!$submissionFile) {
         $dispatcher->handle404();
     }
     $fileIdAndRevision = $submissionFile->getFileIdAndRevision();
     list($fileId, $revision) = array_map(create_function('$a', 'return (int) $a;'), preg_split('/-/', $fileIdAndRevision));
     import('lib.pkp.classes.file.SubmissionFileManager');
     $monographFileManager = new SubmissionFileManager($publishedMonograph->getContextId(), $publishedMonograph->getId());
     switch ($submissionFile->getAssocType()) {
         case ASSOC_TYPE_PUBLICATION_FORMAT:
             // Publication format file
             if ($submissionFile->getAssocId() != $publicationFormat->getId() || $submissionFile->getDirectSalesPrice() === null) {
                 fatalError('Invalid monograph file specified!');
             }
             break;
         case ASSOC_TYPE_SUBMISSION_FILE:
             // Dependent file
             $genreDao = DAORegistry::getDAO('GenreDAO');
             $genre = $genreDao->getById($submissionFile->getGenreId());
             if (!$genre->getDependent()) {
                 fatalError('Invalid monograph file specified!');
             }
             return $monographFileManager->downloadFile($fileId, $revision);
             break;
         default:
             fatalError('Invalid monograph file specified!');
     }
     $ompCompletedPaymentDao = DAORegistry::getDAO('OMPCompletedPaymentDAO');
     $user = $request->getUser();
     if ($submissionFile->getDirectSalesPrice() === '0' || $user && $ompCompletedPaymentDao->hasPaidPurchaseFile($user->getId(), $fileIdAndRevision)) {
         // Paid purchase or open access.
         if (!$user && $press->getSetting('restrictMonographAccess')) {
             // User needs to register first.
             Validation::redirectLogin();
         }
         // If inline viewing is requested, permit plugins to
         // handle the document.
         PluginRegistry::loadCategory('viewableFiles', true);
         if ($view) {
             if (HookRegistry::call('CatalogBookHandler::view', array(&$this, &$publishedMonograph, &$publicationFormat, &$submissionFile))) {
                 // If the plugin handled the hook, prevent further default activity.
                 exit;
             }
         }
         // Inline viewer not available, or viewing not wanted.
         // Download or show the file.
         $inline = $request->getUserVar('inline') ? true : false;
         if (!HookRegistry::call('CatalogBookHandler::download', array(&$this, &$publishedMonograph, &$publicationFormat, &$submissionFile, &$inline))) {
             return $monographFileManager->downloadFile($fileId, $revision, $inline);
         }
     }
     // Fall-through: user needs to pay for purchase.
     // Users that are not logged in need to register/login first.
     if (!$user) {
         return $request->redirect(null, 'login', null, null, array('source' => $request->url(null, null, null, array($monographId, $representationId, $bestFileId))));
     }
     // They're logged in but need to pay to view.
     import('classes.payment.omp.OMPPaymentManager');
     $ompPaymentManager = new OMPPaymentManager($request);
     if (!$ompPaymentManager->isConfigured()) {
         $request->redirect(null, 'catalog');
     }
     $queuedPayment = $ompPaymentManager->createQueuedPayment($press->getId(), PAYMENT_TYPE_PURCHASE_FILE, $user->getId(), $fileIdAndRevision, $submissionFile->getDirectSalesPrice(), $press->getSetting('currency'));
     $ompPaymentManager->displayPaymentForm($ompPaymentManager->queuePayment($queuedPayment), $queuedPayment);
 }