16 import(
'lib.pkp.classes.form.Form');
30 $this->_paypalPaymentPlugin = $paypalPaymentPlugin;
31 $this->_queuedPayment = $queuedPayment;
32 parent::__construct(
null);
38 function display($request =
null, $template =
null) {
40 $journal = $request->getJournal();
42 $gateway = Omnipay\Omnipay::create(
'PayPal_Rest');
43 $gateway->initialize(array(
44 'clientId' => $this->_paypalPaymentPlugin->getSetting($journal->getId(),
'clientId'),
45 'secret' => $this->_paypalPaymentPlugin->getSetting($journal->getId(),
'secret'),
46 'testMode' => $this->_paypalPaymentPlugin->getSetting($journal->getId(),
'testMode'),
48 $transaction = $gateway->purchase(array(
49 'amount' => number_format($this->_queuedPayment->getAmount(), 2),
50 'currency' => $this->_queuedPayment->getCurrencyCode(),
51 'description' => $paymentManager->getPaymentName($this->_queuedPayment),
52 'returnUrl' => $request->url(
null,
'payment',
'plugin', array($this->_paypalPaymentPlugin->getName(),
'return'), array(
'queuedPaymentId' => $this->_queuedPayment->getId())),
53 'cancelUrl' => $request->url(
null,
'index'),
55 $response = $transaction->send();
56 if ($response->isRedirect()) $request->redirectUrl($response->getRedirectUrl());
57 if (!$response->isSuccessful())
throw new \Exception($response->getMessage());
58 throw new \Exception(
'PayPal response was not redirect!');
59 }
catch (\Exception $e) {
60 error_log(
'PayPal transaction exception: ' . $e->getMessage());
62 $templateMgr->assign(
'message',
'plugins.paymethod.paypal.error');
63 $templateMgr->display(
'frontend/pages/message.tpl');