HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/brameda/brameda.nl/app/Komma/Shop/Payment/Clients/MultiSafepay/Models/Cost.php
<?php


namespace App\Komma\Shop\Payment\Clients\MultiSafepay\Models;

/**
 * Class Cost
 *
 * @see https://docs.multisafepay.com/api/#orders
 * @sidenote Created by Komma
 *
 * MultiSafepay orders contain costs
 *
 * @see Order
 * @package App\Komma\Shop\Payment\Clients\MultiSafepay\Models
 */
class Cost
{
    /** @var int Example: 1451408 */
    private $transaction_id;

    /** @var string Example: 0.49 For iDEAL Transactions */
    private $description;

    /** @var string Example: SYSTEM */
    private $type;

    /** @var float Example: 0.48999999999999999 */ //WTF MULTISAFEPAY. WTF. The examples are based of real transaction data
    private $amount;

    /** Prevent constructing a new instance with the new keyword */
    private function __construct() {}

    /**
     * Create an instance from a json string
     *
     * @param string $jsonString
     * @return Cost
     * @throws \Exception
     */
    public static function FromJsonString(string $jsonString): Cost
    {
        $instance = new self;

        $data = json_decode($jsonString, true);
        if ($data === null) throw new \Exception('MultiSafepay Cost: The cost data is invalid. It does not seem to be a json string.');

        $instance->transaction_id = (!empty($data['transaction_id'])) ? $data['transaction_id'] : 0;
        $instance->description = (!empty($data['description'])) ? $data['description'] : '';
        $instance->type = (!empty($data['type'])) ? $data['type'] : '';
        $instance->amount = (!empty($data['amount'])) ? $data['amount'] : 0;

        return $instance;
    }

    /**
     * @return int
     */
    public function getTransactionId(): int
    {
        return $this->transaction_id;
    }

    /**
     * @return string
     */
    public function getDescription(): string
    {
        return $this->description;
    }

    /**
     * @return string
     */
    public function getType(): string
    {
        return $this->type;
    }

    /**
     * @return float
     */
    public function getAmount(): float
    {
        return $this->amount;
    }

    /**
     * @param int $transaction_id
     * @return Cost
     */
    public function setTransactionId(int $transaction_id): Cost
    {
        $this->transaction_id = $transaction_id;
        return $this;
    }

    /**
     * @param string $description
     * @return Cost
     */
    public function setDescription(string $description): Cost
    {
        $this->description = $description;
        return $this;
    }

    /**
     * @param string $type
     * @return Cost
     */
    public function setType(string $type): Cost
    {
        $this->type = $type;
        return $this;
    }

    /**
     * @param float $amount
     * @return Cost
     */
    public function setAmount(float $amount): Cost
    {
        $this->amount = $amount;
        return $this;
    }
}