BokaMera.API.Host

<back to all web services

CalculateTotalPriceOnService

The following routes are available for this service:
PUT/services/{Id}/calculatepriceCalculate price on serviceCalculate an price on a service.
<?php namespace dtos;

use DateTime;
use Exception;
use DateInterval;
use JsonSerializable;
use ServiceStack\{IReturn,IReturnVoid,IGet,IPost,IPut,IDelete,IPatch,IMeta,IHasSessionId,IHasBearerToken,IHasVersion};
use ServiceStack\{ICrud,ICreateDb,IUpdateDb,IPatchDb,IDeleteDb,ISaveDb,AuditBase,QueryDb,QueryDb2,QueryData,QueryData2,QueryResponse};
use ServiceStack\{ResponseStatus,ResponseError,EmptyResponse,IdResponse,ArrayList,KeyValuePair2,StringResponse,StringsResponse,Tuple2,Tuple3,ByteArray};
use ServiceStack\{JsonConverters,Returns,TypeContext};


class RebateCodeTypeResponse implements JsonSerializable
{
    public function __construct(
        /** @var int */
        public int $Id=0,
        /** @var string|null */
        public ?string $Name=null,
        /** @var string|null */
        public ?string $Description=null
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['Id'])) $this->Id = $o['Id'];
        if (isset($o['Name'])) $this->Name = $o['Name'];
        if (isset($o['Description'])) $this->Description = $o['Description'];
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->Id)) $o['Id'] = $this->Id;
        if (isset($this->Name)) $o['Name'] = $this->Name;
        if (isset($this->Description)) $o['Description'] = $this->Description;
        return empty($o) ? new class(){} : $o;
    }
}

class AppliedRebateCodesResponse implements JsonSerializable
{
    public function __construct(
        /** @var string|null */
        public ?string $RebateCodeSign=null,
        /** @var int */
        public int $RebateCodeValue=0,
        /** @var RebateCodeTypeResponse|null */
        public ?RebateCodeTypeResponse $RebateCodeType=null,
        /** @var int */
        public int $RebateCodeId=0,
        /** @var float */
        public float $RebateAmount=0.0
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['RebateCodeSign'])) $this->RebateCodeSign = $o['RebateCodeSign'];
        if (isset($o['RebateCodeValue'])) $this->RebateCodeValue = $o['RebateCodeValue'];
        if (isset($o['RebateCodeType'])) $this->RebateCodeType = JsonConverters::from('RebateCodeTypeResponse', $o['RebateCodeType']);
        if (isset($o['RebateCodeId'])) $this->RebateCodeId = $o['RebateCodeId'];
        if (isset($o['RebateAmount'])) $this->RebateAmount = $o['RebateAmount'];
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->RebateCodeSign)) $o['RebateCodeSign'] = $this->RebateCodeSign;
        if (isset($this->RebateCodeValue)) $o['RebateCodeValue'] = $this->RebateCodeValue;
        if (isset($this->RebateCodeType)) $o['RebateCodeType'] = JsonConverters::to('RebateCodeTypeResponse', $this->RebateCodeType);
        if (isset($this->RebateCodeId)) $o['RebateCodeId'] = $this->RebateCodeId;
        if (isset($this->RebateAmount)) $o['RebateAmount'] = $this->RebateAmount;
        return empty($o) ? new class(){} : $o;
    }
}

class TotalPricePriceDetail implements JsonSerializable
{
    public function __construct(
        /** @var int */
        public int $Quantity=0,
        /** @var float */
        public float $Price=0.0,
        /** @var float */
        public float $VatAmount=0.0,
        /** @var string|null */
        public ?string $Description=null
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['Quantity'])) $this->Quantity = $o['Quantity'];
        if (isset($o['Price'])) $this->Price = $o['Price'];
        if (isset($o['VatAmount'])) $this->VatAmount = $o['VatAmount'];
        if (isset($o['Description'])) $this->Description = $o['Description'];
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->Quantity)) $o['Quantity'] = $this->Quantity;
        if (isset($this->Price)) $o['Price'] = $this->Price;
        if (isset($this->VatAmount)) $o['VatAmount'] = $this->VatAmount;
        if (isset($this->Description)) $o['Description'] = $this->Description;
        return empty($o) ? new class(){} : $o;
    }
}

