Determine whether gift payments are enabled.
public acceptGiftPayments ( ) : boolean | ||
return | boolean | true iff this fee is enabled. |
/** * User redeems a gift * @param $args array * @param $request PKPRequest */ function redeemGift($args, $request) { $this->validate(); if (empty($args)) { $request->redirect(null, 'dashboard'); } $journal = $request->getJournal(); if (!$journal) { $request->redirect(null, 'dashboard'); } // Ensure gift payments are enabled import('classes.payment.ojs.OJSPaymentManager'); $paymentManager = new OJSPaymentManager($request); $acceptGiftPayments = $paymentManager->acceptGiftPayments(); if (!$acceptGiftPayments) { $request->redirect(null, 'dashboard'); } $journalId = $journal->getId(); $user = $request->getUser(); $userId = $user->getId(); $giftId = isset($args[0]) ? (int) $args[0] : 0; // Try to redeem the gift $giftDao = DAORegistry::getDAO('GiftDAO'); $status = $giftDao->redeemGift(ASSOC_TYPE_JOURNAL, $journalId, $userId, $giftId); // Report redeem status to user import('classes.notification.NotificationManager'); $notificationManager = new NotificationManager(); switch ($status) { case GIFT_REDEEM_STATUS_SUCCESS: $notificationType = NOTIFICATION_TYPE_GIFT_REDEEM_STATUS_SUCCESS; break; case GIFT_REDEEM_STATUS_ERROR_NO_GIFT_TO_REDEEM: $notificationType = NOTIFICATION_TYPE_GIFT_REDEEM_STATUS_ERROR_NO_GIFT_TO_REDEEM; break; case GIFT_REDEEM_STATUS_ERROR_GIFT_ALREADY_REDEEMED: $notificationType = NOTIFICATION_TYPE_GIFT_REDEEM_STATUS_ERROR_GIFT_ALREADY_REDEEMED; break; case GIFT_REDEEM_STATUS_ERROR_GIFT_INVALID: $notificationType = NOTIFICATION_TYPE_GIFT_REDEEM_STATUS_ERROR_GIFT_INVALID; break; case GIFT_REDEEM_STATUS_ERROR_SUBSCRIPTION_TYPE_INVALID: $notificationType = NOTIFICATION_TYPE_GIFT_REDEEM_STATUS_ERROR_SUBSCRIPTION_TYPE_INVALID; break; case GIFT_REDEEM_STATUS_ERROR_SUBSCRIPTION_NON_EXPIRING: $notificationType = NOTIFICATION_TYPE_GIFT_REDEEM_STATUS_ERROR_SUBSCRIPTION_NON_EXPIRING; break; default: $notificationType = NOTIFICATION_TYPE_NO_GIFT_TO_REDEEM; } $user = $request->getUser(); $notificationManager->createTrivialNotification($user->getId(), $notificationType); $request->redirect(null, 'user', 'gifts'); }