18 import(
'lib.pkp.classes.payment.CompletedPayment');
27 function getById($completedPaymentId, $contextId =
null) {
28 $params = array((
int) $completedPaymentId);
29 if ($contextId) $params[] = (int) $contextId;
32 'SELECT * FROM completed_payments WHERE completed_payment_id = ?' . ($contextId?
' AND context_id = ?':
''),
37 if ($result->RecordCount() != 0) {
38 $returner = $this->
_fromRow($result->GetRowAssoc(
false));
51 sprintf(
'INSERT INTO completed_payments
52 (timestamp, payment_type, context_id, user_id, assoc_id, amount, currency_code_alpha, payment_method_plugin_name)
54 (%s, ?, ?, ?, ?, ?, ?, ?)',
57 (
int) $completedPayment->getType(),
58 (
int) $completedPayment->getContextId(),
59 (
int) $completedPayment->getUserId(),
60 (
int) $completedPayment->getAssocId(),
61 $completedPayment->getAmount(),
62 $completedPayment->getCurrencyCode(),
63 $completedPayment->getPayMethodPluginName()
79 sprintf(
'UPDATE completed_payments
87 currency_code_alpha = ?,
88 payment_method_plugin_name = ?
89 WHERE completed_payment_id = ?',
92 (
int) $completedPayment->getType(),
93 (
int) $completedPayment->getContextId(),
94 (
int) $completedPayment->getUserId(),
95 (
int) $completedPayment->getAssocId(),
96 $completedPayment->getAmount(),
97 $completedPayment->getCurrencyCode(),
98 $completedPayment->getPayMethodPluginName(),
99 (
int) $completedPayment->getId()
111 return $this->
_getInsertId(
'completed_payments',
'completed_payment_id');
121 function getByAssoc($userId =
null, $paymentType =
null, $assocId =
null) {
123 if ($userId) $params[] = (int) $userId;
124 if ($paymentType) $params[] = (int) $paymentType;
125 if ($assocId) $params[] = (int) $assocId;
127 'SELECT * FROM completed_payments WHERE 1=1' .
128 ($userId?
' AND user_id = ?':
'') .
129 ($paymentType?
' AND payment_type = ?':
'') .
130 ($assocId?
' AND assoc_id = ?':
''),
135 if (isset($result->fields[0]) && $result->fields[0] != 0) {
136 $returner = $this->
_fromRow($result->fields);
149 return $this->
getByAssoc($userId, PAYMENT_TYPE_PURCHASE_ARTICLE, $articleId)?
true:
false;
158 return $this->
getByAssoc($userId, PAYMENT_TYPE_PURCHASE_ISSUE, $issueId)?
true:
false;
167 return $this->
getByAssoc($userId, PAYMENT_TYPE_PUBLICATION, $articleId)?
true:
false;
177 'SELECT * FROM completed_payments WHERE context_id = ? ORDER BY timestamp DESC',
183 while (!$result->EOF) {
184 $payment = $this->
_fromRow($result->fields);
185 $returner[$payment->getId()] = $payment;
199 'SELECT * FROM completed_payments WHERE user_id = ? ORDER BY timestamp DESC',
223 $payment->setId($row[
'completed_payment_id']);
224 $payment->setType($row[
'payment_type']);
225 $payment->setContextId($row[
'context_id']);
226 $payment->setAmount($row[
'amount']);
227 $payment->setCurrencyCode($row[
'currency_code_alpha']);
228 $payment->setUserId($row[
'user_id']);
229 $payment->setAssocId($row[
'assoc_id']);
230 $payment->setPayMethodPluginName($row[
'payment_method_plugin_name']);