Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
ManualPaymentPlugin.inc.php
1 <?php
2 
16 import('classes.plugins.PaymethodPlugin');
17 
22  function ManualPaymentPlugin() {
23  parent::PaymethodPlugin();
24  }
25 
29  function getName() {
30  return 'ManualPayment';
31  }
32 
36  function getDisplayName() {
37  return __('plugins.paymethod.manual.displayName');
38  }
39 
43  function getDescription() {
44  return __('plugins.paymethod.manual.description');
45  }
46 
50  function register($category, $path) {
51  if (parent::register($category, $path)) {
52  $this->addLocaleData();
53  return true;
54  }
55  return false;
56  }
57 
62  return array('manualInstructions');
63  }
64 
68  function isConfigured() {
69  $request = $this->getRequest();
70  $press = $request->getPress();
71  if (!$press) return false;
72 
73  // Make sure that all settings form fields have been filled in
74  foreach ($this->getSettingsFormFieldNames() as $settingName) {
75  $setting = $this->getSetting($press->getId(), $settingName);
76  if (empty($setting)) return false;
77  }
78 
79  return true;
80  }
81 
85  function displayPaymentForm($queuedPaymentId, &$queuedPayment, $request) {
86  if (!$this->isConfigured()) return false;
87  $press = $request->getPress();
88  AppLocale::requireComponents(LOCALE_COMPONENT_APP_COMMON);
89  $templateMgr = TemplateManager::getManager($request);
90  $user = $request->getUser();
91 
92  $templateMgr->assign('itemName', $queuedPayment->getName());
93  $templateMgr->assign('itemDescription', $queuedPayment->getDescription());
94  if ($queuedPayment->getAmount() > 0) {
95  $templateMgr->assign('itemAmount', $queuedPayment->getAmount());
96  $templateMgr->assign('itemCurrencyCode', $queuedPayment->getCurrencyCode());
97  }
98  $templateMgr->assign('manualInstructions', $this->getSetting($press->getId(), 'manualInstructions'));
99  $templateMgr->assign('queuedPaymentId', $queuedPaymentId);
100 
101  $templateMgr->display($this->getTemplatePath() . 'paymentForm.tpl');
102  }
103 
109  function handle($args, $request) {
110  $press = $request->getPress();
111  $templateMgr = TemplateManager::getManager($request);
112  $user = $request->getUser();
113  $op = isset($args[0])?$args[0]:null;
114  $queuedPaymentId = isset($args[1])?((int) $args[1]):0;
115 
116  import('classes.payment.omp.OMPPaymentManager');
117  $ompPaymentManager = new OMPPaymentManager($request);
118  $queuedPayment =& $ompPaymentManager->getQueuedPayment($queuedPaymentId);
119  // if the queued payment doesn't exist, redirect away from payments
120  if (!$queuedPayment) return $request->redirect(null, 'index');
121 
122  switch ($op) {
123  case 'notify':
124  import('lib.pkp.classes.mail.MailTemplate');
125  AppLocale::requireComponents(LOCALE_COMPONENT_APP_COMMON);
126  $contactName = $press->getSetting('contactName');
127  $contactEmail = $press->getSetting('contactEmail');
128  $mail = new MailTemplate('MANUAL_PAYMENT_NOTIFICATION');
129  $mail->setReplyTo($contactEmail, $contactName);
130  $mail->addRecipient($contactEmail, $contactName);
131  $mail->assignParams(array(
132  'pressName' => $press->getLocalizedName(),
133  'userFullName' => $user?$user->getFullName():('(' . __('common.none') . ')'),
134  'userName' => $user?$user->getUsername():('(' . __('common.none') . ')'),
135  'itemName' => $queuedPayment->getName(),
136  'itemCost' => $queuedPayment->getAmount(),
137  'itemCurrencyCode' => $queuedPayment->getCurrencyCode()
138  ));
139  $mail->send();
140 
141  $templateMgr->assign(array(
142  'currentUrl' => $request->url(null, null, 'payment', 'plugin', array('notify', $queuedPaymentId)),
143  'pageTitle' => 'plugins.paymethod.manual.paymentNotification',
144  'message' => 'plugins.paymethod.manual.notificationSent',
145  'backLink' => $queuedPayment->getRequestUrl(),
146  'backLinkLabel' => 'common.continue',
147  ));
148  return $templateMgr->display('common/message.tpl');
149  }
150  return parent::handle($args, $request); // Don't know what to do with it
151  }
152 
157  return ($this->getPluginPath() . DIRECTORY_SEPARATOR . 'emailTemplates.xml');
158  }
159 
164  return ($this->getPluginPath() . '/locale/{$installedLocale}/emailTemplates.xml');
165  }
166 }
167 
168 ?>
& getRequest()
Definition: Plugin.inc.php:755
Abstract class for paymethod plugins.
displayPaymentForm($queuedPaymentId, &$queuedPayment, $request)
static requireComponents()
Manual payment plugin class.
Provides payment management functions.
getTemplatePath($inCore=false)
getPluginPath()
Definition: Plugin.inc.php:324
getSetting($contextId, $name)
Definition: Plugin.inc.php:366
addLocaleData($locale=null)
Definition: Plugin.inc.php:347
Subclass of Mail for mailing a template email.