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 */
        public string $Name='',
        /** @var string */
        public string $Description=''
    ) {
    }

    /** @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 */
        public string $RebateCodeSign='',
        /** @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 */
        public string $Description=''
    ) {
    }

    /** @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 */
        public string $PriceSign='',
        /** @var string */
        public string $CurrencyId='',
        /** @var float */
        public float $TotalPrice=0.0,
        /** @var float */
        public float $TotalVatAmount=0.0,
        /** @var float */
        public float $TotalPriceBeforeRebate=0.0,
        /** @var float */
        public float $PriceDifference=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['PriceDifference'])) $this->PriceDifference = $o['PriceDifference'];
        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->PriceDifference)) $o['PriceDifference'] = $this->PriceDifference;
        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 ArticleToCreateBase implements JsonSerializable
{
    public function __construct(
        /** @var int */
        public int $ArticleId=0,
        /** @var int */
        public int $Quantity=0
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['ArticleId'])) $this->ArticleId = $o['ArticleId'];
        if (isset($o['Quantity'])) $this->Quantity = $o['Quantity'];
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->ArticleId)) $o['ArticleId'] = $this->ArticleId;
        if (isset($this->Quantity)) $o['Quantity'] = $this->Quantity;
        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;
    }
}

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 Optional booking id. If provided, the response will also contain the price difference compared to the existing booking price. */
        // @ApiMember(Description="Optional booking id. If provided, the response will also contain the price difference compared to the existing booking price.")
        /** @var int|null */
        public ?int $BookingId=null,

        /** @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 DEPRECATED — use Articles instead. Article ids that should be included in the price calculation. The articles must be of type ServiceAddonArticle and connected to the service. Duplicate ids are counted as quantity. */
        // @ApiMember(Description="DEPRECATED — use Articles instead. Article ids that should be included in the price calculation. The articles must be of type ServiceAddonArticle and connected to the service. Duplicate ids are counted as quantity.")
        /** @var array<int>|null */
        public ?array $ArticleIds=null,

        /** @description Articles (with quantity) that should be included in the price calculation. The articles must be of type ServiceAddonArticle and connected to the service. */
        // @ApiMember(Description="Articles (with quantity) that should be included in the price calculation. The articles must be of type ServiceAddonArticle and connected to the service.")
        /** @var ArticleToCreateBase[] */
        public array $Articles=[],

        /** @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[] */
        public array $Quantities=[],

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

    /** @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['BookingId'])) $this->BookingId = $o['BookingId'];
        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['ArticleIds'])) $this->ArticleIds = JsonConverters::fromArray('int', $o['ArticleIds']);
        if (isset($o['Articles'])) $this->Articles = JsonConverters::fromArray('ArticleToCreateBase', $o['Articles']);
        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->BookingId)) $o['BookingId'] = $this->BookingId;
        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->ArticleIds)) $o['ArticleIds'] = JsonConverters::toArray('int', $this->ArticleIds);
        if (isset($this->Articles)) $o['Articles'] = JsonConverters::toArray('ArticleToCreateBase', $this->Articles);
        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;
    }
}

PHP CalculateTotalPriceOnService DTOs

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

HTTP + OTHER

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: testapi.bokamera.se 
Accept: text/jsonl
Content-Type: text/jsonl
Content-Length: length

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

{"PriceSign":"String","CurrencyId":"String","TotalPrice":0,"TotalVatAmount":0,"TotalPriceBeforeRebate":0,"PriceDifference":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"}]}