'Fetch Currency Conversion', 'message' => 'You have successfully retrieved a currency conversion' ]; } /** @var FetchesBookingQuotation */ private $fetchBookingQuotation; /** @var GeneratesBookingQuotation */ private $generatesBookingQuotation; /** @var FetchesCompanyPaymentAttemptLimit */ private $fetchesCompanyPaymentAttemptLimit; /** @var CalculatesBookingOutstanding */ private $calculatesBookingOutstanding; /** @var CalculatesBookingRefundAmount */ private $calculatesBookingRefundAmount; /** * FetchBookingPaymentQuotationLogic constructor. * @param FetchesBookingQuotation $fetchBookingQuotation * @param GeneratesBookingQuotation $generatesBookingQuotation * @param FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit * @param CalculatesBookingOutstanding $calculatesBookingOutstanding */ public function __construct(FetchesBookingQuotation $fetchBookingQuotation, GeneratesBookingQuotation $generatesBookingQuotation, FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit, CalculatesBookingOutstanding $calculatesBookingOutstanding, CalculatesBookingRefundAmount $calculatesBookingRefundAmount) { $this->fetchBookingQuotation = $fetchBookingQuotation; $this->generatesBookingQuotation = $generatesBookingQuotation; $this->fetchesCompanyPaymentAttemptLimit = $fetchesCompanyPaymentAttemptLimit; $this->calculatesBookingOutstanding = $calculatesBookingOutstanding; $this->calculatesBookingRefundAmount = $calculatesBookingRefundAmount; } /** * @param Request $request * @return JsonResponse * @throws MalformedRequestException */ public function logic(Request $request) : JsonResponse { $booking = Booking::find($request->route('id')); $conversionObject = new CurrencyConversionObject(floatval(str_replace(',', '', $request->input('amount'))), $booking->convertible_currency_id, $booking->service_id, $booking->fix_currency_id === 1 ? 0:1, PaymentMethodType::PAYMENT_METHODS[$request->input('payment_method')]); $outstanding = $this->calculatesBookingOutstanding->execute($booking) + $this->calculatesBookingRefundAmount->execute($booking, $booking->fix_currency_id); if($conversionObject->getAmount() > round($outstanding, 2)) throw new MalformedRequestException('Your payment must not be greater than '.$booking->fixedCurrency->short_code.' '. number_format((float)$outstanding, 2, '.', ',')); //Voucherify $voucherCode = $request->input('voucherCode'); return $this->response(['data' => $this->generatesBookingQuotation->execute( $this->fetchBookingQuotation->execute($booking->company, $conversionObject, $voucherCode), $this->fetchesCompanyPaymentAttemptLimit->execute($booking->company), $conversionObject )]); } }