first commit
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file classes/payment/CompletedPayment.php
|
||||
*
|
||||
* Copyright (c) 2014-2021 Simon Fraser University
|
||||
* Copyright (c) 2003-2021 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class CompletedPayment
|
||||
*
|
||||
* @ingroup classes_payment
|
||||
*
|
||||
* @see CompletedPaymentDAO
|
||||
*
|
||||
* @brief Class describing a completed payment.
|
||||
*/
|
||||
|
||||
namespace PKP\payment;
|
||||
|
||||
class CompletedPayment extends Payment
|
||||
{
|
||||
/** @var string Payment completion timestamp */
|
||||
public $_timestamp;
|
||||
|
||||
/** @var string Payment plugin name */
|
||||
public $_paymentPluginName;
|
||||
|
||||
/**
|
||||
* Get the payment completion timestamp.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTimestamp()
|
||||
{
|
||||
return $this->_timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the payment completion timestamp.
|
||||
*
|
||||
* @param string $timestamp Timestamp
|
||||
*/
|
||||
public function setTimestamp($timestamp)
|
||||
{
|
||||
$this->_timestamp = $timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the payment plugin name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPayMethodPluginName()
|
||||
{
|
||||
return $this->_paymentPluginName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the payment plugin name.
|
||||
*
|
||||
* @param string $paymentPluginName
|
||||
*/
|
||||
public function setPayMethodPluginName($paymentPluginName)
|
||||
{
|
||||
$this->_paymentPluginName = $paymentPluginName;
|
||||
}
|
||||
}
|
||||
|
||||
if (!PKP_STRICT_MODE) {
|
||||
class_alias('\PKP\payment\CompletedPayment', '\CompletedPayment');
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @defgroup payment Payment
|
||||
* Payment handling and processing code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file classes/payment/Payment.php
|
||||
*
|
||||
* Copyright (c) 2014-2021 Simon Fraser University
|
||||
* Copyright (c) 2000-2021 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class Payment
|
||||
*
|
||||
* @ingroup payment
|
||||
*
|
||||
* @brief Abstract class for payments.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PKP\payment;
|
||||
|
||||
/** DOES NOT inherit from DataObject for the sake of concise serialization */
|
||||
class Payment
|
||||
{
|
||||
/** @var int payment id */
|
||||
public $paymentId;
|
||||
|
||||
/** @var int Context ID */
|
||||
public $contextId;
|
||||
|
||||
/** @var float amount of payment in $currencyCode units */
|
||||
public $amount;
|
||||
|
||||
/** @var string ISO 4217 alpha currency code */
|
||||
public $currencyCode;
|
||||
|
||||
/** @var int user ID of customer making payment */
|
||||
public $userId;
|
||||
|
||||
/** @var int association ID for payment */
|
||||
public $assocId;
|
||||
|
||||
/** @var int PaymentManager::PAYMENT_TYPE_... */
|
||||
public $type;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param float $amount
|
||||
* @param string $currencyCode
|
||||
* @param int $userId
|
||||
* @param int $assocId optional
|
||||
*/
|
||||
public function __construct($amount = null, $currencyCode = null, $userId = null, $assocId = null)
|
||||
{
|
||||
$this->amount = $amount;
|
||||
$this->currencyCode = $currencyCode;
|
||||
$this->userId = $userId;
|
||||
$this->assocId = $assocId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the row id of the payment.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->paymentId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the id of payment
|
||||
*
|
||||
* @param int $paymentId
|
||||
*
|
||||
* @return int new payment id
|
||||
*/
|
||||
public function setId($paymentId)
|
||||
{
|
||||
return $this->paymentId = $paymentId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the payment amount
|
||||
*
|
||||
* @param float $amount
|
||||
*
|
||||
* @return float new amount
|
||||
*/
|
||||
public function setAmount($amount)
|
||||
{
|
||||
return $this->amount = $amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the payment amount
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getAmount()
|
||||
{
|
||||
return $this->amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the currency code for the transaction (ISO 4217)
|
||||
*
|
||||
* @param string $currencyCode
|
||||
*
|
||||
* @return string new currency code
|
||||
*/
|
||||
public function setCurrencyCode($currencyCode)
|
||||
{
|
||||
return $this->currencyCode = $currencyCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the currency code for the transaction (ISO 4217)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCurrencyCode()
|
||||
{
|
||||
return $this->currencyCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the context ID for the payment.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getContextId()
|
||||
{
|
||||
return $this->contextId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the context ID for the payment.
|
||||
*
|
||||
* @param int $contextId
|
||||
*/
|
||||
public function setContextId($contextId)
|
||||
{
|
||||
$this->contextId = $contextId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the type for this payment (PaymentManager::PAYMENT_TYPE_...)
|
||||
*
|
||||
* @param int $type PaymentManager::PAYMENT_TYPE_...
|
||||
*
|
||||
* @return int New payment type
|
||||
*/
|
||||
public function setType($type)
|
||||
{
|
||||
return $this->type = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type of this payment (PaymentManager::PAYMENT_TYPE_...)
|
||||
*
|
||||
* @return int PaymentManager::PAYMENT_TYPE_...
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the user ID of the customer.
|
||||
*
|
||||
* @param int $userId
|
||||
*
|
||||
* @return int New user ID
|
||||
*/
|
||||
public function setUserId($userId)
|
||||
{
|
||||
return $this->userId = $userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user ID of the customer.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getUserId()
|
||||
{
|
||||
return $this->userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the association ID for the payment.
|
||||
*
|
||||
* @param int $assocId
|
||||
*
|
||||
* @return int New association ID
|
||||
*/
|
||||
public function setAssocId($assocId)
|
||||
{
|
||||
return $this->assocId = $assocId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the association ID for the payment.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getAssocId()
|
||||
{
|
||||
return $this->assocId;
|
||||
}
|
||||
}
|
||||
|
||||
if (!PKP_STRICT_MODE) {
|
||||
class_alias('\PKP\payment\Payment', '\Payment');
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file classes/payment/PaymentManager.php
|
||||
*
|
||||
* Copyright (c) 2014-2021 Simon Fraser University
|
||||
* Copyright (c) 2000-2021 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class PaymentManager
|
||||
*
|
||||
* @ingroup payment
|
||||
*
|
||||
* @see Payment
|
||||
*
|
||||
* @brief Provides payment management functions.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PKP\payment;
|
||||
|
||||
use Exception;
|
||||
use PKP\context\Context;
|
||||
use PKP\db\DAORegistry;
|
||||
|
||||
abstract class PaymentManager
|
||||
{
|
||||
public const PAYMENT_TYPE_PUBLICATION = 7; // FIXME: This is OJS-only but referred to in pkp-lib. Move back to OJS.
|
||||
|
||||
/** @var Context */
|
||||
public $_context;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Context $context
|
||||
*/
|
||||
public function __construct($context)
|
||||
{
|
||||
$this->_context = $context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Queue a payment for receipt.
|
||||
*
|
||||
* @param object $queuedPayment
|
||||
* @param string $expiryDate optional
|
||||
*
|
||||
* @return mixed Queued payment ID for new payment, or false if fails
|
||||
*/
|
||||
public function queuePayment($queuedPayment, $expiryDate = null)
|
||||
{
|
||||
if (!$this->isConfigured()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$queuedPaymentDao = DAORegistry::getDAO('QueuedPaymentDAO'); /** @var QueuedPaymentDAO $queuedPaymentDao */
|
||||
$queuedPaymentId = $queuedPaymentDao->insertObject($queuedPayment, $expiryDate);
|
||||
|
||||
// Perform periodic cleanup
|
||||
if (time() % 100 == 0) {
|
||||
$queuedPaymentDao->deleteExpired();
|
||||
}
|
||||
|
||||
return $queuedPaymentId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract method for fetching the payment plugin
|
||||
*
|
||||
* @return \PKP\plugins\PaymethodPlugin
|
||||
*/
|
||||
abstract public function getPaymentPlugin();
|
||||
|
||||
/**
|
||||
* Check if there is a payment plugin and if is configured
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isConfigured()
|
||||
{
|
||||
$paymentPlugin = $this->getPaymentPlugin();
|
||||
if ($paymentPlugin !== null) {
|
||||
return $paymentPlugin->isConfigured($this->_context);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the payment form for the configured payment plugin and specified payment.
|
||||
*
|
||||
* @param QueuedPayment $queuedPayment
|
||||
*
|
||||
* @return \PKP\form\Form
|
||||
*/
|
||||
public function getPaymentForm($queuedPayment)
|
||||
{
|
||||
$paymentPlugin = $this->getPaymentPlugin();
|
||||
if ($paymentPlugin !== null && $paymentPlugin->isConfigured($this->_context)) {
|
||||
return $paymentPlugin->getPaymentForm($this->_context, $queuedPayment);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a queued payment
|
||||
*
|
||||
* @param int $queuedPaymentId
|
||||
*
|
||||
* @return QueuedPayment
|
||||
*/
|
||||
public function getQueuedPayment($queuedPaymentId)
|
||||
{
|
||||
$queuedPaymentDao = DAORegistry::getDAO('QueuedPaymentDAO'); /** @var QueuedPaymentDAO $queuedPaymentDao */
|
||||
$queuedPayment = $queuedPaymentDao->getById($queuedPaymentId);
|
||||
return $queuedPayment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fulfill a queued payment
|
||||
*
|
||||
* @param \PKP\core\PKPRequest $request
|
||||
* @param QueuedPayment $queuedPayment
|
||||
*
|
||||
* @return bool success/failure
|
||||
*/
|
||||
abstract public function fulfillQueuedPayment($request, $queuedPayment);
|
||||
}
|
||||
|
||||
if (!PKP_STRICT_MODE) {
|
||||
class_alias('\PKP\payment\PaymentManager', '\PaymentManager');
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file classes/payment/QueuedPayment.php
|
||||
*
|
||||
* Copyright (c) 2014-2021 Simon Fraser University
|
||||
* Copyright (c) 2000-2021 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class QueuedPayment
|
||||
*
|
||||
* @ingroup payment
|
||||
*
|
||||
* @see QueuedPaymentDAO
|
||||
*
|
||||
* @brief Queued (unfulfilled) payment data structure
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PKP\payment;
|
||||
|
||||
class QueuedPayment extends Payment
|
||||
{
|
||||
/** @var string URL associated with this payment */
|
||||
public $requestUrl;
|
||||
|
||||
/**
|
||||
* Set the request URL.
|
||||
*
|
||||
* @param string $url
|
||||
*
|
||||
* @return string New URL
|
||||
*/
|
||||
public function setRequestUrl($url)
|
||||
{
|
||||
return $this->requestUrl = $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the request URL.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRequestUrl()
|
||||
{
|
||||
return $this->requestUrl;
|
||||
}
|
||||
}
|
||||
|
||||
// (#6091 Class aliasing applied in PKPApplication for the sake of deserializing legacy content.)
|
||||
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file classes/payment/QueuedPaymentDAO.php
|
||||
*
|
||||
* Copyright (c) 2014-2021 Simon Fraser University
|
||||
* Copyright (c) 2000-2021 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class QueuedPaymentDAO
|
||||
*
|
||||
* @ingroup payment
|
||||
*
|
||||
* @see QueuedPayment
|
||||
*
|
||||
* @brief Operations for retrieving and modifying queued payment objects.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PKP\payment;
|
||||
|
||||
use APP\core\Application;
|
||||
use PKP\core\Core;
|
||||
use PKP\db\DAORegistry;
|
||||
use PKP\notification\NotificationDAO;
|
||||
|
||||
class QueuedPaymentDAO extends \PKP\db\DAO
|
||||
{
|
||||
/**
|
||||
* Retrieve a queued payment by ID.
|
||||
*
|
||||
* @param int $queuedPaymentId
|
||||
*
|
||||
* @return QueuedPayment|null on failure
|
||||
*/
|
||||
public function getById($queuedPaymentId)
|
||||
{
|
||||
$result = $this->retrieve(
|
||||
'SELECT * FROM queued_payments WHERE queued_payment_id = ?',
|
||||
[(int) $queuedPaymentId]
|
||||
);
|
||||
if ($row = $result->current()) {
|
||||
$queuedPayment = unserialize($row->payment_data);
|
||||
$queuedPayment->setId($row->queued_payment_id);
|
||||
return $queuedPayment;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a new queued payment.
|
||||
*
|
||||
* @param QueuedPayment $queuedPayment
|
||||
* @param string $expiryDate optional
|
||||
*/
|
||||
public function insertObject($queuedPayment, $expiryDate = null)
|
||||
{
|
||||
$this->update(
|
||||
sprintf(
|
||||
'INSERT INTO queued_payments
|
||||
(date_created, date_modified, expiry_date, payment_data)
|
||||
VALUES
|
||||
(%s, %s, %s, ?)',
|
||||
$this->datetimeToDB(Core::getCurrentDate()),
|
||||
$this->datetimeToDB(Core::getCurrentDate()),
|
||||
$this->datetimeToDB($expiryDate)
|
||||
),
|
||||
[
|
||||
serialize($queuedPayment)
|
||||
]
|
||||
);
|
||||
|
||||
return $queuedPayment->setId($this->getInsertId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing queued payment.
|
||||
*
|
||||
* @param int $queuedPaymentId
|
||||
* @param QueuedPayment $queuedPayment
|
||||
*/
|
||||
public function updateObject($queuedPaymentId, $queuedPayment)
|
||||
{
|
||||
return $this->update(
|
||||
sprintf(
|
||||
'UPDATE queued_payments
|
||||
SET
|
||||
date_modified = %s,
|
||||
payment_data = ?
|
||||
WHERE queued_payment_id = ?',
|
||||
$this->datetimeToDB(Core::getCurrentDate())
|
||||
),
|
||||
[
|
||||
serialize($queuedPayment),
|
||||
(int) $queuedPaymentId
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a queued payment.
|
||||
*
|
||||
* @param int $queuedPaymentId
|
||||
*/
|
||||
public function deleteById($queuedPaymentId)
|
||||
{
|
||||
$notificationDao = DAORegistry::getDAO('NotificationDAO'); /** @var NotificationDAO $notificationDao */
|
||||
$notificationDao->deleteByAssoc(Application::ASSOC_TYPE_QUEUED_PAYMENT, $queuedPaymentId);
|
||||
$this->update(
|
||||
'DELETE FROM queued_payments WHERE queued_payment_id = ?',
|
||||
[(int) $queuedPaymentId]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete expired queued payments.
|
||||
*/
|
||||
public function deleteExpired()
|
||||
{
|
||||
$this->update('DELETE FROM queued_payments WHERE expiry_date < now()');
|
||||
}
|
||||
}
|
||||
|
||||
if (!PKP_STRICT_MODE) {
|
||||
class_alias('\PKP\payment\QueuedPaymentDAO', '\QueuedPaymentDAO');
|
||||
}
|
||||
Reference in New Issue
Block a user