class TotalPriceInformationResponse implements JsonSerializable
{
    public function __construct(
        /** @var string|null */
        public ?string $PriceSign=null,
        /** @var string|null */
        public ?string $CurrencyId=null,
        /** @var float */
        public float $TotalPrice=0.0,
        /** @var float */
        public float $TotalVatAmount=0.0,
        /** @var float */
        public float $TotalPriceBeforeRebate=0.0,
        /** @var array<AppliedRebateCodesResponse>|null */
        public ?array $AppliedCodes=null,
        /** @var array<TotalPricePriceDetail>|null */
        public ?array $PriceDetails=null
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['PriceSign'])) $this->PriceSign = $o['PriceSign'];
        if (isset($o['CurrencyId'])) $this->CurrencyId = $o['CurrencyId'];
        if (isset($o['TotalPrice'])) $this->TotalPrice = $o['TotalPrice'];
        if (isset($o['TotalVatAmount'])) $this->TotalVatAmount = $o['TotalVatAmount'];
        if (isset($o['TotalPriceBeforeRebate'])) $this->TotalPriceBeforeRebate = $o['TotalPriceBeforeRebate'];
        if (isset($o['AppliedCodes'])) $this->AppliedCodes = JsonConverters::fromArray('AppliedRebateCodesResponse', $o['AppliedCodes']);
        if (isset($o['PriceDetails'])) $this->PriceDetails = JsonConverters::fromArray('TotalPricePriceDetail', $o['PriceDetails']);
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->PriceSign)) $o['PriceSign'] = $this->PriceSign;
        if (isset($this->CurrencyId)) $o['CurrencyId'] = $this->CurrencyId;
        if (isset($this->TotalPrice)) $o['TotalPrice'] = $this->TotalPrice;
        if (isset($this->TotalVatAmount)) $o['TotalVatAmount'] = $this->TotalVatAmount;
        if (isset($this->TotalPriceBeforeRebate)) $o['TotalPriceBeforeRebate'] = $this->TotalPriceBeforeRebate;
        if (isset($this->AppliedCodes)) $o['AppliedCodes'] = JsonConverters::toArray('AppliedRebateCodesResponse', $this->AppliedCodes);
        if (isset($this->PriceDetails)) $o['PriceDetails'] = JsonConverters::toArray('TotalPricePriceDetail', $this->PriceDetails);
        return empty($o) ? new class(){} : $o;
    }
}

class PriceInterval implements JsonSerializable
{
    public function __construct(
        /** @description The start date and time for the price to be calculated. Normally the booking start datetime. */
        // @ApiMember(Description="The start date and time for the price to be calculated. Normally the booking start datetime.", IsRequired=true)
        /** @var DateTime */
        public DateTime $From=new DateTime(),

        /** @description The end date and time for the price to be calculated.Normally the booking end datetime. If nothing entered it will use the service length. */
        // @ApiMember(Description="The end date and time for the price to be calculated.Normally the booking end datetime. If nothing entered it will use the service length.")
        /** @var DateTime|null */
        public ?DateTime $To=null
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['From'])) $this->From = JsonConverters::from('DateTime', $o['From']);
        if (isset($o['To'])) $this->To = JsonConverters::from('DateTime', $o['To']);
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->From)) $o['From'] = JsonConverters::to('DateTime', $this->From);
        if (isset($this->To)) $o['To'] = JsonConverters::to('DateTime', $this->To);
        return empty($o) ? new class(){} : $o;
    }
}

