Open Journal Systems  3.3.0
PaypalPaymentForm.inc.php
1 <?php
2 
16 import('lib.pkp.classes.form.Form');
17 
18 class PaypalPaymentForm extends Form {
21 
24 
29  function __construct($paypalPaymentPlugin, $queuedPayment) {
30  $this->_paypalPaymentPlugin = $paypalPaymentPlugin;
31  $this->_queuedPayment = $queuedPayment;
32  parent::__construct(null);
33  }
34 
38  function display($request = null, $template = null) {
39  try {
40  $journal = $request->getJournal();
41  $paymentManager = Application::getPaymentManager($journal);
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'),
47  ));
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'),
54  ));
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());
61  $templateMgr = TemplateManager::getManager($request);
62  $templateMgr->assign('message', 'plugins.paymethod.paypal.error');
63  $templateMgr->display('frontend/pages/message.tpl');
64  }
65  }
66 }
PaypalPaymentForm\__construct
__construct($paypalPaymentPlugin, $queuedPayment)
Definition: PaypalPaymentForm.inc.php:35
Application\getPaymentManager
static getPaymentManager($context)
Definition: Application.inc.php:226
PaypalPaymentForm
Definition: PaypalPaymentForm.inc.php:18
PaypalPaymentForm\$_queuedPayment
$_queuedPayment
Definition: PaypalPaymentForm.inc.php:29
PaypalPaymentForm\$_paypalPaymentPlugin
$_paypalPaymentPlugin
Definition: PaypalPaymentForm.inc.php:23
PKPTemplateManager\getManager
static & getManager($request=null)
Definition: PKPTemplateManager.inc.php:1239
Form
Class defining basic operations for handling HTML forms.
Definition: Form.inc.php:47
PaypalPaymentForm\display
display($request=null, $template=null)
Definition: PaypalPaymentForm.inc.php:44