_endpoints = array_merge_recursive($this->_endpoints, [ 'PUT' => [ [ 'pattern' => $rootPattern, 'handler' => [$this, 'edit'], 'roles' => [ Role::ROLE_ID_SITE_ADMIN, Role::ROLE_ID_MANAGER, ], ], ], ]); parent::__construct(); } /** * @copydoc PKPHandler::authorize */ public function authorize($request, &$args, $roleAssignments) { $this->addPolicy(new UserRolesRequiredPolicy($request), true); $rolePolicy = new PolicySet(PolicySet::COMBINING_PERMIT_OVERRIDES); foreach ($roleAssignments as $role => $operations) { $rolePolicy->addPolicy(new RoleBasedHandlerOperationPolicy($request, $role, $operations)); } $this->addPolicy($rolePolicy); return parent::authorize($request, $args, $roleAssignments); } /** * Receive requests to edit the payments form * * @param \Slim\Http\Request $slimRequest Slim request object * @param \PKP\core\APIResponse $response object * * @return \PKP\core\APIResponse */ public function edit($slimRequest, $response, $args) { $request = $this->getRequest(); $context = $request->getContext(); $params = $slimRequest->getParsedBody(); $contextService = Services::get('context'); // Process query params to format incoming data as needed foreach ($slimRequest->getParsedBody() as $param => $val) { switch ($param) { case 'paymentsEnabled': $params[$param] = $val === 'true'; break; case 'currency': $params[$param] = (string) $val; break; } } if (isset($params['currency'])) { $errors = $contextService->validate( EntityWriteInterface::VALIDATE_ACTION_EDIT, ['currency' => $params['currency']], $context->getSupportedFormLocales(), $context->getPrimaryLocale() ); if (!empty($errors)) { return $response->withStatus(400)->withJson($errors); } } PluginRegistry::loadCategory('paymethod', true); Hook::call( 'API::payments::settings::edit', [ $slimRequest, $request, $params, $updatedSettings = new Collection(), $errors = new Collection() ] ); if ($errors->isNotEmpty()) { return $response->withStatus(400)->withJson($errors->toArray()); } $context = $contextService->get($context->getId()); $contextService->edit($context, $params, $request); return $response->withJson(array_merge($params, $updatedSettings->toArray())); } }