'Created Segment Constant', 'message' => 'You have successfully created a new Segment Constant' ]; } /** @var CanCreateSegmentConstant */ private $canCreateSegmentConstant; /** @var CreatesSegmentConstantTax */ private $createsSegmentConstantTax; /** @var CreatesSegmentConstantBillingFee */ private $createsSegmentConstantBillingFee; /** @var CreatesSegmentConstantServiceCharge */ private $createsSegmentConstantServiceCharge; /** @var CreatesSegmentConstantBookingAmountMax */ private $createsSegmentConstantBookingAmountMax; /** @var CreatesSegmentConstantPaymentAttemptExpiryTime */ private $createsSegmentConstantPaymentAttemptExpiryTime; /** @var FetchesSegmentConstant */ private $fetchesSegmentConstant; /** @var FetchesSegment */ private $fetchesSegment; /** * CreateSegmentConstantLogic constructor. * @param CanCreateSegmentConstant $canCreateSegmentConstant * @param CreatesSegmentConstantTax $createsSegmentConstantTax * @param CreatesSegmentConstantBillingFee $createsSegmentConstantBillingFee * @param CreatesSegmentConstantServiceCharge $createsSegmentConstantServiceCharge * @param CreatesSegmentConstantBookingAmountMax $createsSegmentConstantBookingAmountMax * @param CreatesSegmentConstantPaymentAttemptExpiryTime $createsSegmentConstantPaymentAttemptExpiryTime * @param FetchesSegmentConstant $fetchesSegmentConstant * @param FetchesSegment $fetchesSegment */ public function __construct( CanCreateSegmentConstant $canCreateSegmentConstant, CreatesSegmentConstantTax $createsSegmentConstantTax, CreatesSegmentConstantBillingFee $createsSegmentConstantBillingFee, CreatesSegmentConstantServiceCharge $createsSegmentConstantServiceCharge, CreatesSegmentConstantBookingAmountMax $createsSegmentConstantBookingAmountMax, CreatesSegmentConstantPaymentAttemptExpiryTime $createsSegmentConstantPaymentAttemptExpiryTime, FetchesSegmentConstant $fetchesSegmentConstant, FetchesSegment $fetchesSegment ) { $this->canCreateSegmentConstant = $canCreateSegmentConstant; $this->createsSegmentConstantTax = $createsSegmentConstantTax; $this->createsSegmentConstantBillingFee = $createsSegmentConstantBillingFee; $this->createsSegmentConstantServiceCharge = $createsSegmentConstantServiceCharge; $this->createsSegmentConstantBookingAmountMax = $createsSegmentConstantBookingAmountMax; $this->createsSegmentConstantPaymentAttemptExpiryTime = $createsSegmentConstantPaymentAttemptExpiryTime; $this->fetchesSegmentConstant = $fetchesSegmentConstant; $this->fetchesSegment = $fetchesSegment; } /** * @param Request $request * @return JsonResponse * @throws ErrorException */ public function logic(Request $request) : JsonResponse { try { DB::beginTransaction(); $segment_query = $this->fetchesSegment->execute([ 'id' => $request->input('segment_id'), ]); $segment_constant_query = $this->fetchesSegmentConstant->execute([ 'id' => $request->input('standard_segment_constant_id'), ]); if ($segment_constant_query->reference == 'TAX') { $segment_constant_object = new SegmentConstantTaxObject( $request->input('segment_id'), $segment_constant_query->name, $segment_constant_query->reference, $segment_constant_query->detail->type, $request->input('value') ); $this->canCreateSegmentConstant->passes($segment_constant_object); $segment_constant_query = $this->createsSegmentConstantTax->execute($segment_query, $segment_constant_object); } elseif ($segment_constant_query->reference == 'BILLING_FEE') { $segment_constant_object = new SegmentConstantBillingFeeObject( $request->input('segment_id'), $segment_constant_query->name, $segment_constant_query->reference, $segment_constant_query->detail->type, $request->input('value') ); $this->canCreateSegmentConstant->passes($segment_constant_object); $segment_constant_query = $this->createsSegmentConstantBillingFee->execute($segment_query, $segment_constant_object); } elseif ($segment_constant_query->reference == 'SERVICE_CHARGE') { $segment_constant_object = new SegmentConstantServiceChargeObject( $request->input('segment_id'), $segment_constant_query->name, $segment_constant_query->reference, $segment_constant_query->detail->type, $request->input('value') ); $this->canCreateSegmentConstant->passes($segment_constant_object); $segment_constant_query = $this->createsSegmentConstantServiceCharge->execute($segment_query, $segment_constant_object); } elseif ($segment_constant_query->reference == 'BOOKING_AMOUNT_MAX') { $segment_constant_object = new SegmentConstantBookingAmountMaxObject( $request->input('segment_id'), $segment_constant_query->name, $segment_constant_query->reference, $segment_constant_query->detail->type, $request->input('value'), $segment_constant_query->detail->currency_id ); $this->canCreateSegmentConstant->passes($segment_constant_object); $segment_constant_query = $this->createsSegmentConstantBookingAmountMax->execute($segment_query, $segment_constant_object); } elseif ($segment_constant_query->reference == 'PAYMENT_ATTEMP_EXPIRY_TIME') { $segment_constant_object = new SegmentConstantPaymentAttemptExpiryTimeObject( $request->input('segment_id'), $segment_constant_query->name, $segment_constant_query->reference, $segment_constant_query->detail->type, $request->input('value') ); $this->canCreateSegmentConstant->passes($segment_constant_object); $segment_constant_query = $this->createsSegmentConstantPaymentAttemptExpiryTime->execute($segment_query, $segment_constant_object); } DB::commit(); return $this->resourceResponse(new SegmentConstantResource($segment_constant_query)); } catch (\Exception $exception) { throw new ErrorException($exception->getMessage(), $exception->getCode()); } } }