summit_repository = $summit_repository; $this->resource_server_context = $resource_server_context; $this->location_service = $location_service; $this->order_service = $order_service; $this->default_payment_gateway_strategy = $default_payment_gateway_strategy;; } /** * @param string $application_type * @return IProcessPaymentService|null */ private function getProcessPaymentService(string $application_type):?IProcessPaymentService { if($application_type == IPaymentConstants::ApplicationTypeRegistration) return $this->order_service; if($application_type == IPaymentConstants::ApplicationTypeBookableRooms) return $this->location_service; return null; } /** * @param $application_type * @param LaravelRequest $request * @return \Illuminate\Http\JsonResponse|mixed */ public function genericConfirm($application_type, LaravelRequest $request){ try { Log::debug(sprintf("PaymentGatewayWebHookController::genericConfirm application_type %s ", $application_type)); // get api $paymentGatewayApi = $this->default_payment_gateway_strategy->build($application_type); if(is_null($paymentGatewayApi)) { Log::debug(sprintf("PaymentGatewayWebHookController::genericConfirm application_type %s profile payment not found.", $application_type)); return $this->error412([sprintf("application_type %s profile payment not found.", $application_type)]); } $service = $this->getProcessPaymentService($application_type); if(is_null($service)) { Log::debug(sprintf("PaymentGatewayWebHookController::genericConfirm application_type %s service not found.", $application_type)); return $this->error412([sprintf("application_type %s service not found.", $application_type)]); } $service->processPayment($paymentGatewayApi->buildPaymentGatewayApi()->processCallback($request)); return $this->ok(); } catch(EntityNotFoundException $ex){ Log::warning($ex); return $this->response2XX(208, ['error' => 'already reported']); } catch(ValidationException $ex){ Log::warning($ex); return $this->error412(["error" => 'payload error']); } catch (Exception $ex){ Log::error($ex); return $this->error400(["error" => 'payload error']); } return $this->error400(["error" => 'invalid event type']); } /** * @param $summit_id * @param $application_type * @param LaravelRequest $request * @return \Illuminate\Http\JsonResponse|mixed */ public function confirm($summit_id, $application_type, LaravelRequest $request){ try { Log::debug(sprintf("PaymentGatewayWebHookController::confirm summit %s application_type %s ", $summit_id, $application_type)); // get current summit $summit = SummitFinderStrategyFactory::build ( $this->summit_repository, $this->resource_server_context )->find($summit_id); if (is_null($summit) || !$summit instanceof Summit){ Log::debug(sprintf("PaymentGatewayWebHookController::confirm summit %s not found.", $summit_id)); return $this->error412([sprintf("application_type %s summit not found.", $application_type)]); } // get api $paymentGatewayApi = $summit->getPaymentGateWayPerApp($application_type, $this->default_payment_gateway_strategy); if(is_null($paymentGatewayApi)) { Log::debug(sprintf("PaymentGatewayWebHookController::confirm summit %s profile payment not found.", $summit_id)); return $this->error412([sprintf("application_type %s summit not found.", $application_type)]); } $service = $this->getProcessPaymentService($application_type); if(is_null($service)) { Log::debug(sprintf("PaymentGatewayWebHookController::confirm summit %s service not found.", $summit_id)); return $this->error412([sprintf("application_type %s service not found.", $application_type)]); } $service->processPayment($paymentGatewayApi->processCallback($request), $summit); return $this->ok(); } catch(EntityNotFoundException $ex){ Log::warning($ex); return $this->response2XX(208, ['error' => 'already reported']); } catch(ValidationException $ex){ Log::warning($ex); return $this->error412(["error" => 'payload error']); } catch (Exception $ex){ Log::error($ex); return $this->error400(["error" => 'payload error']); } return $this->error400(["error" => 'invalid event type']); } }