class CalculateTotalPriceOnService implements ICompany, JsonSerializable
{
    public function __construct(
        /** @description The company id, if empty will use the company id for the user you are logged in with. */
        // @ApiMember(Description="The company id, if empty will use the company id for the user you are logged in with.")
        /** @var string|null */
        public ?string $CompanyId=null,

        /** @description Id of the service */
        // @ApiMember(Description="Id of the service", IsRequired=true, ParameterType="path")
        /** @var int */
        public int $Id=0,

        /** @description The price interval to be used for calculations */
        // @ApiMember(Description="The price interval to be used for calculations", IsRequired=true)
        /** @var PriceInterval|null */
        public ?PriceInterval $Interval=null,

        /** @description Rebate codes applied to booking */
        // @ApiMember(Description="Rebate codes applied to booking")
        /** @var array<int>|null */
        public ?array $RebateCodeIds=null,

        /** @description If you have selected to include the prices, here you can include the quantities to book to get the correct total price. */
        // @ApiMember(Description="If you have selected to include the prices, here you can include the quantities to book to get the correct total price.")
        /** @var QuantityToBook[]|null */
        public ?array $Quantities=null,

        /** @description  */
        // @ApiMember(Description="")
        /** @var string|null */
        public ?string $CustomerEmail=null
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['CompanyId'])) $this->CompanyId = $o['CompanyId'];
        if (isset($o['Id'])) $this->Id = $o['Id'];
        if (isset($o['Interval'])) $this->Interval = JsonConverters::from('PriceInterval', $o['Interval']);
        if (isset($o['RebateCodeIds'])) $this->RebateCodeIds = JsonConverters::fromArray('int', $o['RebateCodeIds']);
        if (isset($o['Quantities'])) $this->Quantities = JsonConverters::fromArray('QuantityToBook', $o['Quantities']);
        if (isset($o['CustomerEmail'])) $this->CustomerEmail = $o['CustomerEmail'];
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->CompanyId)) $o['CompanyId'] = $this->CompanyId;
        if (isset($this->Id)) $o['Id'] = $this->Id;
        if (isset($this->Interval)) $o['Interval'] = JsonConverters::to('PriceInterval', $this->Interval);
        if (isset($this->RebateCodeIds)) $o['RebateCodeIds'] = JsonConverters::toArray('int', $this->RebateCodeIds);
        if (isset($this->Quantities)) $o['Quantities'] = JsonConverters::toArray('QuantityToBook', $this->Quantities);
        if (isset($this->CustomerEmail)) $o['CustomerEmail'] = $this->CustomerEmail;
        return empty($o) ? new class(){} : $o;
    }
}

class QuantityToBook implements JsonSerializable
{
    public function __construct(
        /** @description If service has a price, enter the price id for that price. If no price exists for the service set 0 as PriceId. If you put 0 and a price exists, it will use that price (only works if just one price exists for the current selected date to book) */
        // @ApiMember(Description="If service has a price, enter the price id for that price. If no price exists for the service set 0 as PriceId. If you put 0 and a price exists, it will use that price (only works if just one price exists for the current selected date to book)", IsRequired=true)
        /** @var int */
        public int $PriceId=0,

        /** @description Set the number of spots or resources you want to book on the specific price category */
        // @ApiMember(Description="Set the number of spots or resources you want to book on the specific price category", IsRequired=true)
        /** @var int */
        public int $Quantity=0,

        /** @description If the quantity you add should occupy a spot. Default is true. If no it will only be a row that includes price information. */
        // @ApiMember(Description="If the quantity you add should occupy a spot. Default is true. If no it will only be a row that includes price information.")
        /** @var bool|null */
        public ?bool $OccupiesSpot=null
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['PriceId'])) $this->PriceId = $o['PriceId'];
        if (isset($o['Quantity'])) $this->Quantity = $o['Quantity'];
        if (isset($o['OccupiesSpot'])) $this->OccupiesSpot = $o['OccupiesSpot'];
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->PriceId)) $o['PriceId'] = $this->PriceId;
        if (isset($this->Quantity)) $o['Quantity'] = $this->Quantity;
        if (isset($this->OccupiesSpot)) $o['OccupiesSpot'] = $this->OccupiesSpot;
        return empty($o) ? new class(){} : $o;
    }
}

PHP CalculateTotalPriceOnService DTOs

To override the Content-type in your clients, use the HTTP Accept Header, append the .json suffix or ?format=json

To embed the response in a jsonp callback, append ?callback=myCallback

HTTP + JSON

The following are sample HTTP requests and responses. The placeholders shown need to be replaced with actual values.

PUT /services/{Id}/calculateprice HTTP/1.1 
Host: api.bokamera.se 
Accept: application/json
Content-Type: application/json
Content-Length: length

{"CompanyId":"00000000-0000-0000-0000-000000000000","Id":0,"Interval":{"To":"0001-01-01T00:00:00"},"RebateCodeIds":[0],"Quantities":[{"PriceId":0,"Quantity":0,"OccupiesSpot":false}],"CustomerEmail":"String"}
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: length

{"PriceSign":"String","CurrencyId":"String","TotalPrice":0,"TotalVatAmount":0,"TotalPriceBeforeRebate":0,"AppliedCodes":[{"RebateCodeSign":"String","RebateCodeValue":0,"RebateCodeType":{"Id":0,"Name":"String","Description":"String"},"RebateCodeId":0,"RebateAmount":0}],"PriceDetails":[{"Quantity":0,"Price":0,"VatAmount":0,"Description":"String"}]}